def __get_type_id(cls, ctypes_object, client): type_id = getattr(ctypes_object, "type_id", None) if type_id: if not client: raise ParseError(f'Can not query binary type {type_id}') return type_id return None
async def to_python_not_null_async(cls, ctypes_object, client: 'AioClient' = None, *args, **kwargs): type_id = ctypes_object.type_id if not client: raise ParseError(f'Can not query binary type {type_id}') data_class = await client.query_binary_type(type_id, ctypes_object.schema_id) result = data_class() result.version = ctypes_object.version field_values = await asyncio.gather(*[ field_type.to_python_async( getattr(ctypes_object.object_fields, field_name), client, * args, **kwargs) for field_name, field_type in data_class.schema.items() ]) for i, field_name in enumerate(data_class.schema.keys()): setattr(result, field_name, field_values[i]) return result
def get_dataclass(client: 'Client', header) -> OrderedDict: # get field names from outer space temp_conn = client.clone() result = temp_conn.query_binary_type(header.type_id, header.schema_id) temp_conn.close() if not result: raise ParseError('Binary type is not registered') return result
def parse(cls, client: 'Client'): type_code = client.recv(ctypes.sizeof(ctypes.c_byte)) try: data_class = tc_map(type_code) except KeyError: raise ParseError('Unknown type code: `{}`'.format(type_code)) client.prefetch += type_code return data_class.parse(client)
def to_python(cls, ctype_object, client: 'Client' = None, *args, **kwargs): if not client: raise ParseError('Can not query binary type {}'.format( ctype_object.type_id)) data_class = client.query_binary_type(ctype_object.type_id, ctype_object.schema_id) result = data_class() result.version = ctype_object.version for field_name, field_type in data_class.schema.items(): setattr( result, field_name, field_type.to_python( getattr(ctype_object.object_fields, field_name), client, *args, **kwargs)) return result
def from_python_not_null(cls, stream, value, *args, **kwargs): raise ParseError('Send unwrapped data.')
def __data_class_parse(cls, stream): type_code = stream.slice(offset=ctypes.sizeof(ctypes.c_byte)) try: return tc_map(type_code) except KeyError: raise ParseError('Unknown type code: `{}`'.format(type_code))
def from_python(cls, value): raise ParseError('Send unwrapped data.')