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

class JointState___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::JointState_'
    _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="JointState_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="name_"><Sequence><String/></Sequence></Member><Member name="position_"><Sequence><Double/></Sequence></Member><Member name="velocity_"><Sequence><Double/></Sequence></Member><Member name="effort_"><Sequence><Double/></Sequence></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(JointState___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(JointState_()._get_packing_fmt()))

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

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

class JointState_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return JointState___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 name_(self):
        '''
        a DDS sequence<string> value
        @rtype: list
        '''
        return self._name__

    _name__checker = ddsutil._seq_checker(0,ddsutil._str_checker)
    @name_.setter
    def name_(self, value):
        self._name__checker(value)
        self._name__ = value

    @property
    def position_(self):
        '''
        a DDS sequence<double> value
        @rtype: list
        '''
        return self._position__

    _position__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @position_.setter
    def position_(self, value):
        self._position__checker(value)
        self._position__ = value

    @property
    def velocity_(self):
        '''
        a DDS sequence<double> value
        @rtype: list
        '''
        return self._velocity__

    _velocity__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @velocity_.setter
    def velocity_(self, value):
        self._velocity__checker(value)
        self._velocity__ = value

    @property
    def effort_(self):
        '''
        a DDS sequence<double> value
        @rtype: list
        '''
        return self._effort__

    _effort__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @effort_.setter
    def effort_(self, value):
        self._effort__checker(value)
        self._effort__ = value

    _member_attributes = ('header_', 'name_', 'position_', 'velocity_', 'effort_')

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

        JointState_._packing_fmt = ddsutil._pad_fmt(fmt)
        return JointState_._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.name_ = ddsutil._deserialize_seq(data, 'P', lambda seq_data: ddsutil._ptr_to_bytes(seq_data.pop(0)).decode('ISO-8859-1'))
        self.position_ = ddsutil._deserialize_seq(data, 'd', lambda seq_data: seq_data.pop(0))
        self.velocity_ = ddsutil._deserialize_seq(data, 'd', lambda seq_data: seq_data.pop(0))
        self.effort_ = ddsutil._deserialize_seq(data, 'd', 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(self.header_._get_packing_args())
        args.extend(ddsutil._serialize_seq(self.name_, 'P', lambda seq_args, v: seq_args.append(ddsutil._bytes_to_ptr(v.encode('ISO-8859-1')))))
        args.extend(ddsutil._serialize_seq(self.position_, 'd', lambda seq_args, v: seq_args.append(v)))
        args.extend(ddsutil._serialize_seq(self.velocity_, 'd', lambda seq_args, v: seq_args.append(v)))
        args.extend(ddsutil._serialize_seq(self.effort_, 'd', lambda seq_args, v: seq_args.append(v)))
        return args

