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

class NavSatFix___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::NavSatFix_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="NavSatStatus_"><Member name="status_"><Octet/></Member><Member name="service_"><UShort/></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="NavSatFix_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="status_"><Type name="NavSatStatus_"/></Member><Member name="latitude_"><Double/></Member><Member name="longitude_"><Double/></Member><Member name="altitude_"><Double/></Member><Member name="position_covariance_"><Array size="9"><Double/></Array></Member><Member name="position_covariance_type_"><Octet/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(NavSatFix___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(NavSatFix_()._get_packing_fmt()))

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

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

class NavSatFix_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return NavSatFix___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 status_(self):
        '''
        a DDS sensor_msgs::msg::dds_::NavSatStatus_ value
        @rtype: NavSatStatus_
        '''
        return self._status__

    _status__checker = ddsutil._class_checker(NavSatStatus_)
    @status_.setter
    def status_(self, value):
        self._status__checker(value)
        self._status__ = value

    @property
    def latitude_(self):
        '''
        a DDS double value
        @rtype: float
        '''
        return self._latitude__

    _latitude__checker = ddsutil._float_checker
    @latitude_.setter
    def latitude_(self, value):
        self._latitude__checker(value)
        self._latitude__ = value

    @property
    def longitude_(self):
        '''
        a DDS double value
        @rtype: float
        '''
        return self._longitude__

    _longitude__checker = ddsutil._float_checker
    @longitude_.setter
    def longitude_(self, value):
        self._longitude__checker(value)
        self._longitude__ = value

    @property
    def altitude_(self):
        '''
        a DDS double value
        @rtype: float
        '''
        return self._altitude__

    _altitude__checker = ddsutil._float_checker
    @altitude_.setter
    def altitude_(self, value):
        self._altitude__checker(value)
        self._altitude__ = value

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

    _position_covariance__checker = ddsutil._array_checker(9,ddsutil._float_checker)
    @position_covariance_.setter
    def position_covariance_(self, value):
        self._position_covariance__checker(value)
        self._position_covariance__ = value

    @property
    def position_covariance_type_(self):
        '''
        a DDS octet value
        @rtype: int
        '''
        return self._position_covariance_type__

    _position_covariance_type__checker = ddsutil._octet_checker
    @position_covariance_type_.setter
    def position_covariance_type_(self, value):
        self._position_covariance_type__checker(value)
        self._position_covariance_type__ = value

    _member_attributes = ('header_', 'status_', 'latitude_', 'longitude_', 'altitude_', 'position_covariance_', 'position_covariance_type_')

    def __init__(self, **kwargs):
        ''' Create a NavSatFix_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()
        self.status_ = NavSatStatus_()
        self.latitude_ = 0.0
        self.longitude_ = 0.0
        self.altitude_ = 0.0
        self.position_covariance_ = [0.0 for _ in range(9)]
        self.position_covariance_type_ = 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 NavSatFix_._packing_fmt is not None:
            return NavSatFix_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, std_msgs/msg/Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
        fmt += ddsutil._align(fmt, NavSatStatus_._get_packing_fmt())
        fmt += 'd'
        fmt += 'd'
        fmt += 'd'
        fmt += 'd' * 9
        fmt += 'B'

        NavSatFix_._packing_fmt = ddsutil._pad_fmt(fmt)
        return NavSatFix_._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.status_ = NavSatStatus_()._deserialize(data)
        self.latitude_ = data.pop(0)
        self.longitude_ = data.pop(0)
        self.altitude_ = data.pop(0)
        self.position_covariance_ = [data.pop(0) for _ in range (9)]
        self.position_covariance_type_ = 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(self.status_._get_packing_args())
        args.append(self.latitude_)
        args.append(self.longitude_)
        args.append(self.altitude_)
        ddsutil._lin_map_array(self.position_covariance_, 1, lambda v: args.append(v))
        args.append(self.position_covariance_type_)
        return args

