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

class PointCloud2___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::PointCloud2_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="PointField_"><Member name="name_"><String/></Member><Member name="offset_"><ULong/></Member><Member name="datatype_"><Octet/></Member><Member name="count_"><ULong/></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="PointCloud2_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="height_"><ULong/></Member><Member name="width_"><ULong/></Member><Member name="fields_"><Sequence><Type name="PointField_"/></Sequence></Member><Member name="is_bigendian_"><Boolean/></Member><Member name="point_step_"><ULong/></Member><Member name="row_step_"><ULong/></Member><Member name="data_"><Sequence><Octet/></Sequence></Member><Member name="is_dense_"><Boolean/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(PointCloud2___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(PointCloud2_()._get_packing_fmt()))

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

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

class PointCloud2_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return PointCloud2___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 height_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._height__

    _height__checker = ddsutil._ulong_checker
    @height_.setter
    def height_(self, value):
        self._height__checker(value)
        self._height__ = value

    @property
    def width_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._width__

    _width__checker = ddsutil._ulong_checker
    @width_.setter
    def width_(self, value):
        self._width__checker(value)
        self._width__ = value

    @property
    def fields_(self):
        '''
        a DDS sequence<sensor_msgs::msg::dds_::PointField_> value
        @rtype: list
        '''
        return self._fields__

    _fields__checker = ddsutil._seq_checker(0,ddsutil._class_checker(PointField_))
    @fields_.setter
    def fields_(self, value):
        self._fields__checker(value)
        self._fields__ = value

    @property
    def is_bigendian_(self):
        '''
        a DDS boolean value
        @rtype: bool
        '''
        return self._is_bigendian__

    _is_bigendian__checker = ddsutil._bool_checker
    @is_bigendian_.setter
    def is_bigendian_(self, value):
        self._is_bigendian__checker(value)
        self._is_bigendian__ = value

    @property
    def point_step_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._point_step__

    _point_step__checker = ddsutil._ulong_checker
    @point_step_.setter
    def point_step_(self, value):
        self._point_step__checker(value)
        self._point_step__ = value

    @property
    def row_step_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._row_step__

    _row_step__checker = ddsutil._ulong_checker
    @row_step_.setter
    def row_step_(self, value):
        self._row_step__checker(value)
        self._row_step__ = value

    @property
    def data_(self):
        '''
        a DDS sequence<octet> value
        @rtype: list
        '''
        return self._data__

    _data__checker = ddsutil._seq_checker(0,ddsutil._octet_checker)
    @data_.setter
    def data_(self, value):
        self._data__checker(value)
        self._data__ = value

    @property
    def is_dense_(self):
        '''
        a DDS boolean value
        @rtype: bool
        '''
        return self._is_dense__

    _is_dense__checker = ddsutil._bool_checker
    @is_dense_.setter
    def is_dense_(self, value):
        self._is_dense__checker(value)
        self._is_dense__ = value

    _member_attributes = ('header_', 'height_', 'width_', 'fields_', 'is_bigendian_', 'point_step_', 'row_step_', 'data_', 'is_dense_')

    def __init__(self, **kwargs):
        ''' Create a PointCloud2_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()
        self.height_ = 0
        self.width_ = 0
        self.fields_ = []
        self.is_bigendian_ = False
        self.point_step_ = 0
        self.row_step_ = 0
        self.data_ = []
        self.is_dense_ = False
        # 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 PointCloud2_._packing_fmt is not None:
            return PointCloud2_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, std_msgs/msg/Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
        fmt += 'I'
        fmt += 'I'
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))
        fmt += '?'
        fmt += 'I'
        fmt += 'I'
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))
        fmt += '?'

        PointCloud2_._packing_fmt = ddsutil._pad_fmt(fmt)
        return PointCloud2_._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.height_ = data.pop(0)
        self.width_ = data.pop(0)
        self.fields_ = ddsutil._deserialize_seq(data, PointField_._get_packing_fmt(), lambda seq_data: PointField_()._deserialize(seq_data))
        self.is_bigendian_ = data.pop(0)
        self.point_step_ = data.pop(0)
        self.row_step_ = data.pop(0)
        self.data_ = ddsutil._deserialize_seq(data, 'B', lambda seq_data: seq_data.pop(0))
        self.is_dense_ = data.pop(0)
        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.append(self.height_)
        args.append(self.width_)
        args.extend(ddsutil._serialize_seq(self.fields_, PointField_._get_packing_fmt(), lambda seq_args, v: seq_args.extend(v._get_packing_args())))
        args.append(self.is_bigendian_)
        args.append(self.point_step_)
        args.append(self.row_step_)
        args.extend(ddsutil._serialize_seq(self.data_, 'B', lambda seq_args, v: seq_args.append(v)))
        args.append(self.is_dense_)
        return args

