Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
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
"""
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,
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,
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
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,
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,
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,
}
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:
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,
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.