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


from io import BytesIO
import struct

import drake

class lcmt_contact_results_for_viz(object):

    __slots__ = ["timestamp", "num_point_pair_contacts", "point_pair_contact_info", "num_hydroelastic_contacts", "hydroelastic_contacts"]

    __typenames__ = ["int64_t", "int32_t", "drake.lcmt_point_pair_contact_info_for_viz", "int32_t", "drake.lcmt_hydroelastic_contact_surface_for_viz"]

    __dimensions__ = [None, None, ["num_point_pair_contacts"], None, ["num_hydroelastic_contacts"]]

    def __init__(self):
        self.timestamp = 0
        """
        in microseconds
        LCM Type: int64_t
        """

        self.num_point_pair_contacts = 0
        """ LCM Type: int32_t """
        self.point_pair_contact_info = []
        """ LCM Type: drake.lcmt_point_pair_contact_info_for_viz[num_point_pair_contacts] """
        self.num_hydroelastic_contacts = 0
        """ LCM Type: int32_t """
        self.hydroelastic_contacts = []
        """ LCM Type: drake.lcmt_hydroelastic_contact_surface_for_viz[num_hydroelastic_contacts] """

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">qi", self.timestamp, self.num_point_pair_contacts))
        for i0 in range(self.num_point_pair_contacts):
            assert self.point_pair_contact_info[i0]._get_packed_fingerprint() == drake.lcmt_point_pair_contact_info_for_viz._get_packed_fingerprint()
            self.point_pair_contact_info[i0]._encode_one(buf)
        buf.write(struct.pack(">i", self.num_hydroelastic_contacts))
        for i0 in range(self.num_hydroelastic_contacts):
            assert self.hydroelastic_contacts[i0]._get_packed_fingerprint() == drake.lcmt_hydroelastic_contact_surface_for_viz._get_packed_fingerprint()
            self.hydroelastic_contacts[i0]._encode_one(buf)

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

    @staticmethod
    def _decode_one(buf):
        self = lcmt_contact_results_for_viz()
        self.timestamp, self.num_point_pair_contacts = struct.unpack(">qi", buf.read(12))
        self.point_pair_contact_info = []
        for i0 in range(self.num_point_pair_contacts):
            self.point_pair_contact_info.append(drake.lcmt_point_pair_contact_info_for_viz._decode_one(buf))
        self.num_hydroelastic_contacts = struct.unpack(">i", buf.read(4))[0]
        self.hydroelastic_contacts = []
        for i0 in range(self.num_hydroelastic_contacts):
            self.hydroelastic_contacts.append(drake.lcmt_hydroelastic_contact_surface_for_viz._decode_one(buf))
        return self

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

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

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

