From b6e5a0cd5cbd2203ed975f4becfd3c9009df8fb3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 25 Aug 2024 14:47:09 +0300 Subject: [PATCH] pblite: fix deserializing bools --- pblite/deserialize.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pblite/deserialize.go b/pblite/deserialize.go index e094dd3..5867e2a 100644 --- a/pblite/deserialize.go +++ b/pblite/deserialize.go @@ -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()) }