Commit 48eb3b0e authored by Juraj Sloboda's avatar Juraj Sloboda

Remove cbor dependency - use cbor2 in all places (#58)

parent 50871f9a
......@@ -7,11 +7,11 @@ Conforms to::
(which is compatible with uPCN 0.6.0)
Dependencies:
This module depends on the ``cbor`` package which can be installed via pip:
This module depends on the ``cbor2`` package which can be installed via pip:
.. code:: bash
pip install cbor
pip install cbor2
Usage:
If you are in the root directory of the project you can simply run:
......@@ -44,8 +44,7 @@ import struct
from enum import IntEnum, IntFlag
from datetime import datetime, tzinfo, timedelta
from random import random
import cbor
from cbor.cbor import CBOR_ARRAY
import cbor2
from .crc import crc16_x25, crc32
......@@ -308,7 +307,7 @@ class PrimaryBlock(object):
# encode each field
for field in primary_block:
binary.append(cbor.dumps(field))
binary.append(cbor2.dumps(field))
if self.crc_type == CRCType.CRC32:
# Empty CRC-32 bit field: CBOR "byte string"
......@@ -324,7 +323,7 @@ class PrimaryBlock(object):
crc = crc16_x25(binary)
primary_block.append(struct.pack("!H", crc))
return cbor.dumps(primary_block)
return cbor2.dumps(primary_block)
class CanonicalBlock(object):
......@@ -350,7 +349,7 @@ class CanonicalBlock(object):
# Block data length
# If the value can be expressed in one byte, we have to ensure
# that we do not return 0 as block length. Therefore max(1, ...)
block.append(max(1, len(cbor.dumps(serialized_data))))
block.append(max(1, len(cbor2.dumps(serialized_data))))
# Block-specific data
block.append(serialized_data)
......@@ -364,7 +363,7 @@ class CanonicalBlock(object):
else:
empty_crc = b"\x42\x00\x00"
binary = struct.pack("B", 0x80 | 7) + b"".join([cbor.dumps(item) for item in block]) + empty_crc
binary = struct.pack("B", 0x80 | 7) + b"".join([cbor2.dumps(item) for item in block]) + empty_crc
if self.crc_type == CRCType.CRC32:
crc = crc32(binary)
......@@ -375,7 +374,7 @@ class CanonicalBlock(object):
# unsigned short in network byte order
block.append(struct.pack("!H", crc))
return cbor.dumps(block)
return cbor2.dumps(block)
class PayloadBlock(CanonicalBlock):
......@@ -504,6 +503,7 @@ class Bundle(object):
def serialize(self):
# Header for indefinite array
CBOR_ARRAY = 0x80
head = struct.pack("B", CBOR_ARRAY | 31)
# Stop-code for indefinite array
stop = b"\xff"
......
pyyaml~=3.13
cbor~=1.0.0
cbor2~=4.1.2
asyncio~=3.4.3
from setuptools import setup, find_packages
install_requires = ["pyyaml>=3.13", "cbor>=1.0.0", "cbor2>=4.1.2", "asyncio>=3.4.3"]
install_requires = ["pyyaml>=3.13", "cbor2>=4.1.2", "asyncio>=3.4.3"]
setup(
name="pydtn",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment