Skip to content

v0.3.0

Choose a tag to compare

@RezaKargar RezaKargar released this 16 Feb 16:53
· 4 commits to main since this release

What's New

NormalizeArrays — Convert PHP sequential maps to Go slices

PHP does not distinguish indexed arrays from associative arrays at the igbinary level — both are encoded as key-value maps. A PHP indexed array like ["a","b","c"] decodes as map[string]any{"0":"a","1":"b","2":"c"}.

NormalizeArrays recursively converts such maps back into []any slices so that JSON serialization produces JSON arrays instead of JSON objects.

Usage

// Option A: manual post-processing
val, _ := igbinary.Decode(data)
val = igbinary.NormalizeArrays(val)

// Option B: automatic via decoder option
dec := igbinary.NewDecoder(igbinary.WithNormalizeArrays())
val, _ := dec.Decode(data)  // sequential maps are already []any

Rules

  • Empty maps → []any{}
  • Maps with keys "0","1",…,"N-1" → []any of length N (recursive)
  • All other maps → left as-is, values recursively normalized
  • Non-map/non-slice values → unchanged

Full Changelog: v0.2.1...v0.3.0