How to use the cbor2.decoder.CBORDecoder function in cbor2

To help you get started, we’ve selected a few cbor2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agronholm / cbor2 / cbor2 / decoder.py View on Github external
}

semantic_decoders = {
    0:   CBORDecoder.decode_datetime_string,
    1:   CBORDecoder.decode_epoch_datetime,
    2:   CBORDecoder.decode_positive_bignum,
    3:   CBORDecoder.decode_negative_bignum,
    4:   CBORDecoder.decode_fraction,
    5:   CBORDecoder.decode_bigfloat,
    28:  CBORDecoder.decode_shareable,
    29:  CBORDecoder.decode_sharedref,
    30:  CBORDecoder.decode_rational,
    35:  CBORDecoder.decode_regexp,
    36:  CBORDecoder.decode_mime,
    37:  CBORDecoder.decode_uuid,
    258: CBORDecoder.decode_set,
    260: CBORDecoder.decode_ipaddress,
    261: CBORDecoder.decode_ipnetwork,
}


def loads(s, **kwargs):
    """
    Deserialize an object from a bytestring.

    :param bytes s:
        the bytestring to deserialize
    :param kwargs:
        keyword arguments passed to :class:`CBORDecoder`
    :return:
        the deserialized object
    """
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
payload = self.read(2)
        try:
            value = struct.unpack('>e', payload)[0]
        except struct.error:
            value = unpack_float16(payload)
        return self.set_shareable(value)

    def decode_float32(self):
        return self.set_shareable(struct.unpack('>f', self.read(4))[0])

    def decode_float64(self):
        return self.set_shareable(struct.unpack('>d', self.read(8))[0])


major_decoders = {
    0: CBORDecoder.decode_uint,
    1: CBORDecoder.decode_negint,
    2: CBORDecoder.decode_bytestring,
    3: CBORDecoder.decode_string,
    4: CBORDecoder.decode_array,
    5: CBORDecoder.decode_map,
    6: CBORDecoder.decode_semantic,
    7: CBORDecoder.decode_special,
}

special_decoders = {
    20: lambda self: False,
    21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
except struct.error:
            value = unpack_float16(payload)
        return self.set_shareable(value)

    def decode_float32(self):
        return self.set_shareable(struct.unpack('>f', self.read(4))[0])

    def decode_float64(self):
        return self.set_shareable(struct.unpack('>d', self.read(8))[0])


major_decoders = {
    0: CBORDecoder.decode_uint,
    1: CBORDecoder.decode_negint,
    2: CBORDecoder.decode_bytestring,
    3: CBORDecoder.decode_string,
    4: CBORDecoder.decode_array,
    5: CBORDecoder.decode_map,
    6: CBORDecoder.decode_semantic,
    7: CBORDecoder.decode_special,
}

special_decoders = {
    20: lambda self: False,
    21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
    27: CBORDecoder.decode_float64,
    31: lambda self: break_marker,
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
31: lambda self: break_marker,
}

semantic_decoders = {
    0:   CBORDecoder.decode_datetime_string,
    1:   CBORDecoder.decode_epoch_datetime,
    2:   CBORDecoder.decode_positive_bignum,
    3:   CBORDecoder.decode_negative_bignum,
    4:   CBORDecoder.decode_fraction,
    5:   CBORDecoder.decode_bigfloat,
    28:  CBORDecoder.decode_shareable,
    29:  CBORDecoder.decode_sharedref,
    30:  CBORDecoder.decode_rational,
    35:  CBORDecoder.decode_regexp,
    36:  CBORDecoder.decode_mime,
    37:  CBORDecoder.decode_uuid,
    258: CBORDecoder.decode_set,
    260: CBORDecoder.decode_ipaddress,
    261: CBORDecoder.decode_ipnetwork,
}


def loads(s, **kwargs):
    """
    Deserialize an object from a bytestring.

    :param bytes s:
        the bytestring to deserialize
    :param kwargs:
        keyword arguments passed to :class:`CBORDecoder`
    :return:
        the deserialized object
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
try:
            value = struct.unpack('>e', payload)[0]
        except struct.error:
            value = unpack_float16(payload)
        return self.set_shareable(value)

    def decode_float32(self):
        return self.set_shareable(struct.unpack('>f', self.read(4))[0])

    def decode_float64(self):
        return self.set_shareable(struct.unpack('>d', self.read(8))[0])


major_decoders = {
    0: CBORDecoder.decode_uint,
    1: CBORDecoder.decode_negint,
    2: CBORDecoder.decode_bytestring,
    3: CBORDecoder.decode_string,
    4: CBORDecoder.decode_array,
    5: CBORDecoder.decode_map,
    6: CBORDecoder.decode_semantic,
    7: CBORDecoder.decode_special,
}

special_decoders = {
    20: lambda self: False,
    21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
value = struct.unpack('>e', payload)[0]
        except struct.error:
            value = unpack_float16(payload)
        return self.set_shareable(value)

    def decode_float32(self):
        return self.set_shareable(struct.unpack('>f', self.read(4))[0])

    def decode_float64(self):
        return self.set_shareable(struct.unpack('>d', self.read(8))[0])


major_decoders = {
    0: CBORDecoder.decode_uint,
    1: CBORDecoder.decode_negint,
    2: CBORDecoder.decode_bytestring,
    3: CBORDecoder.decode_string,
    4: CBORDecoder.decode_array,
    5: CBORDecoder.decode_map,
    6: CBORDecoder.decode_semantic,
    7: CBORDecoder.decode_special,
}

special_decoders = {
    20: lambda self: False,
    21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
    27: CBORDecoder.decode_float64,
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
special_decoders = {
    20: lambda self: False,
    21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
    27: CBORDecoder.decode_float64,
    31: lambda self: break_marker,
}

semantic_decoders = {
    0:   CBORDecoder.decode_datetime_string,
    1:   CBORDecoder.decode_epoch_datetime,
    2:   CBORDecoder.decode_positive_bignum,
    3:   CBORDecoder.decode_negative_bignum,
    4:   CBORDecoder.decode_fraction,
    5:   CBORDecoder.decode_bigfloat,
    28:  CBORDecoder.decode_shareable,
    29:  CBORDecoder.decode_sharedref,
    30:  CBORDecoder.decode_rational,
    35:  CBORDecoder.decode_regexp,
    36:  CBORDecoder.decode_mime,
    37:  CBORDecoder.decode_uuid,
    258: CBORDecoder.decode_set,
    260: CBORDecoder.decode_ipaddress,
    261: CBORDecoder.decode_ipnetwork,
}
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
    27: CBORDecoder.decode_float64,
    31: lambda self: break_marker,
}

semantic_decoders = {
    0:   CBORDecoder.decode_datetime_string,
    1:   CBORDecoder.decode_epoch_datetime,
    2:   CBORDecoder.decode_positive_bignum,
    3:   CBORDecoder.decode_negative_bignum,
    4:   CBORDecoder.decode_fraction,
    5:   CBORDecoder.decode_bigfloat,
    28:  CBORDecoder.decode_shareable,
    29:  CBORDecoder.decode_sharedref,
    30:  CBORDecoder.decode_rational,
    35:  CBORDecoder.decode_regexp,
    36:  CBORDecoder.decode_mime,
    37:  CBORDecoder.decode_uuid,
    258: CBORDecoder.decode_set,
    260: CBORDecoder.decode_ipaddress,
    261: CBORDecoder.decode_ipnetwork,
}


def loads(s, **kwargs):
    """
    Deserialize an object from a bytestring.

    :param bytes s:
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
0: CBORDecoder.decode_uint,
    1: CBORDecoder.decode_negint,
    2: CBORDecoder.decode_bytestring,
    3: CBORDecoder.decode_string,
    4: CBORDecoder.decode_array,
    5: CBORDecoder.decode_map,
    6: CBORDecoder.decode_semantic,
    7: CBORDecoder.decode_special,
}

special_decoders = {
    20: lambda self: False,
    21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
    27: CBORDecoder.decode_float64,
    31: lambda self: break_marker,
}

semantic_decoders = {
    0:   CBORDecoder.decode_datetime_string,
    1:   CBORDecoder.decode_epoch_datetime,
    2:   CBORDecoder.decode_positive_bignum,
    3:   CBORDecoder.decode_negative_bignum,
    4:   CBORDecoder.decode_fraction,
    5:   CBORDecoder.decode_bigfloat,
    28:  CBORDecoder.decode_shareable,
    29:  CBORDecoder.decode_sharedref,
    30:  CBORDecoder.decode_rational,
github agronholm / cbor2 / cbor2 / decoder.py View on Github external
21: lambda self: True,
    22: lambda self: None,
    23: lambda self: undefined,
    24: CBORDecoder.decode_simple_value,
    25: CBORDecoder.decode_float16,
    26: CBORDecoder.decode_float32,
    27: CBORDecoder.decode_float64,
    31: lambda self: break_marker,
}

semantic_decoders = {
    0:   CBORDecoder.decode_datetime_string,
    1:   CBORDecoder.decode_epoch_datetime,
    2:   CBORDecoder.decode_positive_bignum,
    3:   CBORDecoder.decode_negative_bignum,
    4:   CBORDecoder.decode_fraction,
    5:   CBORDecoder.decode_bigfloat,
    28:  CBORDecoder.decode_shareable,
    29:  CBORDecoder.decode_sharedref,
    30:  CBORDecoder.decode_rational,
    35:  CBORDecoder.decode_regexp,
    36:  CBORDecoder.decode_mime,
    37:  CBORDecoder.decode_uuid,
    258: CBORDecoder.decode_set,
    260: CBORDecoder.decode_ipaddress,
    261: CBORDecoder.decode_ipnetwork,
}


def loads(s, **kwargs):
    """
    Deserialize an object from a bytestring.