objectInterface is like object but returns map[string]interface{}.
()
| 1064 | |
| 1065 | // objectInterface is like object but returns map[string]interface{}. |
| 1066 | func (d *decodeState) objectInterface() map[string]interface{} { |
| 1067 | m := make(map[string]interface{}) |
| 1068 | for { |
| 1069 | // Read opening " of string key or closing }. |
| 1070 | d.scanWhile(scanSkipSpace) |
| 1071 | if d.opcode == scanEndObject { |
| 1072 | // closing } - can only happen on first iteration. |
| 1073 | break |
| 1074 | } |
| 1075 | if d.opcode != scanBeginLiteral { |
| 1076 | panic(phasePanicMsg) |
| 1077 | } |
| 1078 | |
| 1079 | // Read string key. |
| 1080 | start := d.readIndex() |
| 1081 | d.scanWhile(scanContinue) |
| 1082 | item := d.data[start:d.readIndex()] |
| 1083 | key, ok := unquote(item) |
| 1084 | if !ok { |
| 1085 | panic(phasePanicMsg) |
| 1086 | } |
| 1087 | |
| 1088 | // Read : before value. |
| 1089 | if d.opcode == scanSkipSpace { |
| 1090 | d.scanWhile(scanSkipSpace) |
| 1091 | } |
| 1092 | if d.opcode != scanObjectKey { |
| 1093 | panic(phasePanicMsg) |
| 1094 | } |
| 1095 | d.scanWhile(scanSkipSpace) |
| 1096 | |
| 1097 | // Read value. |
| 1098 | m[key] = d.valueInterface() |
| 1099 | |
| 1100 | // Next token must be , or }. |
| 1101 | if d.opcode == scanSkipSpace { |
| 1102 | d.scanWhile(scanSkipSpace) |
| 1103 | } |
| 1104 | if d.opcode == scanEndObject { |
| 1105 | break |
| 1106 | } |
| 1107 | if d.opcode != scanObjectValue { |
| 1108 | panic(phasePanicMsg) |
| 1109 | } |
| 1110 | } |
| 1111 | return m |
| 1112 | } |
| 1113 | |
| 1114 | // literalInterface consumes and returns a literal from d.data[d.off-1:] and |
| 1115 | // it reads the following byte ahead. The first byte of the literal has been |
no test coverage detected