MCPcopy Create free account
hub / github.com/ccxt/ccxt / from_bytes

Method from_bytes

python/ccxt/static_dependencies/msgpack/ext.py:71–95  ·  view source on GitHub ↗

Unpack bytes into a `Timestamp` object. Used for pure-Python msgpack unpacking. :param b: Payload from msgpack ext message with code -1 :type b: bytes :returns: Timestamp object unpacked from msgpack ext payload :rtype: Timestamp

(b)

Source from the content-addressed store, hash-verified

69
70 @staticmethod
71 def from_bytes(b):
72 """Unpack bytes into a `Timestamp` object.
73
74 Used for pure-Python msgpack unpacking.
75
76 :param b: Payload from msgpack ext message with code -1
77 :type b: bytes
78
79 :returns: Timestamp object unpacked from msgpack ext payload
80 :rtype: Timestamp
81 """
82 if len(b) == 4:
83 seconds = struct.unpack("!L", b)[0]
84 nanoseconds = 0
85 elif len(b) == 8:
86 data64 = struct.unpack("!Q", b)[0]
87 seconds = data64 & 0x00000003FFFFFFFF
88 nanoseconds = data64 >> 34
89 elif len(b) == 12:
90 nanoseconds, seconds = struct.unpack("!Iq", b)
91 else:
92 raise ValueError(
93 "Timestamp type can only be created from 32, 64, or 96-bit byte objects"
94 )
95 return Timestamp(seconds, nanoseconds)
96
97 def to_bytes(self):
98 """Pack this Timestamp object into bytes.

Callers 8

int_from_bytesFunction · 0.45
_round_constantFunction · 0.45
encode_shortstringFunction · 0.45
FromBytesMethod · 0.45
ToIntegerMethod · 0.45
to_mnemonicMethod · 0.45
_unpackMethod · 0.45
from_bytesFunction · 0.45

Calls 2

unpackMethod · 0.80
TimestampClass · 0.70

Tested by

no test coverage detected