import dds
import ddsutil
import struct

class MultiArrayLayout___TypeSupport(dds.TypeSupport):

    _typename = 'std_msgs::msg::dds_::MultiArrayLayout_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="std_msgs"><Module name="msg"><Module name="dds_"><Struct name="MultiArrayDimension_"><Member name="label_"><String/></Member><Member name="size_"><ULong/></Member><Member name="stride_"><ULong/></Member></Struct><Struct name="MultiArrayLayout_"><Member name="dim_"><Sequence><Type name="MultiArrayDimension_"/></Sequence></Member><Member name="data_offset_"><ULong/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(MultiArrayLayout___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(MultiArrayLayout_()._get_packing_fmt()))

    def _serialize(self, o):
        if not isinstance(o, MultiArrayLayout_):
            raise TypeError('Incorrect data type')
        result = o._serialize()
        return result

    def _deserialize(self, buf):
        result = MultiArrayLayout_()
        data = struct.unpack(result._get_packing_fmt(), buf)
        result._deserialize(list(data))
        return result

class MultiArrayLayout_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return MultiArrayLayout___TypeSupport()

    @property
    def dim_(self):
        '''
        a DDS sequence<std_msgs::msg::dds_::MultiArrayDimension_> value
        @rtype: list
        '''
        return self._dim__

    _dim__checker = ddsutil._seq_checker(0,ddsutil._class_checker(MultiArrayDimension_))
    @dim_.setter
    def dim_(self, value):
        self._dim__checker(value)
        self._dim__ = value

    @property
    def data_offset_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._data_offset__

    _data_offset__checker = ddsutil._ulong_checker
    @data_offset_.setter
    def data_offset_(self, value):
        self._data_offset__checker(value)
        self._data_offset__ = value

    _member_attributes = ('dim_', 'data_offset_')

    def __init__(self, **kwargs):
        ''' Create a MultiArrayLayout_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.dim_ = []
        self.data_offset_ = 0
        # set values for attributes passed in
        for key, value in kwargs.items():
            if key not in self._member_attributes:
                raise TypeError('Invalid argument name : %s' %(key))
            setattr(self, key, value)

    _packing_fmt = None

    @staticmethod
    def _get_packing_fmt():
        ''' Returns packing format of this class data '''
        if MultiArrayLayout_._packing_fmt is not None:
            return MultiArrayLayout_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))
        fmt += 'I'

        MultiArrayLayout_._packing_fmt = ddsutil._pad_fmt(fmt)
        return MultiArrayLayout_._packing_fmt

    def _serialize(self):
        ''' Serialize data for writing '''
        fmt = self._get_packing_fmt()
        args = self._get_packing_args()
        result = struct.pack(fmt, *args)
        return result

    def _deserialize(self, data):
        ''' Initialize values from data returned by struct.unpack()'''
        self.dim_ = ddsutil._deserialize_seq(data, MultiArrayDimension_._get_packing_fmt(), lambda seq_data: MultiArrayDimension_()._deserialize(seq_data))
        self.data_offset_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(ddsutil._serialize_seq(self.dim_, MultiArrayDimension_._get_packing_fmt(), lambda seq_args, v: seq_args.extend(v._get_packing_args())))
        args.append(self.data_offset_)
        return args

