import dds
import ddsutil
import struct

class LaserEcho___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::LaserEcho_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="LaserEcho_"><Member name="echoes_"><Sequence><Float/></Sequence></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(LaserEcho___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(LaserEcho_()._get_packing_fmt()))

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

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

class LaserEcho_(ddsutil.TopicDataClass):

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

    @property
    def echoes_(self):
        '''
        a DDS sequence<float> value
        @rtype: list
        '''
        return self._echoes__

    _echoes__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @echoes_.setter
    def echoes_(self, value):
        self._echoes__checker(value)
        self._echoes__ = value

    _member_attributes = ('echoes_')

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

        LaserEcho_._packing_fmt = ddsutil._pad_fmt(fmt)
        return LaserEcho_._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.echoes_ = ddsutil._deserialize_seq(data, 'f', lambda seq_data: seq_data.pop(0))
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(ddsutil._serialize_seq(self.echoes_, 'f', lambda seq_args, v: seq_args.append(v)))
        return args

