go-json-experiment / json

Experimental implementation of a proposed v2 encoding/json package
BSD 3-Clause "New" or "Revised" License
341 stars 11 forks source link

Use int64 for object or array length #27

Closed dsnet closed 2 months ago

dsnet commented 2 months ago

WARNING: This commit includes breaking changes.

When processing JSON as a stream, it is conceivable that the total number of elements in a JSON object or array exceeds a 32-bit integer.

Switch from int to int64 for a similar reason as why io.Copy returns int64 instead of int.

Note that the depth still uses an int because the stack must be representable in memory, which is limited to the native integer width of the platform. This is similar to how io.Reader.Read returns an int because the length of a []byte cannot possibly be larger than the largest int.