"""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 new_image_t(object):
    __slots__ = ["command_id", "instance", "image_pathname", "n_sec"]

    def __init__(self):
        self.command_id = 0
        self.instance = 0
        self.image_pathname = ""
        self.n_sec = 0

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">qi", self.command_id, self.instance))
        __image_pathname_encoded = self.image_pathname.encode('utf-8')
        buf.write(struct.pack('>I', len(__image_pathname_encoded)+1))
        buf.write(__image_pathname_encoded)
        buf.write(b"\0")
        buf.write(struct.pack(">q", self.n_sec))

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

    def _decode_one(buf):
        self = new_image_t()
        self.command_id, self.instance = struct.unpack(">qi", buf.read(12))
        __image_pathname_len = struct.unpack('>I', buf.read(4))[0]
        self.image_pathname = buf.read(__image_pathname_len)[:-1].decode('utf-8', 'replace')
        self.n_sec = struct.unpack(">q", buf.read(8))[0]
        return self
    _decode_one = staticmethod(_decode_one)

    _hash = None
    def _get_hash_recursive(parents):
        if new_image_t in parents: return 0
        tmphash = (0x6541429b545277e0) & 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 new_image_t._packed_fingerprint is None:
            new_image_t._packed_fingerprint = struct.pack(">Q", new_image_t._get_hash_recursive([]))
        return new_image_t._packed_fingerprint
    _get_packed_fingerprint = staticmethod(_get_packed_fingerprint)

