import dds
import ddsutil
import struct

class Byte___TypeSupport(dds.TypeSupport):

    _typename = 'std_msgs::msg::dds_::Byte_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="std_msgs"><Module name="msg"><Module name="dds_"><Struct name="Byte_"><Member name="data_"><Octet/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(Byte___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(Byte_()._get_packing_fmt()))

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

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

class Byte_(ddsutil.TopicDataClass):

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

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

    _data__checker = ddsutil._octet_checker
    @data_.setter
    def data_(self, value):
        self._data__checker(value)
        self._data__ = value

    _member_attributes = ('data_')

    def __init__(self, **kwargs):
        ''' Create a Byte_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.data_ = 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 Byte_._packing_fmt is not None:
            return Byte_._packing_fmt
        fmt = ''
        fmt += 'B'

        Byte_._packing_fmt = ddsutil._pad_fmt(fmt)
        return Byte_._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.data_ = data.pop(0)
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.append(self.data_)
        return args

