import dds
import ddsutil
import struct

class ColorRGBA___TypeSupport(dds.TypeSupport):

    _typename = 'std_msgs::msg::dds_::ColorRGBA_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="std_msgs"><Module name="msg"><Module name="dds_"><Struct name="ColorRGBA_"><Member name="r_"><Float/></Member><Member name="g_"><Float/></Member><Member name="b_"><Float/></Member><Member name="a_"><Float/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(ColorRGBA___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(ColorRGBA_()._get_packing_fmt()))

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

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

class ColorRGBA_(ddsutil.TopicDataClass):

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

    @property
    def r_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._r__

    _r__checker = ddsutil._float_checker
    @r_.setter
    def r_(self, value):
        self._r__checker(value)
        self._r__ = value

    @property
    def g_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._g__

    _g__checker = ddsutil._float_checker
    @g_.setter
    def g_(self, value):
        self._g__checker(value)
        self._g__ = value

    @property
    def b_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._b__

    _b__checker = ddsutil._float_checker
    @b_.setter
    def b_(self, value):
        self._b__checker(value)
        self._b__ = value

    @property
    def a_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._a__

    _a__checker = ddsutil._float_checker
    @a_.setter
    def a_(self, value):
        self._a__checker(value)
        self._a__ = value

    _member_attributes = ('r_', 'g_', 'b_', 'a_')

    def __init__(self, **kwargs):
        ''' Create a ColorRGBA_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.r_ = 0.0
        self.g_ = 0.0
        self.b_ = 0.0
        self.a_ = 0.0
        # 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 ColorRGBA_._packing_fmt is not None:
            return ColorRGBA_._packing_fmt
        fmt = ''
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'

        ColorRGBA_._packing_fmt = ddsutil._pad_fmt(fmt)
        return ColorRGBA_._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.r_ = data.pop(0)
        self.g_ = data.pop(0)
        self.b_ = data.pop(0)
        self.a_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.append(self.r_)
        args.append(self.g_)
        args.append(self.b_)
        args.append(self.a_)
        return args

