"""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 kearfott_t(object):
    __slots__ = ["time_unix_sec", "count_publish", "sender_id", "cycles_uint", "mode", "monitor", "latitude_rad", "longitude_rad", "northing_m", "easting_m", "depth_m", "bheight_m", "roll_rad", "pitch_rad", "heading_rad", "vbodyx_ms", "vbodyy_ms", "vbodyz_ms", "accelx_ms2", "accely_ms2", "accelz_ms2", "prate_rads", "qrate_rads", "rrate_rads", "utcTime", "sampleTime", "num_doubles", "doubles"]

    __typenames__ = ["double", "int64_t", "string", "int16_t", "byte", "byte", "double", "double", "double", "double", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "float", "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, ["num_doubles"]]

    def __init__(self):
        self.time_unix_sec = 0.0
        self.count_publish = 0
        self.sender_id = ""
        self.cycles_uint = 0
        self.mode = 0
        self.monitor = 0
        self.latitude_rad = 0.0
        self.longitude_rad = 0.0
        self.northing_m = 0.0
        self.easting_m = 0.0
        self.depth_m = 0.0
        self.bheight_m = 0.0
        self.roll_rad = 0.0
        self.pitch_rad = 0.0
        self.heading_rad = 0.0
        self.vbodyx_ms = 0.0
        self.vbodyy_ms = 0.0
        self.vbodyz_ms = 0.0
        self.accelx_ms2 = 0.0
        self.accely_ms2 = 0.0
        self.accelz_ms2 = 0.0
        self.prate_rads = 0.0
        self.qrate_rads = 0.0
        self.rrate_rads = 0.0
        self.utcTime = 0.0
        self.sampleTime = 0.0
        self.num_doubles = 0
        self.doubles = []

    def encode(self):
        buf = BytesIO()
        buf.write(kearfott_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(">hBBddddffffffffffffffffh", self.cycles_uint, self.mode, self.monitor, self.latitude_rad, self.longitude_rad, self.northing_m, self.easting_m, self.depth_m, self.bheight_m, self.roll_rad, self.pitch_rad, self.heading_rad, self.vbodyx_ms, self.vbodyy_ms, self.vbodyz_ms, self.accelx_ms2, self.accely_ms2, self.accelz_ms2, self.prate_rads, self.qrate_rads, self.rrate_rads, self.utcTime, self.sampleTime, 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) != kearfott_t._get_packed_fingerprint():
            raise ValueError("Decode error")
        return kearfott_t._decode_one(buf)
    decode = staticmethod(decode)

    def _decode_one(buf):
        self = kearfott_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.cycles_uint, self.mode, self.monitor, self.latitude_rad, self.longitude_rad, self.northing_m, self.easting_m, self.depth_m, self.bheight_m, self.roll_rad, self.pitch_rad, self.heading_rad, self.vbodyx_ms, self.vbodyy_ms, self.vbodyz_ms, self.accelx_ms2, self.accely_ms2, self.accelz_ms2, self.prate_rads, self.qrate_rads, self.rrate_rads, self.utcTime, self.sampleTime, self.num_doubles = struct.unpack(">hBBddddffffffffffffffffh", buf.read(102))
        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 kearfott_t in parents: return 0
        newparents = parents + [kearfott_t]
        tmphash = (0xb3fe10b7f94bb7a6+ 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 kearfott_t._packed_fingerprint is None:
            kearfott_t._packed_fingerprint = struct.pack(">Q", kearfott_t._get_hash_recursive([]))
        return kearfott_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", kearfott_t._get_packed_fingerprint())[0]

