"""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_t(object):
    __slots__ = ["utime", "n_pings", "angle_range", "pings"]

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

    __dimensions__ = [None, None, None, ["n_pings"]]

    def __init__(self):
        self.utime = 0
        self.n_pings = 0
        self.angle_range = 0.0
        self.pings = []

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">qhd", self.utime, self.n_pings, self.angle_range))
        buf.write(struct.pack('>%dd' % self.n_pings, *self.pings[:self.n_pings]))

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

    def _decode_one(buf):
        self = multibeam_t()
        self.utime, self.n_pings, self.angle_range = struct.unpack(">qhd", buf.read(18))
        self.pings = struct.unpack('>%dd' % self.n_pings, buf.read(self.n_pings * 8))
        return self
    _decode_one = staticmethod(_decode_one)

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

