Skip to content

Commit

Permalink
fix decoding lists of TRUE values (#122)
Browse files Browse the repository at this point in the history
* fix decoding lists of TRUE values

* fix typo

* minimal code change
  • Loading branch information
Achille authored Apr 26, 2022
1 parent 886f222 commit a1e4c6b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions thrift/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/ioutil"
"math/bits"
"reflect"
"sync/atomic"
)
Expand Down Expand Up @@ -219,6 +218,15 @@ func decodeFuncSliceOf(t reflect.Type, seen decodeFuncCache) decodeFunc {
return err
}

// Sometimes the list type is set to TRUE when the list contains only
// TRUE values. Thrift does not seem to optimize the encoding by
// omitting the boolean values that are known to all be TRUE, we still
// need to decode them.
switch l.Type {
case TRUE:
l.Type = BOOL
}

// TODO: implement type conversions?
if typ != l.Type {
if flags.have(strict) {
Expand Down Expand Up @@ -314,6 +322,13 @@ func decodeFuncMapAsSetOf(t reflect.Type, seen decodeFuncCache) decodeFunc {
return err
}

// See decodeFuncSliceOf for details about why this type conversion
// needs to be done.
switch s.Type {
case TRUE:
s.Type = BOOL
}

v.Set(reflect.MakeMapWithSize(t, int(s.Size)))

if s.Size == 0 {
Expand Down Expand Up @@ -415,8 +430,12 @@ func (dec *structDecoder) decode(r Reader, v reflect.Value, flags flags) error {

for i, required := range dec.required {
if mask := required & seen[i]; mask != required {
index := bits.TrailingZeros64(mask)
field := &dec.fields[i+index]
i *= 64
for (mask & 1) != 0 {
mask >>= 1
i++
}
field := &dec.fields[i]
return &MissingField{Field: Field{ID: field.id, Type: field.typ}}
}
}
Expand Down

0 comments on commit a1e4c6b

Please sign in to comment.