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

class GridCells___TypeSupport(dds.TypeSupport):

    _typename = 'nav_msgs::msg::dds_::GridCells_'
    _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><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="nav_msgs"><Module name="msg"><Module name="dds_"><Struct name="GridCells_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="cell_width_"><Float/></Member><Member name="cell_height_"><Float/></Member><Member name="cells_"><Sequence><Type name="::geometry_msgs::msg::dds_::Point_"/></Sequence></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(GridCells___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(GridCells_()._get_packing_fmt()))

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

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

class GridCells_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return GridCells___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 cell_width_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._cell_width__

    _cell_width__checker = ddsutil._float_checker
    @cell_width_.setter
    def cell_width_(self, value):
        self._cell_width__checker(value)
        self._cell_width__ = value

    @property
    def cell_height_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._cell_height__

    _cell_height__checker = ddsutil._float_checker
    @cell_height_.setter
    def cell_height_(self, value):
        self._cell_height__checker(value)
        self._cell_height__ = value

    @property
    def cells_(self):
        '''
        a DDS sequence<geometry_msgs::msg::dds_::Point_> value
        @rtype: list
        '''
        return self._cells__

    _cells__checker = ddsutil._seq_checker(0,ddsutil._class_checker(geometry_msgs/msg/Point_.geometry_msgs.msg.dds_.Point_))
    @cells_.setter
    def cells_(self, value):
        self._cells__checker(value)
        self._cells__ = value

    _member_attributes = ('header_', 'cell_width_', 'cell_height_', 'cells_')

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

        GridCells_._packing_fmt = ddsutil._pad_fmt(fmt)
        return GridCells_._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.cell_width_ = data.pop(0)
        self.cell_height_ = data.pop(0)
        self.cells_ = ddsutil._deserialize_seq(data, geometry_msgs/msg/Point_.geometry_msgs.msg.dds_.Point_._get_packing_fmt(), lambda seq_data: geometry_msgs/msg/Point_.geometry_msgs.msg.dds_.Point_()._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.append(self.cell_width_)
        args.append(self.cell_height_)
        args.extend(ddsutil._serialize_seq(self.cells_, geometry_msgs/msg/Point_.geometry_msgs.msg.dds_.Point_._get_packing_fmt(), lambda seq_args, v: seq_args.extend(v._get_packing_args())))
        return args

