MCPcopy Index your code
hub / github.com/apache/fory / write

Method write

python/pyfory/_serializer.py:461–467  ·  view source on GitHub ↗
(self, write_context, value: datetime.timedelta)

Source from the content-addressed store, hash-verified

459
460class DurationSerializer(Serializer):
461 def write(self, write_context, value: datetime.timedelta):
462 if not isinstance(value, datetime.timedelta):
463 raise TypeError("{} should be {} instead of {}".format(value, datetime.timedelta, type(value)))
464 total_micros = value.days * 86_400_000_000 + value.seconds * 1_000_000 + value.microseconds
465 seconds, micros = divmod(total_micros, 1_000_000)
466 write_context.write_varint64(seconds)
467 write_context.write_int32(micros * 1000)
468
469 def read(self, read_context):
470 seconds = read_context.read_varint64()

Callers

nothing calls this directly

Calls 3

write_varint64Method · 0.80
formatMethod · 0.45
write_int32Method · 0.45

Tested by

no test coverage detected