Skip to content

fix(ts): support PhysicalLevelTechnique.NONE for integer streams#1138

Open
DoFabien wants to merge 2 commits into
maplibre:mainfrom
DoFabien:fix/ts-integer-physical-none
Open

fix(ts): support PhysicalLevelTechnique.NONE for integer streams#1138
DoFabien wants to merge 2 commits into
maplibre:mainfrom
DoFabien:fix/ts-integer-physical-none

Conversation

@DoFabien

Copy link
Copy Markdown
Contributor

replace #1136

This PR fixes TypeScript support for PhysicalLevelTechnique.NONE on integer streams.

The previous implementation did not read or write integer payloads as explicit little-endian words. In practice:

  • the 32-bit NONE path decoded bytes incorrectly
  • the 32-bit encoder did not emit plain little-endian integer payloads correctly
  • the 64-bit integer stream decode paths did not support NONE

Changes

  • decode integer NONE payloads as little-endian integer words
  • encode integer NONE payloads as little-endian integer words
  • add NONE support to the TypeScript int64 integer stream decode paths
  • split the physical integer decode path into explicit Int32 / Int64 helpers
  • update tests so they actually exercise physicalLevelTechnique: NONE

Note

The repository is currently inconsistent on this topic:

  • docs/specification.md and docs/encodings.md do not describe the same story
  • Rust / C++ / Java do not currently behave the same way for integer NONE

I will open a separate issue in the next few hours to clarify the intended project-wide direction for the spec and the other implementations.


/**
* Encodes unsigned BigInt64 values with varint compression (no zigzag)
* Encodes unsigned BigInt64 values as plain little-endian uint64 words.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably better to remove single line methods as it doesn't add a lot of value I believe...

return buffer;
}

export function encodeUint32sLE(values: Uint32Array): Uint8Array {

@HarelM HarelM Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this a simple copy of the data? If so maybe it's better to rename the method as copyArray, or simply remove it and use the content of the method when needed.

Comment thread ts/src/decoding/integerStreamDecoder.ts Outdated
const byteOffset = offset.get();
values = new Int32Array(data.buffer, data.byteOffset + byteOffset, 4);
const decoded = decodeUint32sLE(data, offset, 4);
values = new Int32Array(decoded.buffer, decoded.byteOffset, decoded.length);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this be written like in the previous if statement as values = new Int32Array(decodeUint32sLE(data, offset, 4));?
Or maybe even something like:

let values: Int32Array = streamMetadata.physicalLevelTechnique === PhysicalLevelTechnique.VARINT 
  ? decodeVarintInt32(data, offset, 4) 
  : decodeUint32sLE(data, offset, 4);

}

export function encodeUint64sLE(values: BigUint64Array): Uint8Array {
return new Uint8Array(values.slice().buffer);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above.

expect(result).toEqual(expectedValues);
});

it("should decode little-endian signed Int64 words with PhysicalLevelTechnique.NONE", () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test is not clear how the data is transformed from 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 to -8n.
I advise to add an encoderMethod to bridge this gap.


it("should decode little-endian unsigned Int64 words with PhysicalLevelTechnique.NONE", () => {
const metadata = createInt64PhysicalNoneMetadata(1);
const data = new Uint8Array([0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above.

expect(offset.get()).toBe(16);
});

it("should decode uint64 values from little-endian bytes", () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.

return fb;
}

export function decodeUint32sLE(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Other methods in this file has support for nullabilityBuffer, do the new methods require this support as well?

Also other methods are not throwing exceptions, so I think it's better to keep it without exception handling at this level.

@HarelM

HarelM commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Might be worth waiting for a decision about the issue you opened before continuing with the implementation.
In any case, I've added some comments, mostly about expected vs input values in the tests - the more straight forwards this is the better we will be able to review and make sure the tests are working as expected.

@HarelM

HarelM commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks again for all the hard work on this!

@CommanderStorm
CommanderStorm force-pushed the fix/ts-integer-physical-none branch from 7ec23f0 to a942f68 Compare July 19, 2026 00:46
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.02%. Comparing base (d1e2260) to head (a942f68).

Files with missing lines Patch % Lines
ts/src/decoding/decodingUtils.ts 84.61% 4 Missing ⚠️
ts/src/decoding/integerStreamDecoder.ts 91.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1138       +/-   ##
===========================================
+ Coverage   64.58%   96.02%   +31.43%     
===========================================
  Files          93       68       -25     
  Lines       15606     4929    -10677     
  Branches        0      776      +776     
===========================================
- Hits        10079     4733     -5346     
+ Misses       5527      182     -5345     
- Partials        0       14       +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants