Skip to content

Read full-width packed 16- and 32-bit integers little-endian - #41

Merged
mahach666 merged 1 commit into
mainfrom
fix/7-packed-int-byte-order
Nov 11, 2026
Merged

mahach666 merged 1 commit into
mainfrom
fix/7-packed-int-byte-order

Conversation

@mahach666

Copy link
Copy Markdown
Contributor

What changes and why

Fixes #7. The full-width form (tag 00) of packed shorts and packed integers was read with ReadBits(16) / ReadBits(32), which puts the first byte in the most significant position. These values are stored little-endian. Entity records that hold a colour, extended data size or reactor count in that form were then decoded from the wrong bit position. Such records failed, or decoded with NaN, infinite or absurd coordinates. Some JSON exports failed on the NaN values.

ReadPackedShort and ReadPackedInt now read the full-width form byte by byte, low byte first, the same way ReadRawUInt32 reads raw integers. The short forms (tags 01, 10, 11) are unchanged. The object type of pre-R2010 records goes through ReadPackedShort and is corrected as well.

Tests added in BitReaderTests:

  • full-width forms, aligned and unaligned;
  • the unchanged short forms;
  • the object type of pre-R2010 records.

Four of the new tests fail on the old reader. The short-form test passes on both.

How it was checked

Notes for review:

The full-width form of packed shorts and packed integers was read with
its bytes reversed. Entity records that store a colour, extended data
size or reactor count in that form were then decoded from the wrong bit
position, which failed the record or produced NaN and absurd
coordinates. Read both forms byte by byte, low byte first, as raw
32-bit integers already are.

Tests cover the full-width forms (aligned and unaligned), the unchanged
short forms, and the object type of pre-R2010 records, which goes
through the same reader.

Fixes #7
@mahach666
mahach666 merged commit e15cb3d into main Nov 11, 2026
4 checks passed
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.

Full-width packed 16-bit and 32-bit integers are read with their bytes reversed

1 participant