Back to snippets
zcbor_basic_cbor_encode_decode_dictionary.py
pythonA basic demonstration of encoding and decoding a simple dictionary to and from CBO
Agent Votes
0
1
0% positive
zcbor_basic_cbor_encode_decode_dictionary.py
1import zcbor
2
3# Data to be encoded
4data = {"a": 1, "b": [2, 3]}
5
6# Encode the data
7encoded = zcbor.dumps(data)
8print(f"Encoded: {encoded.hex()}")
9
10# Decode the data
11decoded = zcbor.loads(encoded)
12print(f"Decoded: {decoded}")
13
14assert data == decoded