import dds
import ddsutil
import struct

class PoseWithCovariance___TypeSupport(dds.TypeSupport):

    _typename = 'geometry_msgs::msg::dds_::PoseWithCovariance_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="geometry_msgs"><Module name="msg"><Module name="dds_"><Struct name="Point_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member></Struct><Struct name="Quaternion_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member><Member name="w_"><Double/></Member></Struct><Struct name="Pose_"><Member name="position_"><Type name="Point_"/></Member><Member name="orientation_"><Type name="Quaternion_"/></Member></Struct><Struct name="PoseWithCovariance_"><Member name="pose_"><Type name="Pose_"/></Member><Member name="covariance_"><Array size="36"><Double/></Array></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(PoseWithCovariance___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(PoseWithCovariance_()._get_packing_fmt()))

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

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

class PoseWithCovariance_(ddsutil.TopicDataClass):

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

    @property
    def pose_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Pose_ value
        @rtype: Pose_
        '''
        return self._pose__

    _pose__checker = ddsutil._class_checker(Pose_)
    @pose_.setter
    def pose_(self, value):
        self._pose__checker(value)
        self._pose__ = 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 = ('pose_', 'covariance_')

    def __init__(self, **kwargs):
        ''' Create a PoseWithCovariance_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.pose_ = Pose_()
        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 PoseWithCovariance_._packing_fmt is not None:
            return PoseWithCovariance_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, Pose_._get_packing_fmt())
        fmt += 'd' * 36

        PoseWithCovariance_._packing_fmt = ddsutil._pad_fmt(fmt)
        return PoseWithCovariance_._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.pose_ = Pose_()._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.pose_._get_packing_args())
        ddsutil._lin_map_array(self.covariance_, 1, lambda v: args.append(v))
        return args

