"""LCM type definitions
This file automatically generated by lcm.
DO NOT MODIFY BY HAND!!!!
"""


from io import BytesIO
import struct

import drake

class lcmt_robot_plan(object):

    __slots__ = ["utime", "num_states", "plan"]

    __typenames__ = ["int64_t", "int32_t", "drake.lcmt_robot_state"]

    __dimensions__ = [None, None, ["num_states"]]

    def __init__(self):
        self.utime = 0
        """ LCM Type: int64_t """
        self.num_states = 0
        """ LCM Type: int32_t """
        self.plan = []
        """ LCM Type: drake.lcmt_robot_state[num_states] """

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">qi", self.utime, self.num_states))
        for i0 in range(self.num_states):
            assert self.plan[i0]._get_packed_fingerprint() == drake.lcmt_robot_state._get_packed_fingerprint()
            self.plan[i0]._encode_one(buf)

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

    @staticmethod
    def _decode_one(buf):
        self = lcmt_robot_plan()
        self.utime, self.num_states = struct.unpack(">qi", buf.read(12))
        self.plan = []
        for i0 in range(self.num_states):
            self.plan.append(drake.lcmt_robot_state._decode_one(buf))
        return self

    @staticmethod
    def _get_hash_recursive(parents):
        if lcmt_robot_plan in parents: return 0
        newparents = parents + [lcmt_robot_plan]
        tmphash = (0x819ba3bc0a8b9ad2+ drake.lcmt_robot_state._get_hash_recursive(newparents)) & 0xffffffffffffffff
        tmphash  = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff
        return tmphash
    _packed_fingerprint = None

    @staticmethod
    def _get_packed_fingerprint():
        if lcmt_robot_plan._packed_fingerprint is None:
            lcmt_robot_plan._packed_fingerprint = struct.pack(">Q", lcmt_robot_plan._get_hash_recursive([]))
        return lcmt_robot_plan._packed_fingerprint

    def get_hash(self):
        """Get the LCM hash of the struct"""
        return struct.unpack(">Q", lcmt_robot_plan._get_packed_fingerprint())[0]

