MCPcopy Create free account
hub / github.com/apache/fory / read

Method read

python/pyfory/serializer.py:914–946  ·  view source on GitHub ↗
(self, read_context)

Source from the content-addressed store, hash-verified

912 write_context.write_buffer_object(NDArrayBufferObject(value))
913
914 def read(self, read_context):
915 reader_index = read_context.get_reader_index()
916 type_id = read_context.read_uint8()
917 dtype = _np_typeid_to_dtype.get(type_id)
918 if dtype is not None:
919 data = read_context.read_bytes_and_size()
920 arr = np.frombuffer(data, dtype=dtype.newbyteorder("<"))
921 if dtype.itemsize > 1:
922 if is_little_endian:
923 arr = arr.view(dtype)
924 else:
925 arr = arr.astype(dtype)
926 return arr
927
928 read_context.set_reader_index(reader_index)
929 dtype = np.dtype(read_context.read_string())
930 ndim = read_context.read_var_uint32()
931 _check_non_negative_size(ndim, "ndarray dimension")
932 shape = tuple(read_context.read_var_uint32() for _ in range(ndim))
933 if dtype.kind == "O":
934 length = read_context.read_varint32()
935 _check_non_negative_size(length, "ndarray object")
936 read_context.check_readable_bytes(length)
937 items = [read_context.read_ref() for _ in range(length)]
938 return np.array(items, dtype=object)
939 for dim in shape:
940 _check_non_negative_size(dim, "ndarray dimension")
941 fory_buf = read_context.read_buffer_object()
942 if isinstance(fory_buf, memoryview):
943 return np.frombuffer(fory_buf, dtype=dtype).reshape(shape)
944 elif isinstance(fory_buf, bytes):
945 return np.frombuffer(fory_buf, dtype=dtype).reshape(shape)
946 return np.frombuffer(fory_buf.to_pybytes(), dtype=dtype).reshape(shape)
947
948
949class BytesSerializer(Serializer):

Callers

nothing calls this directly

Calls 10

_check_non_negative_sizeFunction · 0.85
read_varint32Method · 0.80
check_readable_bytesMethod · 0.80
read_buffer_objectMethod · 0.80
getMethod · 0.65
read_uint8Method · 0.45
read_stringMethod · 0.45
read_var_uint32Method · 0.45
read_refMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected