예제 #1
0
 def to_json_serializable(self):
     amap = {}
     for name, atype in self._fields:
         value = getattr(self, name)
         atype = type_mapping(atype)
         amap[name] = Base.to_json_data(value_type=(value, atype))
     return amap
예제 #2
0
 def decode(cls, cursor):
     index = Uint32.parse_uint32_from_uleb128(cursor)
     _name, datatype = cls._enums[index]
     if datatype is not None:
         value = type_mapping(datatype).decode(cursor)
         return cls.new_with_index_value(index, value)
     else:
         return cls.new_with_index_value(index, None)
예제 #3
0
 def decode(cls, cursor):
     ret = cls.__new__(cls)
     ret.__init__()
     for name, atype in ret._fields:
         prop = getattr(ret, name)
         mtype = type_mapping(atype)
         assert mtype == prop.expected_type
         value = mtype.decode(cursor)
         prop.__set__(ret, value)
     return ret
예제 #4
0
 def to_json_serializable(self):
     amap = {}
     for name, atype in self._fields:
         value = getattr(self, name)
         if isinstance(value, TypedProperty):
             amap[name] = None
         else:
             atype = type_mapping(atype)
             amap[name] = atype.to_json_serializable(value)
     return amap
예제 #5
0
 def pretty_print_obj(cls, obj, buffer, ident):
     #TODO obj should be instance of cls
     prefix_blank = '  '
     #buffer.write(prefix_blank*ident)
     buffer.write('{\n')
     ident_inner = ident+1
     for name, atype in obj._fields:
         value = getattr(obj, name)
         buffer.write(prefix_blank*ident_inner)
         cls.pretty_print_field(name, type_mapping(atype), value, buffer, ident_inner)
         buffer.write(',\n')
     buffer.write(prefix_blank*ident)
     buffer.write('}')
예제 #6
0
 def encode(cls, obj):
     output = b''
     for name, atype in obj._fields:
         value = getattr(obj, name)
         output += type_mapping(atype).encode(value)
     return output
예제 #7
0
 def initailize_fields_type(cls):
     if not cls._initialized:
         cls._initialized = True
         for name, atype in cls._fields:
             setattr(cls, name, TypedProperty(name, type_mapping(atype)))
예제 #8
0
 def _init_with_index_value(self, index, value, datatype):
     self._index = index
     self.value_type = type_mapping(datatype)
     self.value = value
예제 #9
0
 def __init__(self, value=None):
     if not self.__class__._type:
         raise TypeError(f'{self.__class__} has no _type defined.')
     self.__dict__["value_type"] = type_mapping(self.__class__._type)
     self.value = value
예제 #10
0
def test_type_mapping():
    atype = {Uint16: Uint64}
    mtype = type_mapping(atype)
    print(mtype)
예제 #11
0
 def dtype(cls):
     return type_mapping(cls.delegate_type)