"""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

import compas_lcmtypes.navlcm.position_t

class uuv_state_t(object):
    __slots__ = ["utime", "position", "altitude", "orglat", "orglon", "leak_state", "battery_percent"]

    __typenames__ = ["int64_t", "compas_lcmtypes.navlcm.position_t", "double", "double", "double", "boolean", "int32_t"]

    __dimensions__ = [None, None, None, None, None, None, None]

    def __init__(self):
        self.utime = 0
        self.position = compas_lcmtypes.navlcm.position_t()
        self.altitude = 0.0
        self.orglat = 0.0
        self.orglon = 0.0
        self.leak_state = False
        self.battery_percent = 0

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">q", self.utime))
        assert self.position._get_packed_fingerprint() == compas_lcmtypes.navlcm.position_t._get_packed_fingerprint()
        self.position._encode_one(buf)
        buf.write(struct.pack(">dddbi", self.altitude, self.orglat, self.orglon, self.leak_state, self.battery_percent))

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

    def _decode_one(buf):
        self = uuv_state_t()
        self.utime = struct.unpack(">q", buf.read(8))[0]
        self.position = compas_lcmtypes.navlcm.position_t._decode_one(buf)
        self.altitude, self.orglat, self.orglon = struct.unpack(">ddd", buf.read(24))
        self.leak_state = bool(struct.unpack('b', buf.read(1))[0])
        self.battery_percent = struct.unpack(">i", buf.read(4))[0]
        return self
    _decode_one = staticmethod(_decode_one)

    def _get_hash_recursive(parents):
        if uuv_state_t in parents: return 0
        newparents = parents + [uuv_state_t]
        tmphash = (0x337286d2f2d6bdc0+ compas_lcmtypes.navlcm.position_t._get_hash_recursive(newparents)) & 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 uuv_state_t._packed_fingerprint is None:
            uuv_state_t._packed_fingerprint = struct.pack(">Q", uuv_state_t._get_hash_recursive([]))
        return uuv_state_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", uuv_state_t._get_packed_fingerprint())[0]

