import dds
import ddsutil
import struct

class JoyFeedbackArray___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::JoyFeedbackArray_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="JoyFeedback_"><Member name="type_"><Octet/></Member><Member name="id_"><Octet/></Member><Member name="intensity_"><Float/></Member></Struct><Struct name="JoyFeedbackArray_"><Member name="array_"><Sequence><Type name="JoyFeedback_"/></Sequence></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(JoyFeedbackArray___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(JoyFeedbackArray_()._get_packing_fmt()))

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

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

class JoyFeedbackArray_(ddsutil.TopicDataClass):

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

    @property
    def array_(self):
        '''
        a DDS sequence<sensor_msgs::msg::dds_::JoyFeedback_> value
        @rtype: list
        '''
        return self._array__

    _array__checker = ddsutil._seq_checker(0,ddsutil._class_checker(JoyFeedback_))
    @array_.setter
    def array_(self, value):
        self._array__checker(value)
        self._array__ = value

    _member_attributes = ('array_')

    def __init__(self, **kwargs):
        ''' Create a JoyFeedbackArray_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.array_ = []
        # 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 JoyFeedbackArray_._packing_fmt is not None:
            return JoyFeedbackArray_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))

        JoyFeedbackArray_._packing_fmt = ddsutil._pad_fmt(fmt)
        return JoyFeedbackArray_._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.array_ = ddsutil._deserialize_seq(data, JoyFeedback_._get_packing_fmt(), lambda seq_data: JoyFeedback_()._deserialize(seq_data))
        return self;

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

