Skip to content

Update needed for v3.2.0 compatibility - Special Values handling #6

@beenotung

Description

@beenotung

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 to null and encoded as '' (empty string)
  • true is encoded as b|T
  • false is encoded as b|F
  • Infinity is encoded as N|+NEW
  • -Infinity is encoded as N|-NEW
  • NaN is encoded as N|0NEW

Key Additions

  1. Infinity support: Added encoding for Infinity as N|+
  2. Negative Infinity support: Added encoding for -Infinity as N|-
  3. NaN support: Added encoding for NaN as N|0
  4. 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:

  1. Add Infinity encoding: Handle INF as N|+
  2. Add Negative Infinity encoding: Handle -INF as N|-
  3. Add NaN encoding: Handle NAN as N|0
  4. Add corresponding decode support: Handle N|+, N|-, N|0 in decode functions
  5. Add tests: Include test cases for special values
  6. 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions