"""autogenerated by genmsg_py from Embed.msg. Do not edit."""
import roslib.message
import struct

import test_rostopic.msg
import roslib.rostime

class Embed(roslib.message.Message):
  _md5sum = "6dec891298f3675c2d964c161d28efaa"
  _type = "test_rostopic/Embed"
  _has_header = False #flag to mark the presence of a Header object
  _full_text = """Simple simple
Arrays arrays

================================================================================
MSG: test_rostopic/Simple
byte b
int16 int16
int32 int32
int64 int64
char c
uint16 uint16
uint32 uint32
uint64 uint64
string str

================================================================================
MSG: test_rostopic/Arrays
int8[] int8_arr
uint8[] uint8_arr
int32[] int32_arr
uint32[] uint32_arr
string[] string_arr
time[] time_arr

"""
  __slots__ = ['simple','arrays']
  _slot_types = ['test_rostopic/Simple','test_rostopic/Arrays']

  def __init__(self, *args, **kwds):
    """
    Constructor. Any message fields that are implicitly/explicitly
    set to None will be assigned a default value. The recommend
    use is keyword arguments as this is more robust to future message
    changes.  You cannot mix in-order arguments and keyword arguments.
    
    The available fields are:
       simple,arrays
    
    @param args: complete set of field values, in .msg order
    @param kwds: use keyword arguments corresponding to message field names
    to set specific fields. 
    """
    if args or kwds:
      super(Embed, self).__init__(*args, **kwds)
      #message fields cannot be None, assign default values for those that are
      if self.simple is None:
        self.simple = test_rostopic.msg.Simple()
      if self.arrays is None:
        self.arrays = test_rostopic.msg.Arrays()
    else:
      self.simple = test_rostopic.msg.Simple()
      self.arrays = test_rostopic.msg.Arrays()

  def _get_types(self):
    """
    internal API method
    """
    return self._slot_types

  def serialize(self, buff):
    """
    serialize message into buffer
    @param buff: buffer
    @type  buff: StringIO
    """
    try:
      _x = self
      buff.write(_struct_bhiqBHIQ.pack(_x.simple.b, _x.simple.int16, _x.simple.int32, _x.simple.int64, _x.simple.c, _x.simple.uint16, _x.simple.uint32, _x.simple.uint64))
      _x = self.simple.str
      length = len(_x)
      buff.write(struct.pack('<I%ss'%length, length, _x))
      length = len(self.arrays.int8_arr)
      buff.write(_struct_I.pack(length))
      pattern = '<%sb'%length
      buff.write(struct.pack(pattern, *self.arrays.int8_arr))
      _x = self.arrays.uint8_arr
      length = len(_x)
      # - if encoded as a list instead, serialize as bytes instead of string
      if type(_x) in [list, tuple]:
        buff.write(struct.pack('<I%sB'%length, length, *_x))
      else:
        buff.write(struct.pack('<I%ss'%length, length, _x))
      length = len(self.arrays.int32_arr)
      buff.write(_struct_I.pack(length))
      pattern = '<%si'%length
      buff.write(struct.pack(pattern, *self.arrays.int32_arr))
      length = len(self.arrays.uint32_arr)
      buff.write(_struct_I.pack(length))
      pattern = '<%sI'%length
      buff.write(struct.pack(pattern, *self.arrays.uint32_arr))
      length = len(self.arrays.string_arr)
      buff.write(_struct_I.pack(length))
      for val1 in self.arrays.string_arr:
        length = len(val1)
        buff.write(struct.pack('<I%ss'%length, length, val1))
      length = len(self.arrays.time_arr)
      buff.write(_struct_I.pack(length))
      for val1 in self.arrays.time_arr:
        _x = val1
        buff.write(_struct_2I.pack(_x.secs, _x.nsecs))
    except struct.error, se: self._check_types(se)
    except TypeError, te: self._check_types(te)

  def deserialize(self, str):
    """
    unpack serialized message in str into this message instance
    @param str: byte array of serialized message
    @type  str: str
    """
    try:
      if self.simple is None:
        self.simple = test_rostopic.msg.Simple()
      if self.arrays is None:
        self.arrays = test_rostopic.msg.Arrays()
      end = 0
      _x = self
      start = end
      end += 30
      (_x.simple.b, _x.simple.int16, _x.simple.int32, _x.simple.int64, _x.simple.c, _x.simple.uint16, _x.simple.uint32, _x.simple.uint64,) = _struct_bhiqBHIQ.unpack(str[start:end])
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      start = end
      end += length
      self.simple.str = str[start:end]
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      pattern = '<%sb'%length
      start = end
      end += struct.calcsize(pattern)
      self.arrays.int8_arr = struct.unpack(pattern, str[start:end])
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      start = end
      end += length
      self.arrays.uint8_arr = str[start:end]
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      pattern = '<%si'%length
      start = end
      end += struct.calcsize(pattern)
      self.arrays.int32_arr = struct.unpack(pattern, str[start:end])
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      pattern = '<%sI'%length
      start = end
      end += struct.calcsize(pattern)
      self.arrays.uint32_arr = struct.unpack(pattern, str[start:end])
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      self.arrays.string_arr = []
      for i in xrange(0, length):
        start = end
        end += 4
        (length,) = _struct_I.unpack(str[start:end])
        start = end
        end += length
        val1 = str[start:end]
        self.arrays.string_arr.append(val1)
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      self.arrays.time_arr = []
      for i in xrange(0, length):
        val1 = roslib.rostime.Time()
        _x = val1
        start = end
        end += 8
        (_x.secs, _x.nsecs,) = _struct_2I.unpack(str[start:end])
        self.arrays.time_arr.append(val1)
      return self
    except struct.error, e:
      raise roslib.message.DeserializationError(e) #most likely buffer underfill


  def serialize_numpy(self, buff, numpy):
    """
    serialize message with numpy array types into buffer
    @param buff: buffer
    @type  buff: StringIO
    @param numpy: numpy python module
    @type  numpy module
    """
    try:
      _x = self
      buff.write(_struct_bhiqBHIQ.pack(_x.simple.b, _x.simple.int16, _x.simple.int32, _x.simple.int64, _x.simple.c, _x.simple.uint16, _x.simple.uint32, _x.simple.uint64))
      _x = self.simple.str
      length = len(_x)
      buff.write(struct.pack('<I%ss'%length, length, _x))
      length = len(self.arrays.int8_arr)
      buff.write(_struct_I.pack(length))
      pattern = '<%sb'%length
      buff.write(self.arrays.int8_arr.tostring())
      _x = self.arrays.uint8_arr
      length = len(_x)
      # - if encoded as a list instead, serialize as bytes instead of string
      if type(_x) in [list, tuple]:
        buff.write(struct.pack('<I%sB'%length, length, *_x))
      else:
        buff.write(struct.pack('<I%ss'%length, length, _x))
      length = len(self.arrays.int32_arr)
      buff.write(_struct_I.pack(length))
      pattern = '<%si'%length
      buff.write(self.arrays.int32_arr.tostring())
      length = len(self.arrays.uint32_arr)
      buff.write(_struct_I.pack(length))
      pattern = '<%sI'%length
      buff.write(self.arrays.uint32_arr.tostring())
      length = len(self.arrays.string_arr)
      buff.write(_struct_I.pack(length))
      for val1 in self.arrays.string_arr:
        length = len(val1)
        buff.write(struct.pack('<I%ss'%length, length, val1))
      length = len(self.arrays.time_arr)
      buff.write(_struct_I.pack(length))
      for val1 in self.arrays.time_arr:
        _x = val1
        buff.write(_struct_2I.pack(_x.secs, _x.nsecs))
    except struct.error, se: self._check_types(se)
    except TypeError, te: self._check_types(te)

  def deserialize_numpy(self, str, numpy):
    """
    unpack serialized message in str into this message instance using numpy for array types
    @param str: byte array of serialized message
    @type  str: str
    @param numpy: numpy python module
    @type  numpy: module
    """
    try:
      if self.simple is None:
        self.simple = test_rostopic.msg.Simple()
      if self.arrays is None:
        self.arrays = test_rostopic.msg.Arrays()
      end = 0
      _x = self
      start = end
      end += 30
      (_x.simple.b, _x.simple.int16, _x.simple.int32, _x.simple.int64, _x.simple.c, _x.simple.uint16, _x.simple.uint32, _x.simple.uint64,) = _struct_bhiqBHIQ.unpack(str[start:end])
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      start = end
      end += length
      self.simple.str = str[start:end]
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      pattern = '<%sb'%length
      start = end
      end += struct.calcsize(pattern)
      self.arrays.int8_arr = numpy.frombuffer(str[start:end], dtype=numpy.int8, count=length)
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      start = end
      end += length
      self.arrays.uint8_arr = str[start:end]
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      pattern = '<%si'%length
      start = end
      end += struct.calcsize(pattern)
      self.arrays.int32_arr = numpy.frombuffer(str[start:end], dtype=numpy.int32, count=length)
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      pattern = '<%sI'%length
      start = end
      end += struct.calcsize(pattern)
      self.arrays.uint32_arr = numpy.frombuffer(str[start:end], dtype=numpy.uint32, count=length)
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      self.arrays.string_arr = []
      for i in xrange(0, length):
        start = end
        end += 4
        (length,) = _struct_I.unpack(str[start:end])
        start = end
        end += length
        val1 = str[start:end]
        self.arrays.string_arr.append(val1)
      start = end
      end += 4
      (length,) = _struct_I.unpack(str[start:end])
      self.arrays.time_arr = []
      for i in xrange(0, length):
        val1 = roslib.rostime.Time()
        _x = val1
        start = end
        end += 8
        (_x.secs, _x.nsecs,) = _struct_2I.unpack(str[start:end])
        self.arrays.time_arr.append(val1)
      return self
    except struct.error, e:
      raise roslib.message.DeserializationError(e) #most likely buffer underfill

_struct_I = roslib.message.struct_I
_struct_bhiqBHIQ = struct.Struct("<bhiqBHIQ")
_struct_2I = struct.Struct("<2I")
