@@ -50,9 +50,33 @@ def _reject_nonfinite_json(value: str) -> None:
5050 raise ValueError (f"non-finite JSON constant: { value } " )
5151
5252
53+ def _decode_json_integer (value : str ) -> int | float :
54+ """Keep ordinary integers exact and accept finite JavaScript wire numbers.
55+
56+ Cosmoaudition serializes IEEE-754 numbers with ``JSON.stringify``. A value
57+ such as the Bitcoin hashrate can therefore arrive with an integer spelling
58+ outside GERM's signed-64-bit persistence boundary even though the producer
59+ already represents it as a finite float. Preserve normal JSON integers as
60+ integers, but materialize those wider wire values as finite floats so one
61+ observation cannot invalidate the complete modulation frame.
62+ """
63+
64+ decoded = int (value )
65+ if - (2 ** 63 ) <= decoded < 2 ** 63 :
66+ return decoded
67+ widened = float (value )
68+ if not math .isfinite (widened ):
69+ raise ValueError ("JSON integer exceeds the finite-number boundary" )
70+ return widened
71+
72+
5373def _decode_json_object (raw : bytes ) -> dict [str , Any ]:
5474 try :
55- value = json .loads (raw , parse_constant = _reject_nonfinite_json )
75+ value = json .loads (
76+ raw ,
77+ parse_constant = _reject_nonfinite_json ,
78+ parse_int = _decode_json_integer ,
79+ )
5680 except (UnicodeError , json .JSONDecodeError , ValueError , RecursionError ) as exc :
5781 raise CosmoauditionBridgeError ("Cosmoaudition returned invalid JSON" ) from exc
5882 if not isinstance (value , dict ):
0 commit comments