"""LCM type definitions
This file automatically generated by lcm.
DO NOT MODIFY BY HAND!!!!
"""

try:
    import cStringIO.StringIO as BytesIO
except ImportError:
    from io import BytesIO
import struct

class timedrift_t(object):
    __slots__ = ["sync_host", "sync_ticks", "ticks_sec", "host_before", "host_after", "ticks", "host_utime", "cam_utime"]

    __typenames__ = ["int64_t", "int64_t", "double", "int64_t", "int64_t", "int64_t", "int64_t", "int64_t"]

    __dimensions__ = [None, None, None, None, None, None, None, None]

    def __init__(self):
        self.sync_host = 0
        self.sync_ticks = 0
        self.ticks_sec = 0.0
        self.host_before = 0
        self.host_after = 0
        self.ticks = 0
        self.host_utime = 0
        self.cam_utime = 0

    def encode(self):
        buf = BytesIO()
        buf.write(timedrift_t._get_packed_fingerprint())
        self._encode_one(buf)
        return buf.getvalue()

    def _encode_one(self, buf):
        buf.write(struct.pack(">qqdqqqqq", self.sync_host, self.sync_ticks, self.ticks_sec, self.host_before, self.host_after, self.ticks, self.host_utime, self.cam_utime))

    def decode(data):
        if hasattr(data, 'read'):
            buf = data
        else:
            buf = BytesIO(data)
        if buf.read(8) != timedrift_t._get_packed_fingerprint():
            raise ValueError("Decode error")
        return timedrift_t._decode_one(buf)
    decode = staticmethod(decode)

    def _decode_one(buf):
        self = timedrift_t()
        self.sync_host, self.sync_ticks, self.ticks_sec, self.host_before, self.host_after, self.ticks, self.host_utime, self.cam_utime = struct.unpack(">qqdqqqqq", buf.read(64))
        return self
    _decode_one = staticmethod(_decode_one)

    def _get_hash_recursive(parents):
        if timedrift_t in parents: return 0
        tmphash = (0x3144eb295ac5e503) & 0xffffffffffffffff
        tmphash  = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff
        return tmphash
    _get_hash_recursive = staticmethod(_get_hash_recursive)
    _packed_fingerprint = None

    def _get_packed_fingerprint():
        if timedrift_t._packed_fingerprint is None:
            timedrift_t._packed_fingerprint = struct.pack(">Q", timedrift_t._get_hash_recursive([]))
        return timedrift_t._packed_fingerprint
    _get_packed_fingerprint = staticmethod(_get_packed_fingerprint)

    def get_hash(self):
        """Get the LCM hash of the struct"""
        return struct.unpack(">Q", timedrift_t._get_packed_fingerprint())[0]

