77# cython: wraparound=True
88# cython: boundscheck=False
99
10- import decimal
11- import pybase64 as base64
12-
1310from libc.stdint cimport int64_t, uint64_t
14- from cpython.list cimport PyList_Size
1511from libc.math cimport isnan
1612from libcpp.unordered_map cimport unordered_map
1713from cython.operator cimport dereference, preincrement
@@ -36,27 +32,6 @@ cdef inline int64_t map_get(unordered_map[string, int64_t]& m, string key, int64
3632 return m[key]
3733 return default_val
3834
39- cdef object _orjson_default(obj):
40- objtype = type (obj)
41- if objtype == decimal.Decimal:
42- return {" __decimal__" : str (obj)}
43- if objtype == bytes:
44- return {" __bytes__" : base64.b64encode(obj).decode(" utf-8" )}
45- return str (obj)
46-
47- cdef object _decode_object(object obj):
48- cdef Py_ssize_t i, sz
49- if isinstance (obj, dict ):
50- if " __decimal__" in obj:
51- return decimal.Decimal(obj[" __decimal__" ])
52- if " __bytes__" in obj:
53- return base64.b64decode(obj[" __bytes__" ])
54- return {k: _decode_object(v) for k, v in obj.items()}
55- elif isinstance (obj, list ):
56- sz = PyList_Size(obj)
57- return [_decode_object(< object > PyList_GET_ITEM(obj, i)) for i in range (sz)]
58- return obj
59-
6035cdef inline int64_t _ensure_64bit_range(int64_t val):
6136 if val < MIN_SIGNED_64BIT:
6237 return MIN_SIGNED_64BIT
0 commit comments