import dds
import ddsutil
import geometry_msgs/msg/Quaternion_.geometry_msgs.msg.dds_
import geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_
import std_msgs/msg/Header_.std_msgs.msg.dds_
import struct

class Imu___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::Imu_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="geometry_msgs"><Module name="msg"><Module name="dds_"><Struct name="Quaternion_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member><Member name="w_"><Double/></Member></Struct><Struct name="Vector3_"><Member name="x_"><Double/></Member><Member name="y_"><Double/></Member><Member name="z_"><Double/></Member></Struct></Module></Module></Module><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="Imu_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="orientation_"><Type name="::geometry_msgs::msg::dds_::Quaternion_"/></Member><Member name="orientation_covariance_"><Array size="9"><Double/></Array></Member><Member name="angular_velocity_"><Type name="::geometry_msgs::msg::dds_::Vector3_"/></Member><Member name="angular_velocity_covariance_"><Array size="9"><Double/></Array></Member><Member name="linear_acceleration_"><Type name="::geometry_msgs::msg::dds_::Vector3_"/></Member><Member name="linear_acceleration_covariance_"><Array size="9"><Double/></Array></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(Imu___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(Imu_()._get_packing_fmt()))

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

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

class Imu_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return Imu___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 orientation_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Quaternion_ value
        @rtype: geometry_msgs/msg/Quaternion_.geometry_msgs.msg.dds_.Quaternion_
        '''
        return self._orientation__

    _orientation__checker = ddsutil._class_checker(geometry_msgs/msg/Quaternion_.geometry_msgs.msg.dds_.Quaternion_)
    @orientation_.setter
    def orientation_(self, value):
        self._orientation__checker(value)
        self._orientation__ = value

    @property
    def orientation_covariance_(self):
        '''
        a DDS double[9] value
        @rtype: list
        '''
        return self._orientation_covariance__

    _orientation_covariance__checker = ddsutil._array_checker(9,ddsutil._float_checker)
    @orientation_covariance_.setter
    def orientation_covariance_(self, value):
        self._orientation_covariance__checker(value)
        self._orientation_covariance__ = value

    @property
    def angular_velocity_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Vector3_ value
        @rtype: geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_
        '''
        return self._angular_velocity__

    _angular_velocity__checker = ddsutil._class_checker(geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_)
    @angular_velocity_.setter
    def angular_velocity_(self, value):
        self._angular_velocity__checker(value)
        self._angular_velocity__ = value

    @property
    def angular_velocity_covariance_(self):
        '''
        a DDS double[9] value
        @rtype: list
        '''
        return self._angular_velocity_covariance__

    _angular_velocity_covariance__checker = ddsutil._array_checker(9,ddsutil._float_checker)
    @angular_velocity_covariance_.setter
    def angular_velocity_covariance_(self, value):
        self._angular_velocity_covariance__checker(value)
        self._angular_velocity_covariance__ = value

    @property
    def linear_acceleration_(self):
        '''
        a DDS geometry_msgs::msg::dds_::Vector3_ value
        @rtype: geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_
        '''
        return self._linear_acceleration__

    _linear_acceleration__checker = ddsutil._class_checker(geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_)
    @linear_acceleration_.setter
    def linear_acceleration_(self, value):
        self._linear_acceleration__checker(value)
        self._linear_acceleration__ = value

    @property
    def linear_acceleration_covariance_(self):
        '''
        a DDS double[9] value
        @rtype: list
        '''
        return self._linear_acceleration_covariance__

    _linear_acceleration_covariance__checker = ddsutil._array_checker(9,ddsutil._float_checker)
    @linear_acceleration_covariance_.setter
    def linear_acceleration_covariance_(self, value):
        self._linear_acceleration_covariance__checker(value)
        self._linear_acceleration_covariance__ = value

    _member_attributes = ('header_', 'orientation_', 'orientation_covariance_', 'angular_velocity_', 'angular_velocity_covariance_', 'linear_acceleration_', 'linear_acceleration_covariance_')

    def __init__(self, **kwargs):
        ''' Create a Imu_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()
        self.orientation_ = geometry_msgs/msg/Quaternion_.geometry_msgs.msg.dds_.Quaternion_()
        self.orientation_covariance_ = [0.0 for _ in range(9)]
        self.angular_velocity_ = geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_()
        self.angular_velocity_covariance_ = [0.0 for _ in range(9)]
        self.linear_acceleration_ = geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_()
        self.linear_acceleration_covariance_ = [0.0 for _ in range(9)]
        # 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 Imu_._packing_fmt is not None:
            return Imu_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, std_msgs/msg/Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
        fmt += ddsutil._align(fmt, geometry_msgs/msg/Quaternion_.geometry_msgs.msg.dds_.Quaternion_._get_packing_fmt())
        fmt += 'd' * 9
        fmt += ddsutil._align(fmt, geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_._get_packing_fmt())
        fmt += 'd' * 9
        fmt += ddsutil._align(fmt, geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_._get_packing_fmt())
        fmt += 'd' * 9

        Imu_._packing_fmt = ddsutil._pad_fmt(fmt)
        return Imu_._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.orientation_ = geometry_msgs/msg/Quaternion_.geometry_msgs.msg.dds_.Quaternion_()._deserialize(data)
        self.orientation_covariance_ = [data.pop(0) for _ in range (9)]
        self.angular_velocity_ = geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_()._deserialize(data)
        self.angular_velocity_covariance_ = [data.pop(0) for _ in range (9)]
        self.linear_acceleration_ = geometry_msgs/msg/Vector3_.geometry_msgs.msg.dds_.Vector3_()._deserialize(data)
        self.linear_acceleration_covariance_ = [data.pop(0) for _ in range (9)]
        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.orientation_._get_packing_args())
        ddsutil._lin_map_array(self.orientation_covariance_, 1, lambda v: args.append(v))
        args.extend(self.angular_velocity_._get_packing_args())
        ddsutil._lin_map_array(self.angular_velocity_covariance_, 1, lambda v: args.append(v))
        args.extend(self.linear_acceleration_._get_packing_args())
        ddsutil._lin_map_array(self.linear_acceleration_covariance_, 1, lambda v: args.append(v))
        return args

