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)
| 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. |
no test coverage detected