Skip to content

Add behavior for encoding missing fields in Struct#40

Merged
nozols merged 6 commits intomasterfrom
feature/add-missing-fields-behavior
Mar 6, 2026
Merged

Add behavior for encoding missing fields in Struct#40
nozols merged 6 commits intomasterfrom
feature/add-missing-fields-behavior

Conversation

@nozols
Copy link
Contributor

@nozols nozols commented Mar 2, 2026

Introduce an option to control the encoding of missing fields in the Struct constructor. This change allows users to skip encoding of undefined fields based on the specified behavior. Additional tests ensure the new functionality works as intended.

Note that fromBuffer doesn't support this, because we have no mechanism to determine if a struct field is omitted from the raw data.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an option to Struct() intended to control how missing fields are encoded, and introduces tests for the new behavior.

Changes:

  • Extend Struct(name, defs) to accept an optional opts argument with encodeMissingFieldsBehavior.
  • Update Struct#toBuffer() to conditionally skip encoding undefined fields when configured.
  • Add unit tests covering default behavior and the new skip mode.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
lib/Struct.js Adds opts parameter and a conditional skip in the encoding loop.
test/Struct.test.js Adds tests for default encoding of missing fields and skip behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nozols nozols merged commit 0867242 into master Mar 6, 2026
3 checks passed
@nozols nozols deleted the feature/add-missing-fields-behavior branch March 6, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants