"""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 StringVector(object):
    __slots__ = ["name", "nVal", "val"]

    __typenames__ = ["string", "int32_t", "string"]

    __dimensions__ = [None, None, ["nVal"]]

    def __init__(self):
        self.name = ""
        self.nVal = 0
        self.val = []

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

    def _encode_one(self, buf):
        __name_encoded = self.name.encode('utf-8')
        buf.write(struct.pack('>I', len(__name_encoded)+1))
        buf.write(__name_encoded)
        buf.write(b"\0")
        buf.write(struct.pack(">i", self.nVal))
        for i0 in range(self.nVal):
            __val_encoded = self.val[i0].encode('utf-8')
            buf.write(struct.pack('>I', len(__val_encoded)+1))
            buf.write(__val_encoded)
            buf.write(b"\0")

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

    def _decode_one(buf):
        self = StringVector()
        __name_len = struct.unpack('>I', buf.read(4))[0]
        self.name = buf.read(__name_len)[:-1].decode('utf-8', 'replace')
        self.nVal = struct.unpack(">i", buf.read(4))[0]
        self.val = []
        for i0 in range(self.nVal):
            __val_len = struct.unpack('>I', buf.read(4))[0]
            self.val.append(buf.read(__val_len)[:-1].decode('utf-8', 'replace'))
        return self
    _decode_one = staticmethod(_decode_one)

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

