Skip to content

Commit

Permalink
pblite: fix deserializing bools
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 25, 2024
1 parent 33d03e7 commit b6e5a0c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pblite/deserialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,13 @@ func deserializeOne(val any, index int, ref protoreflect.Message, insideList pro
expectedKind = "string"
outputVal = protoreflect.ValueOfString(str)
case protoreflect.BoolKind:
boolean, ok = val.(bool)
expectedKind = "bool"
outputVal = protoreflect.ValueOfBool(boolean)
expectedKind = "bool or float"
var float float64
if boolean, ok = val.(bool); ok {
outputVal = protoreflect.ValueOfBool(boolean)
} else if float, ok = val.(float64); ok {
outputVal = protoreflect.ValueOfBool(float != 0)
}
default:
return outputVal, fmt.Errorf("unsupported field type %s in %s", fieldDescriptor.Kind(), fieldDescriptor.FullName())
}
Expand Down

0 comments on commit b6e5a0c

Please sign in to comment.