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

class CameraInfo___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::CameraInfo_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="RegionOfInterest_"><Member name="x_offset_"><ULong/></Member><Member name="y_offset_"><ULong/></Member><Member name="height_"><ULong/></Member><Member name="width_"><ULong/></Member><Member name="do_rectify_"><Boolean/></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="CameraInfo_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="height_"><ULong/></Member><Member name="width_"><ULong/></Member><Member name="distortion_model_"><String/></Member><Member name="d_"><Sequence><Double/></Sequence></Member><Member name="k_"><Array size="9"><Double/></Array></Member><Member name="r_"><Array size="9"><Double/></Array></Member><Member name="p_"><Array size="12"><Double/></Array></Member><Member name="binning_x_"><ULong/></Member><Member name="binning_y_"><ULong/></Member><Member name="roi_"><Type name="RegionOfInterest_"/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(CameraInfo___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(CameraInfo_()._get_packing_fmt()))

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

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

class CameraInfo_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return CameraInfo___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 height_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._height__

    _height__checker = ddsutil._ulong_checker
    @height_.setter
    def height_(self, value):
        self._height__checker(value)
        self._height__ = value

    @property
    def width_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._width__

    _width__checker = ddsutil._ulong_checker
    @width_.setter
    def width_(self, value):
        self._width__checker(value)
        self._width__ = value

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

    _distortion_model__checker = ddsutil._str_checker
    @distortion_model_.setter
    def distortion_model_(self, value):
        self._distortion_model__checker(value)
        self._distortion_model__ = value

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

    _d__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @d_.setter
    def d_(self, value):
        self._d__checker(value)
        self._d__ = value

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

    _k__checker = ddsutil._array_checker(9,ddsutil._float_checker)
    @k_.setter
    def k_(self, value):
        self._k__checker(value)
        self._k__ = value

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

    _r__checker = ddsutil._array_checker(9,ddsutil._float_checker)
    @r_.setter
    def r_(self, value):
        self._r__checker(value)
        self._r__ = value

    @property
    def p_(self):
        '''
        a DDS double[12] value
        @rtype: list
        '''
        return self._p__

    _p__checker = ddsutil._array_checker(12,ddsutil._float_checker)
    @p_.setter
    def p_(self, value):
        self._p__checker(value)
        self._p__ = value

    @property
    def binning_x_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._binning_x__

    _binning_x__checker = ddsutil._ulong_checker
    @binning_x_.setter
    def binning_x_(self, value):
        self._binning_x__checker(value)
        self._binning_x__ = value

    @property
    def binning_y_(self):
        '''
        a DDS unsigned long value
        @rtype: int
        '''
        return self._binning_y__

    _binning_y__checker = ddsutil._ulong_checker
    @binning_y_.setter
    def binning_y_(self, value):
        self._binning_y__checker(value)
        self._binning_y__ = value

    @property
    def roi_(self):
        '''
        a DDS sensor_msgs::msg::dds_::RegionOfInterest_ value
        @rtype: RegionOfInterest_
        '''
        return self._roi__

    _roi__checker = ddsutil._class_checker(RegionOfInterest_)
    @roi_.setter
    def roi_(self, value):
        self._roi__checker(value)
        self._roi__ = value

    _member_attributes = ('header_', 'height_', 'width_', 'distortion_model_', 'd_', 'k_', 'r_', 'p_', 'binning_x_', 'binning_y_', 'roi_')

    def __init__(self, **kwargs):
        ''' Create a CameraInfo_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()
        self.height_ = 0
        self.width_ = 0
        self.distortion_model_ = ''
        self.d_ = []
        self.k_ = [0.0 for _ in range(9)]
        self.r_ = [0.0 for _ in range(9)]
        self.p_ = [0.0 for _ in range(12)]
        self.binning_x_ = 0
        self.binning_y_ = 0
        self.roi_ = RegionOfInterest_()
        # 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 CameraInfo_._packing_fmt is not None:
            return CameraInfo_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, std_msgs/msg/Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
        fmt += 'I'
        fmt += 'I'
        fmt += 'P'
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))
        fmt += 'd' * 9
        fmt += 'd' * 9
        fmt += 'd' * 12
        fmt += 'I'
        fmt += 'I'
        fmt += ddsutil._align(fmt, RegionOfInterest_._get_packing_fmt())

        CameraInfo_._packing_fmt = ddsutil._pad_fmt(fmt)
        return CameraInfo_._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.height_ = data.pop(0)
        self.width_ = data.pop(0)
        self.distortion_model_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')
        self.d_ = ddsutil._deserialize_seq(data, 'd', lambda seq_data: seq_data.pop(0))
        self.k_ = [data.pop(0) for _ in range (9)]
        self.r_ = [data.pop(0) for _ in range (9)]
        self.p_ = [data.pop(0) for _ in range (12)]
        self.binning_x_ = data.pop(0)
        self.binning_y_ = data.pop(0)
        self.roi_ = RegionOfInterest_()._deserialize(data)
        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.append(self.height_)
        args.append(self.width_)
        args.append(ddsutil._bytes_to_ptr(self.distortion_model_.encode('ISO-8859-1')))
        args.extend(ddsutil._serialize_seq(self.d_, 'd', lambda seq_args, v: seq_args.append(v)))
        ddsutil._lin_map_array(self.k_, 1, lambda v: args.append(v))
        ddsutil._lin_map_array(self.r_, 1, lambda v: args.append(v))
        ddsutil._lin_map_array(self.p_, 1, lambda v: args.append(v))
        args.append(self.binning_x_)
        args.append(self.binning_y_)
        args.extend(self.roi_._get_packing_args())
        return args

