-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Issue: Update needed for v3.2.0 compatibility - Special Values handling
Summary
The javascript and python version compress-json library has been updated to v3.2.0 with new encoding support for special floating-point values. The PHP implementation should be updated to maintain compatibility.
Changes in v3.2.0
Special Values Encoding
The following special values now have standardized encoding across all implementations:
null
is encoded as''
(empty string)undefined
is converted tonull
and encoded as''
(empty string)true
is encoded asb|T
false
is encoded asb|F
Infinity
is encoded asN|+
⭐ NEW-Infinity
is encoded asN|-
⭐ NEWNaN
is encoded asN|0
⭐ NEW
Key Additions
- Infinity support: Added encoding for
Infinity
asN|+
- Negative Infinity support: Added encoding for
-Infinity
asN|-
- NaN support: Added encoding for
NaN
asN|0
- Documentation: Added comprehensive "Special Values" section to README
Implementation Details
JavaScript/TypeScript Changes
// Before: No special handling for Infinity/NaN
export function encodeNum(num: number): string {
const a = 'n|' + num_to_s(num)
return a
}
// After: Added special value handling
export function encodeNum(num: number): string {
if (num === Infinity) return 'N|+'
if (num === -Infinity) return 'N|-'
if (Number.isNaN(num)) return 'N|0'
const a = 'n|' + num_to_s(num)
return a
}
Python Changes
# Before: No special handling for Infinity/NaN
def encode_num(num):
return 'n|' + num_to_s(num)
# After: Added special value handling
def encode_num(num):
if num == float('inf'):
return 'N|+'
if num == float('-inf'):
return 'N|-'
if math.isnan(num):
return 'N|0'
return 'n|' + num_to_s(num)
Action Required
Please update the PHP implementation to:
- Add Infinity encoding: Handle
INF
asN|+
- Add Negative Infinity encoding: Handle
-INF
asN|-
- Add NaN encoding: Handle
NAN
asN|0
- Add corresponding decode support: Handle
N|+
,N|-
,N|0
in decode functions - Add tests: Include test cases for special values
- Update documentation: Add "Special Values" section to README
Compatibility
This update adds new functionality for special values. Data compressed with v3.2.0 that contains Infinity
, -Infinity
, or NaN
will not be compatible with previous versions that don't support these encodings.
References
Labels
enhancement
compatibility
new-feature
Metadata
Metadata
Assignees
Labels
No labels