"""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 cmd_t(object):
    __slots__ = ["utime", "force"]

    __typenames__ = ["int64_t", "double"]

    __dimensions__ = [None, [6]]

    def __init__(self):
        self.utime = 0
        self.force = [ 0.0 for dim0 in range(6) ]

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">q", self.utime))
        buf.write(struct.pack('>6d', *self.force[:6]))

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

    def _decode_one(buf):
        self = cmd_t()
        self.utime = struct.unpack(">q", buf.read(8))[0]
        self.force = struct.unpack('>6d', buf.read(48))
        return self
    _decode_one = staticmethod(_decode_one)

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

