Skip to content

Commit cb4fafd

Browse files
committed
feat: Treat out-of-version fields as optional and decode if provided
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]>
1 parent ecb8034 commit cb4fafd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ttlv/decoder.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,14 @@ func structDecodeFunc(ty reflect.Type) func(d *Decoder, tag int, value reflect.V
481481
}
482482
if info.vrange != nil {
483483
ff := ffunc
484-
ffunc = func(d *Decoder, _ int, v reflect.Value) error {
485-
if !d.versionIn(*info.vrange) {
484+
ffunc = func(d *Decoder, i int, v reflect.Value) error {
485+
// If the field is not for current version, consider it optional
486+
// (but still accept and decode it if it's present)
487+
if !d.versionIn(*info.vrange) && d.Tag() != i {
488+
v.SetZero()
486489
return nil
487490
}
488-
return ff(d, numTag, v)
491+
return ff(d, i, v)
489492
}
490493
}
491494
if info.setVersion {

0 commit comments

Comments
 (0)