-
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:
nullis encoded as''(empty string)undefinedis converted tonulland encoded as''(empty string)trueis encoded asb|Tfalseis encoded asb|FInfinityis encoded asN|+⭐ NEW-Infinityis encoded asN|-⭐ NEWNaNis encoded asN|0⭐ NEW
Key Additions
- Infinity support: Added encoding for
InfinityasN|+ - Negative Infinity support: Added encoding for
-InfinityasN|- - NaN support: Added encoding for
NaNasN|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
INFasN|+ - Add Negative Infinity encoding: Handle
-INFasN|- - Add NaN encoding: Handle
NANasN|0 - Add corresponding decode support: Handle
N|+,N|-,N|0in 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
enhancementcompatibilitynew-feature
Metadata
Metadata
Assignees
Labels
No labels