From 98824e9bd93d911839efcbe27f33e624f90b924f Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 15 Feb 2021 18:45:58 +0900 Subject: [PATCH] Fix decoding of struct type --- decode_struct.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/decode_struct.go b/decode_struct.go index bfd46d6..2ccb6dd 100644 --- a/decode_struct.go +++ b/decode_struct.go @@ -483,6 +483,7 @@ func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error { } } s.cursor++ + s.skipWhiteSpace() if s.char() == '}' { s.cursor++ return nil @@ -551,10 +552,12 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6 default: return 0, errNotAtBeginningOfValue(cursor) } - if buflen < 2 { - return 0, errUnexpectedEndOfJSON("object", cursor) - } cursor++ + cursor = skipWhiteSpace(buf, cursor) + if buf[cursor] == '}' { + cursor++ + return cursor, nil + } for { c, field, err := d.keyDecoder(d, buf, cursor) if err != nil {