"""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 integer_entry_t(object):
    __slots__ = ["key", "value"]

    __typenames__ = ["string", "int64_t"]

    __dimensions__ = [None, None]

    def __init__(self):
        self.key = ""
        self.value = 0

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

    def _encode_one(self, buf):
        __key_encoded = self.key.encode('utf-8')
        buf.write(struct.pack('>I', len(__key_encoded)+1))
        buf.write(__key_encoded)
        buf.write(b"\0")
        buf.write(struct.pack(">q", self.value))

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

    def _decode_one(buf):
        self = integer_entry_t()
        __key_len = struct.unpack('>I', buf.read(4))[0]
        self.key = buf.read(__key_len)[:-1].decode('utf-8', 'replace')
        self.value = struct.unpack(">q", buf.read(8))[0]
        return self
    _decode_one = staticmethod(_decode_one)

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

