Pack this Timestamp object into bytes. Used for pure-Python msgpack packing. :returns data: Payload for EXT message with code -1 (timestamp type) :rtype: bytes
(self)
| 95 | return Timestamp(seconds, nanoseconds) |
| 96 | |
| 97 | def to_bytes(self): |
| 98 | """Pack this Timestamp object into bytes. |
| 99 | |
| 100 | Used for pure-Python msgpack packing. |
| 101 | |
| 102 | :returns data: Payload for EXT message with code -1 (timestamp type) |
| 103 | :rtype: bytes |
| 104 | """ |
| 105 | if (self.seconds >> 34) == 0: # seconds is non-negative and fits in 34 bits |
| 106 | data64 = self.nanoseconds << 34 | self.seconds |
| 107 | if data64 & 0xFFFFFFFF00000000 == 0: |
| 108 | # nanoseconds is zero and seconds < 2**32, so timestamp 32 |
| 109 | data = struct.pack("!L", data64) |
| 110 | else: |
| 111 | # timestamp 64 |
| 112 | data = struct.pack("!Q", data64) |
| 113 | else: |
| 114 | # timestamp 96 |
| 115 | data = struct.pack("!Iq", self.nanoseconds, self.seconds) |
| 116 | return data |
| 117 | |
| 118 | @staticmethod |
| 119 | def from_unix(unix_sec): |
no test coverage detected