import dds
import ddsutil
import struct

class MultiArrayDimension___TypeSupport(dds.TypeSupport):

    _typename = 'std_msgs::msg::dds_::MultiArrayDimension_'
    _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></Module></Module></Module></MetaData>'

    def __init__(self):
        super(MultiArrayDimension___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(MultiArrayDimension_()._get_packing_fmt()))

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

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

class MultiArrayDimension_(ddsutil.TopicDataClass):

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

    @property
    def label_(self):
        '''
        a DDS string value
        @rtype: str
        '''
        return self._label__

    _label__checker = ddsutil._str_checker
    @label_.setter
    def label_(self, value):
        self._label__checker(value)
        self._label__ = value

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

    _size__checker = ddsutil._ulong_checker
    @size_.setter
    def size_(self, value):
        self._size__checker(value)
        self._size__ = value

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

    _stride__checker = ddsutil._ulong_checker
    @stride_.setter
    def stride_(self, value):
        self._stride__checker(value)
        self._stride__ = value

    _member_attributes = ('label_', 'size_', 'stride_')

    def __init__(self, **kwargs):
        ''' Create a MultiArrayDimension_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.label_ = ''
        self.size_ = 0
        self.stride_ = 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 MultiArrayDimension_._packing_fmt is not None:
            return MultiArrayDimension_._packing_fmt
        fmt = ''
        fmt += 'P'
        fmt += 'I'
        fmt += 'I'

        MultiArrayDimension_._packing_fmt = ddsutil._pad_fmt(fmt)
        return MultiArrayDimension_._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.label_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')
        self.size_ = data.pop(0)
        self.stride_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.append(ddsutil._bytes_to_ptr(self.label_.encode('ISO-8859-1')))
        args.append(self.size_)
        args.append(self.stride_)
        return args

