import builtin_interfaces.Time_.builtin_interfaces.msg.dds_
import dds
import ddsutil
import struct

class Header___TypeSupport(dds.TypeSupport):

    _typename = 'std_msgs::msg::dds_::Header_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><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></MetaData>'

    def __init__(self):
        super(Header___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(Header_()._get_packing_fmt()))

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

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

class Header_(ddsutil.TopicDataClass):

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

    @property
    def stamp_(self):
        '''
        a DDS builtin_interfaces::msg::dds_::Time_ value
        @rtype: builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_
        '''
        return self._stamp__

    _stamp__checker = ddsutil._class_checker(builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_)
    @stamp_.setter
    def stamp_(self, value):
        self._stamp__checker(value)
        self._stamp__ = value

    @property
    def frame_id_(self):
        '''
        a DDS string value
        @rtype: str
        '''
        return self._frame_id__

    _frame_id__checker = ddsutil._str_checker
    @frame_id_.setter
    def frame_id_(self, value):
        self._frame_id__checker(value)
        self._frame_id__ = value

    _member_attributes = ('stamp_', 'frame_id_')

    def __init__(self, **kwargs):
        ''' Create a Header_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.stamp_ = builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_()
        self.frame_id_ = ''
        # 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 Header_._packing_fmt is not None:
            return Header_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_._get_packing_fmt())
        fmt += 'P'

        Header_._packing_fmt = ddsutil._pad_fmt(fmt)
        return Header_._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.stamp_ = builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_()._deserialize(data)
        self.frame_id_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(self.stamp_._get_packing_args())
        args.append(ddsutil._bytes_to_ptr(self.frame_id_.encode('ISO-8859-1')))
        return args

