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

class TimeReference___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::TimeReference_'
    _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><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="TimeReference_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="time_ref_"><Type name="::builtin_interfaces::msg::dds_::Time_"/></Member><Member name="source_"><String/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(TimeReference___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(TimeReference_()._get_packing_fmt()))

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

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

class TimeReference_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return TimeReference___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 time_ref_(self):
        '''
        a DDS builtin_interfaces::msg::dds_::Time_ value
        @rtype: builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_
        '''
        return self._time_ref__

    _time_ref__checker = ddsutil._class_checker(builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_)
    @time_ref_.setter
    def time_ref_(self, value):
        self._time_ref__checker(value)
        self._time_ref__ = value

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

    _source__checker = ddsutil._str_checker
    @source_.setter
    def source_(self, value):
        self._source__checker(value)
        self._source__ = value

    _member_attributes = ('header_', 'time_ref_', 'source_')

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

        TimeReference_._packing_fmt = ddsutil._pad_fmt(fmt)
        return TimeReference_._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.time_ref_ = builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_()._deserialize(data)
        self.source_ = 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.header_._get_packing_args())
        args.extend(self.time_ref_._get_packing_args())
        args.append(ddsutil._bytes_to_ptr(self.source_.encode('ISO-8859-1')))
        return args

