def get_socketcan_timestamp(sock) -> Timestamp: SIOCGSTAMP = 0x8906 buf = struct.pack('@LL', 0, 0) # https://docs.python.org/3/library/fcntl.html#fcntl.ioctl buf = fcntl.ioctl(sock, SIOCGSTAMP, buf) seconds, microseconds = struct.unpack('@LL', buf) ts = Timestamp() ts.FromMicroseconds(seconds * 1000000 + microseconds) return ts
def pa_column_to_timestamp_proto_column(column: pa.lib.ChunkedArray) -> List[Timestamp]: if not isinstance(column.type, TimestampType): raise Exception("Only TimestampType columns are allowed") proto_column = [] for val in column: timestamp = Timestamp() timestamp.FromMicroseconds(micros=int(val.as_py().timestamp() * 1_000_000)) proto_column.append(timestamp) return proto_column