diff options
Diffstat (limited to 'decode.go')
-rw-r--r-- | decode.go | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -891,13 +891,12 @@ func (dec *Decoder) scanNumber(gTyp reflect.Type, out fastio.RuneWriter) *Decode } func (dec *Decoder) decodeAny() (any, *DecodeError) { - c, _, err := dec.readRune() + t, err := dec.peekRuneType() if err != nil { return nil, err } - dec.unreadRune() - switch c { - case '{': + switch t { + case jsonparse.RuneTypeObjectBeg: ret := make(map[string]any) typ := reflect.TypeOf(ret) var nameBuf strings.Builder @@ -922,7 +921,7 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { return nil, err } return ret, nil - case '[': + case jsonparse.RuneTypeArrayBeg: ret := []any{} typ := reflect.TypeOf(ret) if err := dec.decodeArray(typ, func() *DecodeError { @@ -940,13 +939,13 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { return nil, err } return ret, nil - case '"': + case jsonparse.RuneTypeStringBeg: var buf strings.Builder if err := dec.decodeString(nil, &buf); err != nil { return nil, err } return buf.String(), nil - case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + case jsonparse.RuneTypeNumberIntNeg, jsonparse.RuneTypeNumberIntZero, jsonparse.RuneTypeNumberIntDig: var buf strings.Builder if err := dec.scan(&buf); err != nil { return nil, err @@ -960,9 +959,9 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { return nil, dec.newTypeError("number "+buf.String(), float64Type, err) } return f64, nil - case 't', 'f': + case jsonparse.RuneTypeTrueT, jsonparse.RuneTypeFalseF: return dec.decodeBool(nil) - case 'n': + case jsonparse.RuneTypeNullN: return nil, dec.decodeNull() default: panic("should not happen") |