"""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 bounding_box_t(object):
    __slots__ = ["utime", "left", "top", "width", "height", "num_classes", "scores", "class_name", "channel"]

    __typenames__ = ["int64_t", "double", "double", "double", "double", "int8_t", "double", "string", "int8_t"]

    __dimensions__ = [None, None, None, None, None, None, ["num_classes"], None, None]

    def __init__(self):
        self.utime = 0
        self.left = 0.0
        self.top = 0.0
        self.width = 0.0
        self.height = 0.0
        self.num_classes = 0
        self.scores = []
        self.class_name = ""
        self.channel = 0

    def encode(self):
        buf = BytesIO()
        buf.write(bounding_box_t._get_packed_fingerprint())
        self._encode_one(buf)
        return buf.getvalue()

    def _encode_one(self, buf):
        buf.write(struct.pack(">qddddb", self.utime, self.left, self.top, self.width, self.height, self.num_classes))
        buf.write(struct.pack('>%dd' % self.num_classes, *self.scores[:self.num_classes]))
        __class_name_encoded = self.class_name.encode('utf-8')
        buf.write(struct.pack('>I', len(__class_name_encoded)+1))
        buf.write(__class_name_encoded)
        buf.write(b"\0")
        buf.write(struct.pack(">b", self.channel))

    def decode(data):
        if hasattr(data, 'read'):
            buf = data
        else:
            buf = BytesIO(data)
        if buf.read(8) != bounding_box_t._get_packed_fingerprint():
            raise ValueError("Decode error")
        return bounding_box_t._decode_one(buf)
    decode = staticmethod(decode)

    def _decode_one(buf):
        self = bounding_box_t()
        self.utime, self.left, self.top, self.width, self.height, self.num_classes = struct.unpack(">qddddb", buf.read(41))
        self.scores = struct.unpack('>%dd' % self.num_classes, buf.read(self.num_classes * 8))
        __class_name_len = struct.unpack('>I', buf.read(4))[0]
        self.class_name = buf.read(__class_name_len)[:-1].decode('utf-8', 'replace')
        self.channel = struct.unpack(">b", buf.read(1))[0]
        return self
    _decode_one = staticmethod(_decode_one)

    _hash = None
    def _get_hash_recursive(parents):
        if bounding_box_t in parents: return 0
        tmphash = (0xc6bbb40d4ecc6197) & 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 bounding_box_t._packed_fingerprint is None:
            bounding_box_t._packed_fingerprint = struct.pack(">Q", bounding_box_t._get_hash_recursive([]))
        return bounding_box_t._packed_fingerprint
    _get_packed_fingerprint = staticmethod(_get_packed_fingerprint)

