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

Function make_msgpack_compatible

benchmarks/python/fory_benchmark.py:336–354  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

334
335
336def make_msgpack_compatible(obj):
337 if isinstance(obj, datetime.date):
338 return obj.isoformat()
339 if isinstance(obj, array.array):
340 return obj.tolist()
341 if is_dataclass(obj):
342 return {
343 f.name: make_msgpack_compatible(getattr(obj, f.name)) for f in fields(obj)
344 }
345 if isinstance(obj, dict):
346 return {
347 make_msgpack_compatible(k): make_msgpack_compatible(v)
348 for k, v in obj.items()
349 }
350 if isinstance(obj, list):
351 return [make_msgpack_compatible(v) for v in obj]
352 if isinstance(obj, tuple):
353 return tuple(make_msgpack_compatible(v) for v in obj)
354 return obj
355
356
357def _restore_dataclass_from_template(value, template):

Callers 4

micro_benchmarkFunction · 0.85

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected