From 5f0b34250c272a881ff65bff535693263540b9e3 Mon Sep 17 00:00:00 2001 From: ebauer Date: Wed, 23 Jun 2021 15:51:42 +0200 Subject: [PATCH] funcDecoder: handle cases of value being true or false --- internal/decoder/func.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/internal/decoder/func.go b/internal/decoder/func.go index b7d2447..75afe75 100644 --- a/internal/decoder/func.go +++ b/internal/decoder/func.go @@ -53,9 +53,26 @@ func (d *funcDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) err Offset: s.totalOffset(), } case 'n': - if bytes.Equal(src, nullbytes) { - *(*unsafe.Pointer)(p) = nil - return nil + if err := nullBytes(s); err != nil { + return err + } + *(*unsafe.Pointer)(p) = nil + return nil + case 't': + if err := trueBytes(s); err == nil { + return &errors.UnmarshalTypeError{ + Value: "boolean", + Type: runtime.RType2Type(d.typ), + Offset: s.totalOffset(), + } + } + case 'f': + if err := falseBytes(s); err == nil { + return &errors.UnmarshalTypeError{ + Value: "boolean", + Type: runtime.RType2Type(d.typ), + Offset: s.totalOffset(), + } } } } @@ -102,6 +119,22 @@ func (d *funcDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe. *(*unsafe.Pointer)(p) = nil return end, nil } + case 't': + if err := validateTrue(buf, start); err == nil { + return 0, &errors.UnmarshalTypeError{ + Value: "boolean", + Type: runtime.RType2Type(d.typ), + Offset: start, + } + } + case 'f': + if err := validateFalse(buf, start); err == nil { + return 0, &errors.UnmarshalTypeError{ + Value: "boolean", + Type: runtime.RType2Type(d.typ), + Offset: start, + } + } } } return 0, errors.ErrNotAtBeginningOfValue(start)