"""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 multibeam_xy_t(object):
    __slots__ = ["utime", "npoints", "quality", "data"]

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

    __dimensions__ = [None, None, ["npoints"], ["npoints", 3]]

    QUALITY_INVALID = 0
    QUALITY_VALID = 1

    def __init__(self):
        self.utime = 0
        self.npoints = 0
        self.quality = []
        self.data = []

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">qi", self.utime, self.npoints))
        buf.write(struct.pack('>%di' % self.npoints, *self.quality[:self.npoints]))
        for i0 in range(self.npoints):
            buf.write(struct.pack('>3d', *self.data[i0][:3]))

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

    def _decode_one(buf):
        self = multibeam_xy_t()
        self.utime, self.npoints = struct.unpack(">qi", buf.read(12))
        self.quality = struct.unpack('>%di' % self.npoints, buf.read(self.npoints * 4))
        self.data = []
        for i0 in range(self.npoints):
            self.data.append(struct.unpack('>3d', buf.read(24)))
        return self
    _decode_one = staticmethod(_decode_one)

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

