You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some scenarios, it is necessary to ignore the structure length.
One such example is Tarantool. Due to the specifics of the Lua language, a structure that has an empty value at the end (for example, {0, nil, 1, 2, nil}) is truncated to the last non-nil value and becomes {0, nil, 1, 2}.
Despite this behavior, the official Go module github.com/tarantool/go-tarantool/v2 still uses the github.com/vmihailenco/msgpack module in the decoder (see here), which reports an error in such cases: msgpack: number of fields in array-encoded struct has changed.
This PR introduces an option to ignore this error and also fixes decoding when the number of fields differs from what is defined in the struct.
Thanks for porting this from upstream — the core change is small, correct, and the trailing skipNext(n) is the right call to keep stream position consistent for reused decoders. A few requests before merge:
Test-local constant shadows the package constant.types_test.go:36-38 defines ignoreStructLength uint32 = 1 << iota inside the test file, same name as the unexported package constant in decode.go:26. They evaluate to the same bit today by coincidence (both 1 << 0 in their respective iota groups), but if the package-level iota block is ever reordered the tests will still pass while real users break. Could you rename the test constant to something like testIgnoreStructLength, or drop it entirely and just call dec.IgnoreStructLength(true) directly from the test setup?
Doc comment needs more detail.decode.go:265 currently says only IgnoreStructLength disables field count verification during parsing. Users reaching for this won't know the actual semantics — that extra payload elements are skipped, and missing struct fields are left at zero value. Could you expand the comment to spell that out? Something like:
// IgnoreStructLength disables the field-count check when decoding an// array-encoded struct. When enabled, extra elements in the payload are// skipped, and missing trailing fields are left at their zero value.// This is useful for sources like Tarantool that truncate trailing nils.
Naming consistency (optional). Every other flag in that iota block ends in Flag (looseInterfaceDecodingFlag, disallowUnknownFieldsFlag, disableAllocLimitFlag). Renaming ignoreStructLength → ignoreStructLengthFlag would match the dominant pattern. Not a blocker but worth doing while you're in there.
CHANGELOG entry. This is a public API addition and our project guidelines ask for divergence from upstream to be documented. Could you add an entry to CHANGELOG.md?
Once those are addressed I'll run the post-implementation review pass and we can get this merged. Thanks again!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Ported from vmihailenco#382 by vmihailenco#382 (comment) request)
In some scenarios, it is necessary to ignore the structure length.
One such example is Tarantool. Due to the specifics of the Lua language, a structure that has an empty value at the end (for example,
{0, nil, 1, 2, nil}) is truncated to the last non-nil value and becomes{0, nil, 1, 2}.More details are available in the Tarantool documentation.
Despite this behavior, the official Go module github.com/tarantool/go-tarantool/v2 still uses the
github.com/vmihailenco/msgpackmodule in the decoder (see here), which reports an error in such cases:msgpack: number of fields in array-encoded struct has changed.This PR introduces an option to ignore this error and also fixes decoding when the number of fields differs from what is defined in the struct.