summaryrefslogtreecommitdiff
path: root/decode.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 14:29:27 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 14:29:27 -0700
commit8b7c8d2f87f9c4d924d070926fb5ab9860d00c61 (patch)
treeeeba98f83a3dad96e4c0f9e7ef14957edec47a2f /decode.go
parentdb49f2d6001fff8e3e417dc76fe9222ca9cbf862 (diff)
decode: s/stack/structStack/
This should make the next commit less noisy.
Diffstat (limited to 'decode.go')
-rw-r--r--decode.go74
1 files changed, 37 insertions, 37 deletions
diff --git a/decode.go b/decode.go
index f351037..3c51c4b 100644
--- a/decode.go
+++ b/decode.go
@@ -90,8 +90,8 @@ type Decoder struct {
useNumber bool
// state
- err error
- stack []decodeStackItem
+ err error
+ structStack []decodeStackItem
}
const maxNestingDepth = 10000
@@ -150,40 +150,40 @@ func (dec *Decoder) More() bool {
return e == nil && t != internal.RuneTypeEOF
}
-func (dec *Decoder) stackPush(par reflect.Type, idx any) {
- dec.stack = append(dec.stack, decodeStackItem{par, idx})
+func (dec *Decoder) structStackPush(par reflect.Type, idx any) {
+ dec.structStack = append(dec.structStack, decodeStackItem{par, idx})
}
-func (dec *Decoder) stackPop() {
- dec.stack = dec.stack[:len(dec.stack)-1]
+func (dec *Decoder) structStackPop() {
+ dec.structStack = dec.structStack[:len(dec.structStack)-1]
}
-func (dec *Decoder) stackStr() string {
+func (dec *Decoder) structStackStr() string {
var buf strings.Builder
buf.WriteString("v")
- for _, item := range dec.stack {
+ for _, item := range dec.structStack {
fmt.Fprintf(&buf, "[%#v]", item.idx)
}
return buf.String()
}
-func (dec *Decoder) stackParent() string {
- last := len(dec.stack) - 1
- if last > 0 && dec.stack[last].par.Kind() != reflect.Struct && dec.stack[last-1].par.Kind() == reflect.Struct {
+func (dec *Decoder) structStackParent() string {
+ last := len(dec.structStack) - 1
+ if last > 0 && dec.structStack[last].par.Kind() != reflect.Struct && dec.structStack[last-1].par.Kind() == reflect.Struct {
last--
}
- if last >= 0 && dec.stack[last].par.Kind() == reflect.Struct {
- return dec.stack[last].par.Name()
+ if last >= 0 && dec.structStack[last].par.Kind() == reflect.Struct {
+ return dec.structStack[last].par.Name()
}
return ""
}
-func (dec *Decoder) stackName() string {
- if dec.stackParent() == "" {
+func (dec *Decoder) structStackName() string {
+ if dec.structStackParent() == "" {
return ""
}
var fields []string
- for _, elem := range dec.stack {
+ for _, elem := range dec.structStack {
if elem.par.Kind() == reflect.Struct {
fields = append(fields, elem.idx.(string))
}
@@ -259,9 +259,9 @@ type decodeError DecodeError
func (dec *Decoder) panicType(jTyp string, gTyp reflect.Type, err error) {
panic(decodeError{
- Field: dec.stackStr(),
- FieldParent: dec.stackParent(),
- FieldName: dec.stackName(),
+ Field: dec.structStackStr(),
+ FieldParent: dec.structStackParent(),
+ FieldName: dec.structStackName(),
Err: &DecodeTypeError{
GoType: gTyp,
JSONType: jTyp,
@@ -275,9 +275,9 @@ func (dec *Decoder) readRune() (rune, internal.RuneType) {
c, _, t, e := dec.io.ReadRuneType()
if e != nil {
panic(decodeError{
- Field: dec.stackStr(),
- FieldParent: dec.stackParent(),
- FieldName: dec.stackName(),
+ Field: dec.structStackStr(),
+ FieldParent: dec.structStackParent(),
+ FieldName: dec.structStackName(),
Err: e,
})
}
@@ -320,9 +320,9 @@ func (sc *decRuneTypeScanner) ReadRuneType() (rune, int, internal.RuneType, erro
c, s, t, e := sc.dec.io.ReadRuneType()
if e != nil {
panic(decodeError{
- Field: sc.dec.stackStr(),
- FieldParent: sc.dec.stackParent(),
- FieldName: sc.dec.stackName(),
+ Field: sc.dec.structStackStr(),
+ FieldParent: sc.dec.structStackParent(),
+ FieldName: sc.dec.structStackName(),
Err: e,
})
}
@@ -534,8 +534,8 @@ func (dec *Decoder) decode(val reflect.Value, nullOK bool) {
dec.decodeString(nil, &nameBuf)
}, func() {
name := nameBuf.String()
- dec.stackPush(typ, name)
- defer dec.stackPop()
+ dec.structStackPush(typ, name)
+ defer dec.structStackPop()
idx, ok := index.byName[name]
if !ok {
for oidx := range index.byPos {
@@ -645,8 +645,8 @@ func (dec *Decoder) decode(val reflect.Value, nullOK bool) {
dec.panicType("object", typ, &DecodeArgumentError{Type: nameValTyp})
}
}
- dec.stackPush(typ, nameValPtr.Elem())
- defer dec.stackPop()
+ dec.structStackPush(typ, nameValPtr.Elem())
+ defer dec.structStackPop()
fValPtr := reflect.New(typ.Elem())
dec.decode(fValPtr.Elem(), false)
@@ -699,8 +699,8 @@ func (dec *Decoder) decode(val reflect.Value, nullOK bool) {
}
i := 0
dec.decodeArray(typ, func() {
- dec.stackPush(typ, i)
- defer dec.stackPop()
+ dec.structStackPush(typ, i)
+ defer dec.structStackPop()
mValPtr := reflect.New(typ.Elem())
dec.decode(mValPtr.Elem(), false)
val.Set(reflect.Append(val, mValPtr.Elem()))
@@ -718,8 +718,8 @@ func (dec *Decoder) decode(val reflect.Value, nullOK bool) {
i := 0
n := val.Len()
dec.decodeArray(typ, func() {
- dec.stackPush(typ, i)
- defer dec.stackPop()
+ dec.structStackPush(typ, i)
+ defer dec.structStackPop()
if i < n {
mValPtr := reflect.New(typ.Elem())
dec.decode(mValPtr.Elem(), false)
@@ -780,8 +780,8 @@ func (dec *Decoder) decodeAny() any {
dec.decodeString(nil, &nameBuf)
}, func() {
name := nameBuf.String()
- dec.stackPush(typ, name)
- defer dec.stackPop()
+ dec.structStackPush(typ, name)
+ defer dec.structStackPop()
ret[name] = dec.decodeAny()
})
return ret
@@ -789,8 +789,8 @@ func (dec *Decoder) decodeAny() any {
ret := []any{}
typ := reflect.TypeOf(ret)
dec.decodeArray(typ, func() {
- dec.stackPush(typ, len(ret))
- defer dec.stackPop()
+ dec.structStackPush(typ, len(ret))
+ defer dec.structStackPop()
ret = append(ret, dec.decodeAny())
})
return ret