"""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.oi.double_t

class rdi_pd4_t(object):
    __slots__ = ["time_unix_sec", "count_publish", "sender_id", "dvl_id", "datstr", "num_bytes_uint", "sysconfig", "xvelbtm_mms", "yvelbtm_mms", "zvelbtm_mms", "evelbtm_mms", "beam1_cm_uint", "beam2_cm_uint", "beam3_cm_uint", "beam4_cm_uint", "bottom_stat", "xvel_ref_mms", "yvel_ref_mms", "zvel_ref_mms", "evel_ref_mms", "ref_layer_start_dm_uint", "ref_layer_end_dm_uint", "ref_layer_status", "time_of_ping_hr", "time_of_ping_min", "time_of_ping_sec", "time_of_ping_hun", "built_in_test_uint", "speed_of_sound_ms_uint", "temperature_cdegC", "checksum_uint", "ktnav_uint", "num_doubles", "doubles"]

    __typenames__ = ["double", "int64_t", "string", "byte", "byte", "int16_t", "byte", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "byte", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "byte", "byte", "byte", "byte", "byte", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "int16_t", "compas_lcmtypes.oi.double_t"]

    __dimensions__ = [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, ["num_doubles"]]

    def __init__(self):
        self.time_unix_sec = 0.0
        self.count_publish = 0
        self.sender_id = ""
        self.dvl_id = 0
        self.datstr = 0
        self.num_bytes_uint = 0
        self.sysconfig = 0
        self.xvelbtm_mms = 0
        self.yvelbtm_mms = 0
        self.zvelbtm_mms = 0
        self.evelbtm_mms = 0
        self.beam1_cm_uint = 0
        self.beam2_cm_uint = 0
        self.beam3_cm_uint = 0
        self.beam4_cm_uint = 0
        self.bottom_stat = 0
        self.xvel_ref_mms = 0
        self.yvel_ref_mms = 0
        self.zvel_ref_mms = 0
        self.evel_ref_mms = 0
        self.ref_layer_start_dm_uint = 0
        self.ref_layer_end_dm_uint = 0
        self.ref_layer_status = 0
        self.time_of_ping_hr = 0
        self.time_of_ping_min = 0
        self.time_of_ping_sec = 0
        self.time_of_ping_hun = 0
        self.built_in_test_uint = 0
        self.speed_of_sound_ms_uint = 0
        self.temperature_cdegC = 0
        self.checksum_uint = 0
        self.ktnav_uint = 0
        self.num_doubles = 0
        self.doubles = []

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">dq", self.time_unix_sec, self.count_publish))
        __sender_id_encoded = self.sender_id.encode('utf-8')
        buf.write(struct.pack('>I', len(__sender_id_encoded)+1))
        buf.write(__sender_id_encoded)
        buf.write(b"\0")
        buf.write(struct.pack(">BBhBhhhhhhhhBhhhhhhBBBBBhhhhhh", self.dvl_id, self.datstr, self.num_bytes_uint, self.sysconfig, self.xvelbtm_mms, self.yvelbtm_mms, self.zvelbtm_mms, self.evelbtm_mms, self.beam1_cm_uint, self.beam2_cm_uint, self.beam3_cm_uint, self.beam4_cm_uint, self.bottom_stat, self.xvel_ref_mms, self.yvel_ref_mms, self.zvel_ref_mms, self.evel_ref_mms, self.ref_layer_start_dm_uint, self.ref_layer_end_dm_uint, self.ref_layer_status, self.time_of_ping_hr, self.time_of_ping_min, self.time_of_ping_sec, self.time_of_ping_hun, self.built_in_test_uint, self.speed_of_sound_ms_uint, self.temperature_cdegC, self.checksum_uint, self.ktnav_uint, self.num_doubles))
        for i0 in range(self.num_doubles):
            assert self.doubles[i0]._get_packed_fingerprint() == compas_lcmtypes.oi.double_t._get_packed_fingerprint()
            self.doubles[i0]._encode_one(buf)

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

    def _decode_one(buf):
        self = rdi_pd4_t()
        self.time_unix_sec, self.count_publish = struct.unpack(">dq", buf.read(16))
        __sender_id_len = struct.unpack('>I', buf.read(4))[0]
        self.sender_id = buf.read(__sender_id_len)[:-1].decode('utf-8', 'replace')
        self.dvl_id, self.datstr, self.num_bytes_uint, self.sysconfig, self.xvelbtm_mms, self.yvelbtm_mms, self.zvelbtm_mms, self.evelbtm_mms, self.beam1_cm_uint, self.beam2_cm_uint, self.beam3_cm_uint, self.beam4_cm_uint, self.bottom_stat, self.xvel_ref_mms, self.yvel_ref_mms, self.zvel_ref_mms, self.evel_ref_mms, self.ref_layer_start_dm_uint, self.ref_layer_end_dm_uint, self.ref_layer_status, self.time_of_ping_hr, self.time_of_ping_min, self.time_of_ping_sec, self.time_of_ping_hun, self.built_in_test_uint, self.speed_of_sound_ms_uint, self.temperature_cdegC, self.checksum_uint, self.ktnav_uint, self.num_doubles = struct.unpack(">BBhBhhhhhhhhBhhhhhhBBBBBhhhhhh", buf.read(51))
        self.doubles = []
        for i0 in range(self.num_doubles):
            self.doubles.append(compas_lcmtypes.oi.double_t._decode_one(buf))
        return self
    _decode_one = staticmethod(_decode_one)

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

