import dds
import ddsutil
import struct

class RegionOfInterest___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::RegionOfInterest_'
    _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></MetaData>'

    def __init__(self):
        super(RegionOfInterest___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(RegionOfInterest_()._get_packing_fmt()))

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

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

class RegionOfInterest_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return RegionOfInterest___TypeSupport()

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

    _x_offset__checker = ddsutil._ulong_checker
    @x_offset_.setter
    def x_offset_(self, value):
        self._x_offset__checker(value)
        self._x_offset__ = value

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

    _y_offset__checker = ddsutil._ulong_checker
    @y_offset_.setter
    def y_offset_(self, value):
        self._y_offset__checker(value)
        self._y_offset__ = 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 do_rectify_(self):
        '''
        a DDS boolean value
        @rtype: bool
        '''
        return self._do_rectify__

    _do_rectify__checker = ddsutil._bool_checker
    @do_rectify_.setter
    def do_rectify_(self, value):
        self._do_rectify__checker(value)
        self._do_rectify__ = value

    _member_attributes = ('x_offset_', 'y_offset_', 'height_', 'width_', 'do_rectify_')

    def __init__(self, **kwargs):
        ''' Create a RegionOfInterest_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.x_offset_ = 0
        self.y_offset_ = 0
        self.height_ = 0
        self.width_ = 0
        self.do_rectify_ = False
        # 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 RegionOfInterest_._packing_fmt is not None:
            return RegionOfInterest_._packing_fmt
        fmt = ''
        fmt += 'I'
        fmt += 'I'
        fmt += 'I'
        fmt += 'I'
        fmt += '?'

        RegionOfInterest_._packing_fmt = ddsutil._pad_fmt(fmt)
        return RegionOfInterest_._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.x_offset_ = data.pop(0)
        self.y_offset_ = data.pop(0)
        self.height_ = data.pop(0)
        self.width_ = data.pop(0)
        self.do_rectify_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.append(self.x_offset_)
        args.append(self.y_offset_)
        args.append(self.height_)
        args.append(self.width_)
        args.append(self.do_rectify_)
        return args

