import dds
import ddsutil
import struct

class Point___TypeSupport(dds.TypeSupport):

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

    def __init__(self):
        super(Point___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(Point_()._get_packing_fmt()))

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

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

class Point_(ddsutil.TopicDataClass):

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

    @property
    def x_(self):
        '''
        a DDS double value
        @rtype: float
        '''
        return self._x__

    _x__checker = ddsutil._float_checker
    @x_.setter
    def x_(self, value):
        self._x__checker(value)
        self._x__ = value

    @property
    def y_(self):
        '''
        a DDS double value
        @rtype: float
        '''
        return self._y__

    _y__checker = ddsutil._float_checker
    @y_.setter
    def y_(self, value):
        self._y__checker(value)
        self._y__ = value

    @property
    def z_(self):
        '''
        a DDS double value
        @rtype: float
        '''
        return self._z__

    _z__checker = ddsutil._float_checker
    @z_.setter
    def z_(self, value):
        self._z__checker(value)
        self._z__ = value

    _member_attributes = ('x_', 'y_', 'z_')

    def __init__(self, **kwargs):
        ''' Create a Point_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.x_ = 0.0
        self.y_ = 0.0
        self.z_ = 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 Point_._packing_fmt is not None:
            return Point_._packing_fmt
        fmt = ''
        fmt += 'd'
        fmt += 'd'
        fmt += 'd'

        Point_._packing_fmt = ddsutil._pad_fmt(fmt)
        return Point_._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.x_ = data.pop(0)
        self.y_ = data.pop(0)
        self.z_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.append(self.x_)
        args.append(self.y_)
        args.append(self.z_)
        return args

