import dds
import ddsutil
import struct

class TwistWithCovariance___TypeSupport(dds.TypeSupport):

    _typename = 'geometry_msgs::msg::dds_::TwistWithCovariance_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="geometry_msgs"><Module name="msg"><Module name="dds_"><Struct name="Vector3_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member></Struct><Struct name="Twist_"><Member name="linear_"><Type name="Vector3_"/></Member><Member name="angular_"><Type name="Vector3_"/></Member></Struct><Struct name="TwistWithCovariance_"><Member name="twist_"><Type name="Twist_"/></Member><Member name="covariance_"><Array size="36"><Double/></Array></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(TwistWithCovariance___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(TwistWithCovariance_()._get_packing_fmt()))

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

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

class TwistWithCovariance_(ddsutil.TopicDataClass):

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

    @property
    def twist_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Twist_ value
        @rtype: Twist_
        '''
        return self._twist__

    _twist__checker = ddsutil._class_checker(Twist_)
    @twist_.setter
    def twist_(self, value):
        self._twist__checker(value)
        self._twist__ = value

    @property
    def covariance_(self):
        '''
        a DDS double[36] value
        @rtype: list
        '''
        return self._covariance__

    _covariance__checker = ddsutil._array_checker(36,ddsutil._float_checker)
    @covariance_.setter
    def covariance_(self, value):
        self._covariance__checker(value)
        self._covariance__ = value

    _member_attributes = ('twist_', 'covariance_')

    def __init__(self, **kwargs):
        ''' Create a TwistWithCovariance_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.twist_ = Twist_()
        self.covariance_ = [0.0 for _ in range(36)]
        # 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 TwistWithCovariance_._packing_fmt is not None:
            return TwistWithCovariance_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, Twist_._get_packing_fmt())
        fmt += 'd' * 36

        TwistWithCovariance_._packing_fmt = ddsutil._pad_fmt(fmt)
        return TwistWithCovariance_._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.twist_ = Twist_()._deserialize(data)
        self.covariance_ = [data.pop(0) for _ in range (36)]
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(self.twist_._get_packing_args())
        ddsutil._lin_map_array(self.covariance_, 1, lambda v: args.append(v))
        return args

