"""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.senlcm.rdi_pd4_t

class rdi_pd5_t(object):
    __slots__ = ["utime", "pd4", "salinity", "depth", "pitch", "roll", "heading", "dmg_btv", "dmg_wtv"]

    __typenames__ = ["int64_t", "compas_lcmtypes.senlcm.rdi_pd4_t", "double", "double", "double", "double", "double", "double", "double"]

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

    def __init__(self):
        self.utime = 0
        self.pd4 = compas_lcmtypes.senlcm.rdi_pd4_t()
        self.salinity = 0.0
        self.depth = 0.0
        self.pitch = 0.0
        self.roll = 0.0
        self.heading = 0.0
        self.dmg_btv = [ 0.0 for dim0 in range(4) ]
        self.dmg_wtv = [ 0.0 for dim0 in range(4) ]

    def encode(self):
        buf = BytesIO()
        buf.write(rdi_pd5_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.pd4._get_packed_fingerprint() == compas_lcmtypes.senlcm.rdi_pd4_t._get_packed_fingerprint()
        self.pd4._encode_one(buf)
        buf.write(struct.pack(">ddddd", self.salinity, self.depth, self.pitch, self.roll, self.heading))
        buf.write(struct.pack('>4d', *self.dmg_btv[:4]))
        buf.write(struct.pack('>4d', *self.dmg_wtv[:4]))

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

    def _decode_one(buf):
        self = rdi_pd5_t()
        self.utime = struct.unpack(">q", buf.read(8))[0]
        self.pd4 = compas_lcmtypes.senlcm.rdi_pd4_t._decode_one(buf)
        self.salinity, self.depth, self.pitch, self.roll, self.heading = struct.unpack(">ddddd", buf.read(40))
        self.dmg_btv = struct.unpack('>4d', buf.read(32))
        self.dmg_wtv = struct.unpack('>4d', buf.read(32))
        return self
    _decode_one = staticmethod(_decode_one)

    def _get_hash_recursive(parents):
        if rdi_pd5_t in parents: return 0
        newparents = parents + [rdi_pd5_t]
        tmphash = (0x94c4660b03ed5183+ compas_lcmtypes.senlcm.rdi_pd4_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 rdi_pd5_t._packed_fingerprint is None:
            rdi_pd5_t._packed_fingerprint = struct.pack(">Q", rdi_pd5_t._get_hash_recursive([]))
        return rdi_pd5_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", rdi_pd5_t._get_packed_fingerprint())[0]

