Add behavior for encoding missing fields in Struct#40
Conversation
There was a problem hiding this comment.
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 optionaloptsargument withencodeMissingFieldsBehavior. - Update
Struct#toBuffer()to conditionally skip encodingundefinedfields 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Introduce an option to control the encoding of missing fields in the
Structconstructor. 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
fromBufferdoesn't support this, because we have no mechanism to determine if a struct field is omitted from the raw data.