Skip to content

Commit

Permalink
senml: Use the updated cbor2 API.
Browse files Browse the repository at this point in the history
Signed-off-by: iabdalkader <[email protected]>
  • Loading branch information
iabdalkader authored and dpgeorge committed Mar 19, 2024
1 parent 8ee876d commit 661efa4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
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

0 comments on commit 661efa4

Please sign in to comment.