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

Method dump

python/pyfory/_fory.py:384–412  ·  view source on GitHub ↗

Serialize an object directly to a writable stream. Args: obj: The object to serialize stream: Writable stream implementing write(...) Notes: The stream must be a non-retaining sink: ``write(data)`` must synchronously consume

(self, obj, stream)

Source from the content-addressed store, hash-verified

382 return self.serialize(obj, buffer, buffer_callback, unsupported_callback)
383
384 def dump(self, obj, stream):
385 """
386 Serialize an object directly to a writable stream.
387
388 Args:
389 obj: The object to serialize
390 stream: Writable stream implementing write(...)
391
392 Notes:
393 The stream must be a non-retaining sink: ``write(data)`` must
394 synchronously consume ``data`` before returning. Fory may reuse or
395 modify the underlying buffer after ``write`` returns, so retaining
396 the passed object (or a view of it) is unsupported. If your sink
397 needs retention, copy bytes inside ``write``.
398 """
399 try:
400 self.buffer.set_writer_index(0)
401 output_stream = Buffer.wrap_output_stream(stream)
402 self.buffer.bind_output_stream(output_stream)
403 self._serialize(
404 obj,
405 self.buffer,
406 buffer_callback=None,
407 unsupported_callback=None,
408 )
409 self.force_flush()
410 finally:
411 self.buffer.bind_output_stream(None)
412 self.reset_write()
413
414 def loads(
415 self,

Calls 4

_serializeMethod · 0.95
force_flushMethod · 0.95
reset_writeMethod · 0.95
bind_output_streamMethod · 0.80