Fix decoder

This commit is contained in:
Masaaki Goshima 2020-04-26 14:59:45 +09:00
parent 2c698a30a8
commit 3bd7507c30
3 changed files with 31 additions and 2 deletions

View File

@ -130,7 +130,6 @@ func Benchmark_Decode_MediumStruct_GoJayUnsafe(b *testing.B) {
}
}
/*
func Benchmark_Decode_MediumStruct_GoJson(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
@ -150,7 +149,6 @@ func Benchmark_Decode_MediumStruct_GoJsonNoEscape(b *testing.B) {
}
}
}
*/
func Benchmark_Decode_LargeStruct_EncodingJson(b *testing.B) {
b.ReportAllocs()

View File

@ -46,6 +46,21 @@ func (d *stringDecoder) decodeByte(ctx *context) ([]byte, error) {
}
}
return nil, errors.New("unexpected error string")
case 'n':
if cursor+3 >= ctx.buflen {
return nil, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+1] != 'u' {
return nil, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+2] != 'l' {
return nil, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+3] != 'l' {
return nil, errors.New("unexpected error. invalid bool character")
}
ctx.cursor += 5
return []byte{}, nil
}
}
return nil, errors.New("unexpected error key delimiter")

View File

@ -38,14 +38,29 @@ func (d *structDecoder) skipValue(ctx *context) error {
case '}':
braceCount--
if braceCount == -1 && bracketCount == 0 {
ctx.cursor = cursor
return nil
}
case ']':
bracketCount--
case ',':
if bracketCount == 0 && braceCount == 0 {
ctx.cursor = cursor
return nil
}
case '"':
cursor++
for ; cursor < buflen; cursor++ {
tk := buf[cursor]
if tk == '\\' {
cursor++
continue
}
if tk == '"' {
cursor++
break
}
}
}
}
return errors.New("unexpected error value")
@ -91,6 +106,7 @@ func (d *structDecoder) decode(ctx *context, p uintptr) error {
}
cursor = ctx.skipWhiteSpace()
if buf[cursor] == '}' {
ctx.cursor++
return nil
}
if buf[cursor] != ',' {