import dds
import ddsutil
import struct

class Polygon___TypeSupport(dds.TypeSupport):

    _typename = 'geometry_msgs::msg::dds_::Polygon_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="geometry_msgs"><Module name="msg"><Module name="dds_"><Struct name="Point32_"><Member name="x_"><Float/></Member><Member name="y_"><Float/></Member><Member name="z_"><Float/></Member></Struct><Struct name="Polygon_"><Member name="points_"><Sequence><Type name="Point32_"/></Sequence></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(Polygon___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(Polygon_()._get_packing_fmt()))

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

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

class Polygon_(ddsutil.TopicDataClass):

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

    @property
    def points_(self):
        '''
        a DDS sequence<geometry_msgs::msg::dds_::Point32_> value
        @rtype: list
        '''
        return self._points__

    _points__checker = ddsutil._seq_checker(0,ddsutil._class_checker(Point32_))
    @points_.setter
    def points_(self, value):
        self._points__checker(value)
        self._points__ = value

    _member_attributes = ('points_')

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

        Polygon_._packing_fmt = ddsutil._pad_fmt(fmt)
        return Polygon_._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.points_ = ddsutil._deserialize_seq(data, Point32_._get_packing_fmt(), lambda seq_data: Point32_()._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.points_, Point32_._get_packing_fmt(), lambda seq_args, v: seq_args.extend(v._get_packing_args())))
        return args

