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

Function _write_decimal_parts

python/pyfory/serializer.py:362–374  ·  view source on GitHub ↗
(write_context, scale: int, unscaled: int)

Source from the content-addressed store, hash-verified

360
361
362def _write_decimal_parts(write_context, scale: int, unscaled: int):
363 write_context.write_varint32(scale)
364 if _can_use_small_decimal_encoding(unscaled):
365 header = _encode_zigzag64(unscaled) << 1
366 _write_var_uint64(write_context, header)
367 return
368 magnitude = abs(unscaled)
369 if magnitude == 0:
370 raise ValueError("Zero must use the small decimal encoding")
371 magnitude_bytes = magnitude.to_bytes((magnitude.bit_length() + 7) // 8, "little", signed=False)
372 meta = (len(magnitude_bytes) << 1) | (1 if unscaled < 0 else 0)
373 _write_var_uint64(write_context, (meta << 1) | 1)
374 write_context.write_bytes(magnitude_bytes)
375
376
377def _write_var_uint64(write_context, value: int):

Callers 1

writeMethod · 0.85

Calls 6

_encode_zigzag64Function · 0.85
_write_var_uint64Function · 0.85
write_varint32Method · 0.80
to_bytesMethod · 0.45
write_bytesMethod · 0.45

Tested by

no test coverage detected