"""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

from . import DoubleVector

from . import FloatVector

from . import IntVector

from . import StringVector

class DataVectors(object):
    __slots__ = ["epochMillisec", "seqNo", "nIntVectors", "intVector", "nFloatVectors", "floatVector", "nDoubleVectors", "doubleVector", "nStringVectors", "stringVector"]

    __typenames__ = ["int64_t", "int64_t", "int32_t", "lcmMessages.IntVector", "int32_t", "lcmMessages.FloatVector", "int32_t", "lcmMessages.DoubleVector", "int32_t", "lcmMessages.StringVector"]

    __dimensions__ = [None, None, None, ["nIntVectors"], None, ["nFloatVectors"], None, ["nDoubleVectors"], None, ["nStringVectors"]]

    def __init__(self):
        self.epochMillisec = 0
        self.seqNo = 0
        self.nIntVectors = 0
        self.intVector = []
        self.nFloatVectors = 0
        self.floatVector = []
        self.nDoubleVectors = 0
        self.doubleVector = []
        self.nStringVectors = 0
        self.stringVector = []

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

    def _encode_one(self, buf):
        buf.write(struct.pack(">qqi", self.epochMillisec, self.seqNo, self.nIntVectors))
        for i0 in range(self.nIntVectors):
            assert self.intVector[i0]._get_packed_fingerprint() == lcmMessages.IntVector._get_packed_fingerprint()
            self.intVector[i0]._encode_one(buf)
        buf.write(struct.pack(">i", self.nFloatVectors))
        for i0 in range(self.nFloatVectors):
            assert self.floatVector[i0]._get_packed_fingerprint() == lcmMessages.FloatVector._get_packed_fingerprint()
            self.floatVector[i0]._encode_one(buf)
        buf.write(struct.pack(">i", self.nDoubleVectors))
        for i0 in range(self.nDoubleVectors):
            assert self.doubleVector[i0]._get_packed_fingerprint() == lcmMessages.DoubleVector._get_packed_fingerprint()
            self.doubleVector[i0]._encode_one(buf)
        buf.write(struct.pack(">i", self.nStringVectors))
        for i0 in range(self.nStringVectors):
            assert self.stringVector[i0]._get_packed_fingerprint() == lcmMessages.StringVector._get_packed_fingerprint()
            self.stringVector[i0]._encode_one(buf)

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

    def _decode_one(buf):
        self = DataVectors()
        self.epochMillisec, self.seqNo, self.nIntVectors = struct.unpack(">qqi", buf.read(20))
        self.intVector = []
        for i0 in range(self.nIntVectors):
            self.intVector.append(lcmMessages.IntVector._decode_one(buf))
        self.nFloatVectors = struct.unpack(">i", buf.read(4))[0]
        self.floatVector = []
        for i0 in range(self.nFloatVectors):
            self.floatVector.append(lcmMessages.FloatVector._decode_one(buf))
        self.nDoubleVectors = struct.unpack(">i", buf.read(4))[0]
        self.doubleVector = []
        for i0 in range(self.nDoubleVectors):
            self.doubleVector.append(lcmMessages.DoubleVector._decode_one(buf))
        self.nStringVectors = struct.unpack(">i", buf.read(4))[0]
        self.stringVector = []
        for i0 in range(self.nStringVectors):
            self.stringVector.append(lcmMessages.StringVector._decode_one(buf))
        return self
    _decode_one = staticmethod(_decode_one)

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

