import dds
import ddsutil
import struct

class JoyFeedback___TypeSupport(dds.TypeSupport):

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

    def __init__(self):
        super(JoyFeedback___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(JoyFeedback_()._get_packing_fmt()))

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

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

class JoyFeedback_(ddsutil.TopicDataClass):

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

    @property
    def type_(self):
        '''
        a DDS octet value
        @rtype: int
        '''
        return self._type__

    _type__checker = ddsutil._octet_checker
    @type_.setter
    def type_(self, value):
        self._type__checker(value)
        self._type__ = value

    @property
    def id_(self):
        '''
        a DDS octet value
        @rtype: int
        '''
        return self._id__

    _id__checker = ddsutil._octet_checker
    @id_.setter
    def id_(self, value):
        self._id__checker(value)
        self._id__ = value

    @property
    def intensity_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._intensity__

    _intensity__checker = ddsutil._float_checker
    @intensity_.setter
    def intensity_(self, value):
        self._intensity__checker(value)
        self._intensity__ = value

    _member_attributes = ('type_', 'id_', 'intensity_')

    def __init__(self, **kwargs):
        ''' Create a JoyFeedback_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.type_ = 0
        self.id_ = 0
        self.intensity_ = 0.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 JoyFeedback_._packing_fmt is not None:
            return JoyFeedback_._packing_fmt
        fmt = ''
        fmt += 'B'
        fmt += 'B'
        fmt += 'f'

        JoyFeedback_._packing_fmt = ddsutil._pad_fmt(fmt)
        return JoyFeedback_._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.type_ = data.pop(0)
        self.id_ = data.pop(0)
        self.intensity_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.append(self.type_)
        args.append(self.id_)
        args.append(self.intensity_)
        return args

