Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] JSON Binary Encoding: Adds support for encoding uniform arrays #4889

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

kundadebdatta
Copy link
Member

Pull Request Template

Description

  • JSON Binary Encoding: Adds support for encoding uniform arrays.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Closing issues

To automatically close an issue: closes #IssueNumber

sboshra and others added 2 commits November 12, 2024 19:21
…rays (#4866)

## Description

Added full end-to-end support for writing and reading binary-encoded
uniform number arrays, as well as nested arrays of uniform number
arrays.

**Uniform Number Arrays**
A uniform number array is a JSON array where all items share the same
numeric type. The encoding supports the following numeric types:
- **Int8**: Signed 1-byte integer (-128 to 127)
- **UInt8**: Unsigned 1-byte integer (0 to 255)
- **Int16**: Signed 2-byte integer
- **Int32**: Signed 4-byte integer
- **Int64**: Signed 8-byte integer
- **Float16**: 2-byte floating-point value (currently unsupported)
- **Float32**: 4-byte floating-point value
- **Float64**: 8-byte floating-point value

Uniform number arrays are represented by these new type markers:
- **ArrNumC1**: Uniform number array with a 1-byte item count
- **ArrNumC2**: Uniform number array with a 2-byte item count

Both type markers are encoded as follows:
`| Type marker | Item type marker | Item count |`

To maintain backward compatibility, writing uniform number arrays is
controlled via the `EnableNumberArrays `write option. When enabled, at
the end of writing an array, the writer checks if all values are
numeric. It identifies the smallest numeric type that fits all values
and compares the length of the uniform number array to the regular
array. If the new length is less than or equal to the old one, the array
is converted to a uniform number array.

**Arrays of Uniform Number Arrays**
This encoding enhancement allows for encoding multiple uniform number
arrays with the same underlying numeric type and item count into a
single contiguous array of numbers. The items in all arrays are preceded
by a prefix indicating the common array encoding and the number of
encoded arrays.

Arrays of uniform number arrays are supported by these two new
type-markers:

- **ArrArrNumC1C1**: Array of 1-byte item count of common uniform number
arrays with 1-byte item count.
- **ArrArrNumC2C2**: Array of 2-byte item count of common uniform number
arrays with 2-byte item count.

Both new values are encoded as follows:
`| Type-marker | Array type-marker | Number type-marker | Number item
count | Array item count |`

Similar to uniform number arrays, the writing of arrays of uniform
number arrays is conditional on the `EnableNumberArrays` write option
being specified. This ensures backward compatibility with readers and
navigators that do not yet support this encoding.

**JSON Serialization Testing**

- Introduced a new set of tests for both uniform number arrays and
nested arrays of uniform number arrays.
- Enhanced the `JsonToken` class to support representation of uniform
number array tokens.
- Updated `JsonWriterTest` to include additional validation. This now
not only checks the expected output but also verifies round-trip
consistency across different formats and write options for all three
rewrite scenarios: JSON Navigator, JSON Reader - Write All, and JSON
Reader - Write Current Token.


## Type of change

Please delete options that are not relevant.

- [ ] New feature (non-breaking change which adds functionality)

## Closing issues
# Pull Request Template

## Description

This bumps the SDK GA version from `3.45.1` to `3.45.2` and preview
version from `3.46.0-preview.1` to `3.46.0-preview.2`. No changes in the
public GA and preview contract/s.

## Type of change

Please delete options that are not relevant.

- [x] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #IssueNumber
Copy link
Contributor

@aavasthy aavasthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kundadebdatta kundadebdatta added the auto-merge Enables automation to merge PRs label Nov 13, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit d5e954c into releases/3.45.2 Nov 13, 2024
24 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the hotfix/3.45.2 branch November 13, 2024 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Enables automation to merge PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants