summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2025-04-14 09:43:56 +0200
committerLibravatar GitHub <noreply@github.com>2025-04-14 09:43:56 +0200
commit51b9ef5c346f333e558eca38fd954464322f3b7d (patch)
treebf5cd0de887a27c1afc66345b1a464921d96e503 /vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go
parent[docs] Remind the user that password resets don't work without restarting. (#... (diff)
downloadgotosocial-51b9ef5c346f333e558eca38fd954464322f3b7d.tar.xz
[chore]: Bump github.com/gin-contrib/gzip from 1.2.2 to 1.2.3 (#4000)
Bumps [github.com/gin-contrib/gzip](https://github.com/gin-contrib/gzip) from 1.2.2 to 1.2.3. - [Release notes](https://github.com/gin-contrib/gzip/releases) - [Changelog](https://github.com/gin-contrib/gzip/blob/master/.goreleaser.yaml) - [Commits](https://github.com/gin-contrib/gzip/compare/v1.2.2...v1.2.3) --- updated-dependencies: - dependency-name: github.com/gin-contrib/gzip dependency-version: 1.2.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go')
-rw-r--r--vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go56
1 files changed, 42 insertions, 14 deletions
diff --git a/vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go b/vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go
index 1a2bda8f3..958ebc4b0 100644
--- a/vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go
+++ b/vendor/github.com/bytedance/sonic/internal/decoder/optdec/map.go
@@ -292,9 +292,9 @@ func (d *mapU64KeyDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) e
/** Decoder for generic cases */
-type decKey func(dec *mapDecoder, raw string, ctx *context) (interface{}, error)
+type decKey func(dec *mapDecoder, raw string) (interface{}, error)
-func decodeKeyU8(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
+func decodeKeyU8(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@@ -309,7 +309,7 @@ func decodeKeyU8(dec *mapDecoder, raw string, ctx *context) (interface{}, error)
return uint8(ret), nil
}
-func decodeKeyU16(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
+func decodeKeyU16(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@@ -324,7 +324,7 @@ func decodeKeyU16(dec *mapDecoder, raw string, ctx *context) (interface{}, error
return uint16(ret), nil
}
-func decodeKeyI8(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
+func decodeKeyI8(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@@ -339,7 +339,7 @@ func decodeKeyI8(dec *mapDecoder, raw string, ctx *context) (interface{}, error)
return int8(ret), nil
}
-func decodeKeyI16(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
+func decodeKeyI16(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@@ -354,26 +354,53 @@ func decodeKeyI16(dec *mapDecoder, raw string, ctx *context) (interface{}, error
return int16(ret), nil
}
-func decodeKeyJSONUnmarshaler(dec *mapDecoder, raw string, _ *context) (interface{}, error) {
+func decodeKeyTextUnmarshaler(dec *mapDecoder, raw string) (interface{}, error) {
+ key, err := Unquote(raw)
+ if err != nil {
+ return nil, err
+ }
ret := reflect.New(dec.mapType.Key.Pack()).Interface()
- err := ret.(json.Unmarshaler).UnmarshalJSON([]byte(raw))
+ err = ret.(encoding.TextUnmarshaler).UnmarshalText(rt.Str2Mem(key))
if err != nil {
return nil, err
}
return ret, nil
}
-func decodeKeyTextUnmarshaler(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
+func decodeFloat32Key(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
}
- ret := reflect.New(dec.mapType.Key.Pack()).Interface()
- err = ret.(encoding.TextUnmarshaler).UnmarshalText([]byte(key))
+ ret, err := ParseF64(key)
if err != nil {
return nil, err
}
- return ret, nil
+ if ret > math.MaxFloat32 || ret < -math.MaxFloat32 {
+ return nil, error_value(key, dec.mapType.Key.Pack())
+ }
+ return float32(ret), nil
+}
+
+func decodeFloat64Key(dec *mapDecoder, raw string) (interface{}, error) {
+ key, err := Unquote(raw)
+ if err != nil {
+ return nil, err
+ }
+ return ParseF64(key)
+}
+
+func decodeJsonNumberKey(dec *mapDecoder, raw string) (interface{}, error) {
+ // skip the quote
+ raw = raw[1:len(raw)-1]
+ end, ok := SkipNumberFast(raw, 0)
+
+ // check trailing chars
+ if !ok || end != len(raw) {
+ return nil, error_value(raw, rt.JsonNumberType.Pack())
+ }
+
+ return json.Number(raw[0:end]), nil
}
type mapDecoder struct {
@@ -389,8 +416,8 @@ func (d *mapDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error {
}
obj, ok := node.AsObj()
- if !ok {
- return error_mismatch(node, ctx, d.mapType.Pack())
+ if !ok || d.keyDec == nil {
+ return error_mismatch(node, ctx, d.mapType.Pack())
}
// allocate map
@@ -404,7 +431,8 @@ func (d *mapDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error {
for i := 0; i < obj.Len(); i++ {
keyn := NewNode(next)
raw := keyn.AsRaw(ctx)
- key, err := d.keyDec(d, raw, ctx)
+
+ key, err := d.keyDec(d, raw)
if err != nil {
if gerr == nil {
gerr = error_mismatch(keyn, ctx, d.mapType.Pack())