diff --git a/tape/dynamic.go b/tape/dynamic.go index 7ce7665..763d5db 100644 --- a/tape/dynamic.go +++ b/tape/dynamic.go @@ -59,6 +59,7 @@ func EncodeAny(encoder *Encoder, value any, tag Tag) (n int, err error) { case reflect.Uint64: return encoder.WriteUint64(uint64(reflectValue.Uint())) case reflect.Float32: return encoder.WriteFloat32(float32(reflectValue.Float())) case reflect.Float64: return encoder.WriteFloat64(float64(reflectValue.Float())) + case reflect.Bool: return // SI has no payload case reflect.String: if reflectValue.Len() > MaxStructureLength { return 0, ErrTooLong @@ -298,6 +299,12 @@ func tagAny(reflectValue reflect.Value) (Tag, error) { case reflect.Uint64: return LI.WithCN(7), nil case reflect.Float32: return FP.WithCN(3), nil case reflect.Float64: return FP.WithCN(7), nil + case reflect.Bool: + if reflectValue.Bool() { + return SI.WithCN(1), nil + } else { + return SI.WithCN(0), nil + } case reflect.String: return bufferLenTag(reflectValue.Len()), nil } if reflectValue.CanConvert(reflect.TypeOf(dummyBuffer)) { @@ -374,7 +381,8 @@ func canSet(destination reflect.Type, tag Tag) error { switch destination.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, - reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, + reflect.Bool: default: return errCantAssignf("cannot assign integer to %v", destination) }