"""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 total_focus_image(object):
    __slots__ = ["timestamp", "frameRate", "width", "height", "dataType", "pixelType", "dataSize", "data"]

    __typenames__ = ["int64_t", "int32_t", "int32_t", "int32_t", "int32_t", "int32_t", "int32_t", "byte"]

    __dimensions__ = [None, None, None, None, None, None, None, ["dataSize"]]

    def __init__(self):
        self.timestamp = 0
        self.frameRate = 0
        self.width = 0
        self.height = 0
        self.dataType = 0
        self.pixelType = 0
        self.dataSize = 0
        self.data = ""

    def encode(self):
        buf = BytesIO()
        buf.write(total_focus_image._get_packed_fingerprint())
        self._encode_one(buf)
        return buf.getvalue()

    def _encode_one(self, buf):
        buf.write(struct.pack(">qiiiiii", self.timestamp, self.frameRate, self.width, self.height, self.dataType, self.pixelType, self.dataSize))
        buf.write(bytearray(self.data[:self.dataSize]))

    def decode(data):
        if hasattr(data, 'read'):
            buf = data
        else:
            buf = BytesIO(data)
        if buf.read(8) != total_focus_image._get_packed_fingerprint():
            raise ValueError("Decode error")
        return total_focus_image._decode_one(buf)
    decode = staticmethod(decode)

    def _decode_one(buf):
        self = total_focus_image()
        self.timestamp, self.frameRate, self.width, self.height, self.dataType, self.pixelType, self.dataSize = struct.unpack(">qiiiiii", buf.read(32))
        self.data = buf.read(self.dataSize)
        return self
    _decode_one = staticmethod(_decode_one)

    _hash = None
    def _get_hash_recursive(parents):
        if total_focus_image in parents: return 0
        tmphash = (0xd1a47a128645ce77) & 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 total_focus_image._packed_fingerprint is None:
            total_focus_image._packed_fingerprint = struct.pack(">Q", total_focus_image._get_hash_recursive([]))
        return total_focus_image._packed_fingerprint
    _get_packed_fingerprint = staticmethod(_get_packed_fingerprint)

