Skip to content

Commit a1e4c6b

Browse files
author
Achille
authored
fix decoding lists of TRUE values (#122)
* fix decoding lists of TRUE values * fix typo * minimal code change
1 parent 886f222 commit a1e4c6b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

thrift/decode.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"io/ioutil"
9-
"math/bits"
109
"reflect"
1110
"sync/atomic"
1211
)
@@ -219,6 +218,15 @@ func decodeFuncSliceOf(t reflect.Type, seen decodeFuncCache) decodeFunc {
219218
return err
220219
}
221220

221+
// Sometimes the list type is set to TRUE when the list contains only
222+
// TRUE values. Thrift does not seem to optimize the encoding by
223+
// omitting the boolean values that are known to all be TRUE, we still
224+
// need to decode them.
225+
switch l.Type {
226+
case TRUE:
227+
l.Type = BOOL
228+
}
229+
222230
// TODO: implement type conversions?
223231
if typ != l.Type {
224232
if flags.have(strict) {
@@ -314,6 +322,13 @@ func decodeFuncMapAsSetOf(t reflect.Type, seen decodeFuncCache) decodeFunc {
314322
return err
315323
}
316324

325+
// See decodeFuncSliceOf for details about why this type conversion
326+
// needs to be done.
327+
switch s.Type {
328+
case TRUE:
329+
s.Type = BOOL
330+
}
331+
317332
v.Set(reflect.MakeMapWithSize(t, int(s.Size)))
318333

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

416431
for i, required := range dec.required {
417432
if mask := required & seen[i]; mask != required {
418-
index := bits.TrailingZeros64(mask)
419-
field := &dec.fields[i+index]
433+
i *= 64
434+
for (mask & 1) != 0 {
435+
mask >>= 1
436+
i++
437+
}
438+
field := &dec.fields[i]
420439
return &MissingField{Field: Field{ID: field.id, Type: field.typ}}
421440
}
422441
}

0 commit comments

Comments
 (0)