"""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 particle_config(object):
    __slots__ = ["publisher", "detector"]

    __typenames__ = ["string", "string"]

    __dimensions__ = [None, None]

    def __init__(self):
        self.publisher = ""
        self.detector = ""

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

    def _encode_one(self, buf):
        __publisher_encoded = self.publisher.encode('utf-8')
        buf.write(struct.pack('>I', len(__publisher_encoded)+1))
        buf.write(__publisher_encoded)
        buf.write(b"\0")
        __detector_encoded = self.detector.encode('utf-8')
        buf.write(struct.pack('>I', len(__detector_encoded)+1))
        buf.write(__detector_encoded)
        buf.write(b"\0")

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

    def _decode_one(buf):
        self = particle_config()
        __publisher_len = struct.unpack('>I', buf.read(4))[0]
        self.publisher = buf.read(__publisher_len)[:-1].decode('utf-8', 'replace')
        __detector_len = struct.unpack('>I', buf.read(4))[0]
        self.detector = buf.read(__detector_len)[:-1].decode('utf-8', 'replace')
        return self
    _decode_one = staticmethod(_decode_one)

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

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

