Skip to content

Commit

Permalink
feat: Treat out-of-version fields as optional and decode if provided
Browse files Browse the repository at this point in the history
If a field is given while it does not belong to the current protocol version
there's no reason not to decode it still. The request stays valid.

Signed-off-by: Pierre-Henri Symoneaux <[email protected]>
  • Loading branch information
phsym committed Mar 6, 2025
1 parent ecb8034 commit cb4fafd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ttlv/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,14 @@ func structDecodeFunc(ty reflect.Type) func(d *Decoder, tag int, value reflect.V
}
if info.vrange != nil {
ff := ffunc
ffunc = func(d *Decoder, _ int, v reflect.Value) error {
if !d.versionIn(*info.vrange) {
ffunc = func(d *Decoder, i int, v reflect.Value) error {
// If the field is not for current version, consider it optional
// (but still accept and decode it if it's present)
if !d.versionIn(*info.vrange) && d.Tag() != i {
v.SetZero()
return nil
}
return ff(d, numTag, v)
return ff(d, i, v)
}
}
if info.setVersion {
Expand Down

0 comments on commit cb4fafd

Please sign in to comment.