Skip to content

Senml/cbor2 update. #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions micropython/senml/examples/basic_cbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from senml import *
import time
from cbor2 import decoder
import cbor2

pack = SenmlPack("device_name")

Expand All @@ -38,5 +38,5 @@
cbor_val = pack.to_cbor()
print(cbor_val)
print(cbor_val.hex())
print(decoder.loads(cbor_val)) # convert to string again so we can print it.
print(cbor2.loads(cbor_val)) # convert to string again so we can print it.
time.sleep(1)
2 changes: 1 addition & 1 deletion micropython/senml/manifest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
metadata(
description="SenML serialisation for MicroPython.",
version="0.1.0",
version="0.1.1",
pypi_publish="micropython-senml",
)

Expand Down
7 changes: 3 additions & 4 deletions micropython/senml/senml/senml_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from senml.senml_record import SenmlRecord
from senml.senml_base import SenmlBase
import json
from cbor2 import encoder
from cbor2 import decoder
import cbor2


class SenmlPackIterator:
Expand Down Expand Up @@ -278,7 +277,7 @@ def from_cbor(self, data):
:param data: a byte array.
:return: None
"""
records = decoder.loads(data) # load the raw senml data
records = cbor2.loads(data) # load the raw senml data
naming_map = {
"bn": -2,
"bt": -3,
Expand Down Expand Up @@ -320,7 +319,7 @@ def to_cbor(self):
}
converted = []
self._build_rec_dict(naming_map, converted)
return encoder.dumps(converted)
return cbor2.dumps(converted)

def add(self, item):
"""
Expand Down
9 changes: 7 additions & 2 deletions python-ecosys/cbor2/cbor2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
"""


from . import decoder
from . import encoder
from ._decoder import CBORDecoder
from ._decoder import load
from ._decoder import loads

from ._encoder import CBOREncoder
from ._encoder import dump
from ._encoder import dumps
7 changes: 3 additions & 4 deletions python-ecosys/cbor2/examples/cbor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@
"""


from cbor2 import encoder
from cbor2 import decoder
import cbor2

input = [
{"bn": "urn:dev:ow:10e2073a01080063", "u": "Cel", "t": 1.276020076e09, "v": 23.5},
{"u": "Cel", "t": 1.276020091e09, "v": 23.6},
]

data = encoder.dumps(input)
data = cbor2.dumps(input)
print(data)
print(data.hex())
text = decoder.loads(data)
text = cbor2.loads(data)
print(text)
2 changes: 1 addition & 1 deletion python-ecosys/cbor2/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="0.1.0", pypi="cbor2")
metadata(version="1.0.0", pypi="cbor2")

package("cbor2")
Loading