import dds
import ddsutil
import geometry_msgs/msg/Point32_.geometry_msgs.msg.dds_
import std_msgs/msg/Header_.std_msgs.msg.dds_
import struct

class PointCloud___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::PointCloud_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="ChannelFloat32_"><Member name="name_"><String/></Member><Member name="values_"><Sequence><Float/></Sequence></Member></Struct></Module></Module></Module><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></Module></Module></Module><Module name="builtin_interfaces"><Module name="msg"><Module name="dds_"><Struct name="Time_"><Member name="sec_"><Long/></Member><Member name="nanosec_"><ULong/></Member></Struct></Module></Module></Module><Module name="std_msgs"><Module name="msg"><Module name="dds_"><Struct name="Header_"><Member name="stamp_"><Type name="::builtin_interfaces::msg::dds_::Time_"/></Member><Member name="frame_id_"><String/></Member></Struct></Module></Module></Module><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="PointCloud_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="points_"><Sequence><Type name="::geometry_msgs::msg::dds_::Point32_"/></Sequence></Member><Member name="channels_"><Sequence><Type name="ChannelFloat32_"/></Sequence></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(PointCloud___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(PointCloud_()._get_packing_fmt()))

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

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

class PointCloud_(ddsutil.TopicDataClass):

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

    @property
    def header_(self):
        '''
        a DDS std_msgs::msg::dds_::Header_ value
        @rtype: std_msgs/msg/Header_.std_msgs.msg.dds_.Header_
        '''
        return self._header__

    _header__checker = ddsutil._class_checker(std_msgs/msg/Header_.std_msgs.msg.dds_.Header_)
    @header_.setter
    def header_(self, value):
        self._header__checker(value)
        self._header__ = value

    @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(geometry_msgs/msg/Point32_.geometry_msgs.msg.dds_.Point32_))
    @points_.setter
    def points_(self, value):
        self._points__checker(value)
        self._points__ = value

    @property
    def channels_(self):
        '''
        a DDS sequence<sensor_msgs::msg::dds_::ChannelFloat32_> value
        @rtype: list
        '''
        return self._channels__

    _channels__checker = ddsutil._seq_checker(0,ddsutil._class_checker(ChannelFloat32_))
    @channels_.setter
    def channels_(self, value):
        self._channels__checker(value)
        self._channels__ = value

    _member_attributes = ('header_', 'points_', 'channels_')

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

        PointCloud_._packing_fmt = ddsutil._pad_fmt(fmt)
        return PointCloud_._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.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()._deserialize(data)
        self.points_ = ddsutil._deserialize_seq(data, geometry_msgs/msg/Point32_.geometry_msgs.msg.dds_.Point32_._get_packing_fmt(), lambda seq_data: geometry_msgs/msg/Point32_.geometry_msgs.msg.dds_.Point32_()._deserialize(seq_data))
        self.channels_ = ddsutil._deserialize_seq(data, ChannelFloat32_._get_packing_fmt(), lambda seq_data: ChannelFloat32_()._deserialize(seq_data))
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(self.header_._get_packing_args())
        args.extend(ddsutil._serialize_seq(self.points_, geometry_msgs/msg/Point32_.geometry_msgs.msg.dds_.Point32_._get_packing_fmt(), lambda seq_args, v: seq_args.extend(v._get_packing_args())))
        args.extend(ddsutil._serialize_seq(self.channels_, ChannelFloat32_._get_packing_fmt(), lambda seq_args, v: seq_args.extend(v._get_packing_args())))
        return args

