Merge pull request #95 from goccy/feature/fix-unsupport-op

Fix #93
This commit is contained in:
Masaaki Goshima 2021-01-22 22:02:54 +09:00 committed by GitHub
commit 86ae7d931a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1312 additions and 1474 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,12 +29,19 @@ func newStructDecoder(structName, fieldName string, fieldMap map[string]*structF
func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
s.skipWhiteSpace()
if s.char() == nul {
s.read()
switch s.char() {
case 'n':
if err := nullBytes(s); err != nil {
return err
}
return nil
case nul:
s.read()
default:
if s.char() != '{' {
return errNotAtBeginningOfValue(s.totalOffset())
}
}
s.cursor++
if s.char() == '}' {
s.cursor++
@ -92,7 +99,25 @@ func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
buflen := int64(len(buf))
cursor = skipWhiteSpace(buf, cursor)
if buf[cursor] != '{' {
switch buf[cursor] {
case 'n':
buflen := int64(len(buf))
if cursor+3 >= buflen {
return 0, errUnexpectedEndOfJSON("null", cursor)
}
if buf[cursor+1] != 'u' {
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
}
if buf[cursor+2] != 'l' {
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
}
if buf[cursor+3] != 'l' {
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
}
cursor += 4
return cursor, nil
case '{':
default:
return 0, errNotAtBeginningOfValue(cursor)
}
if buflen < 2 {

View File

@ -6,6 +6,7 @@ import (
"fmt"
"math"
"reflect"
"runtime"
"sort"
"strconv"
"unsafe"
@ -278,6 +279,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if err != nil {
return nil, errMarshaler(code, err)
}
runtime.KeepAlive(v)
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
@ -7757,6 +7759,26 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
}
b = encodeComma(b)
code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = append(b, code.key...)
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeComma(b)
code = code.next
case opStructFieldBool:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)
@ -7848,8 +7870,11 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
case opStructFieldOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if code.typ.Kind() == reflect.Ptr && code.typ.Elem().Implements(marshalJSONType) {
p = e.ptrToPtr(p)
}
v := e.ptrToInterface(code, p)
if v != nil {
if v != nil && p != 0 {
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
@ -7914,7 +7939,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p == 0 || uintptr(array.data) == 0 {
code = code.nextField
} else {
b = append(b, code.key...)
code = code.next
store(ctxptr, code.idx, p)
}
case opStructFieldSlice:
b = append(b, code.key...)
@ -7929,7 +7956,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p == 0 || uintptr(slice.data) == 0 {
code = code.nextField
} else {
b = append(b, code.key...)
code = code.next
store(ctxptr, code.idx, p)
}
case opStructFieldMap:
b = append(b, code.key...)
@ -7947,7 +7976,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if mlen == 0 {
code = code.nextField
} else {
b = append(b, code.key...)
code = code.next
store(ctxptr, code.idx, p)
}
}
case opStructFieldMapLoad:
@ -7966,7 +7997,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if mlen == 0 {
code = code.nextField
} else {
b = append(b, code.key...)
code = code.next
store(ctxptr, code.idx, p)
}
}
case opStructFieldStruct:
@ -7998,8 +8031,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt:
ptr := load(ctxptr, code.headIdx)
@ -8026,8 +8067,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(e.ptrToInt(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagIntPtr:
b = append(b, code.key...)
@ -8071,8 +8120,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt8:
ptr := load(ctxptr, code.headIdx)
@ -8099,8 +8156,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(e.ptrToInt8(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt8Ptr:
b = append(b, code.key...)
@ -8144,8 +8209,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt16:
ptr := load(ctxptr, code.headIdx)
@ -8172,8 +8245,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(e.ptrToInt16(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt16Ptr:
b = append(b, code.key...)
@ -8217,8 +8298,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt32:
ptr := load(ctxptr, code.headIdx)
@ -8245,8 +8334,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendInt(b, int64(e.ptrToInt32(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt32Ptr:
b = append(b, code.key...)
@ -8290,8 +8387,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendInt(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt64:
ptr := load(ctxptr, code.headIdx)
@ -8318,8 +8423,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendInt(b, e.ptrToInt64(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt64Ptr:
b = append(b, code.key...)
@ -8363,8 +8476,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint:
ptr := load(ctxptr, code.headIdx)
@ -8391,8 +8512,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(e.ptrToUint(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUintPtr:
b = append(b, code.key...)
@ -8436,8 +8565,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint8:
ptr := load(ctxptr, code.headIdx)
@ -8464,8 +8601,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(e.ptrToUint8(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint8Ptr:
b = append(b, code.key...)
@ -8509,8 +8654,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint16:
ptr := load(ctxptr, code.headIdx)
@ -8537,8 +8690,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(e.ptrToUint16(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint16Ptr:
b = append(b, code.key...)
@ -8582,8 +8743,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint32:
ptr := load(ctxptr, code.headIdx)
@ -8610,8 +8779,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendUint(b, uint64(e.ptrToUint32(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint32Ptr:
b = append(b, code.key...)
@ -8655,8 +8832,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = appendUint(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint64:
ptr := load(ctxptr, code.headIdx)
@ -8683,8 +8868,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = appendUint(b, e.ptrToUint64(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint64Ptr:
b = append(b, code.key...)
@ -8728,8 +8921,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != 0 {
b = append(b, code.key...)
b = encodeFloat32(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat32:
ptr := load(ctxptr, code.headIdx)
@ -8756,8 +8957,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = encodeFloat32(b, e.ptrToFloat32(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat32Ptr:
b = append(b, code.key...)
@ -8808,8 +9017,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
}
b = append(b, code.key...)
b = encodeFloat64(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat64:
ptr := load(ctxptr, code.headIdx)
@ -8850,8 +9067,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat64Ptr:
b = append(b, code.key...)
@ -8903,8 +9128,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v != "" {
b = append(b, code.key...)
b = encodeNoEscapedString(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagString:
ptr := load(ctxptr, code.headIdx)
@ -8930,8 +9163,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if p != 0 {
b = append(b, code.key...)
b = encodeNoEscapedString(b, e.ptrToString(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagStringPtr:
b = append(b, code.key...)
@ -8974,8 +9215,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if v {
b = append(b, code.key...)
b = encodeBool(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagBool:
ptr := load(ctxptr, code.headIdx)
@ -9008,8 +9257,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
if len(v) > 0 {
b = append(b, code.key...)
b = encodeByteSlice(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagBytes:
ptr := load(ctxptr, code.headIdx)
@ -9038,7 +9295,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
if v != nil {
if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) {
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
@ -9049,8 +9306,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
}
b = append(b, code.key...)
b = append(b, buf.Bytes()...)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagMarshalJSON:
ptr := load(ctxptr, code.headIdx)
@ -9091,8 +9356,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
}
b = append(b, code.key...)
b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagMarshalText:
ptr := load(ctxptr, code.headIdx)

View File

@ -6,6 +6,7 @@ import (
"fmt"
"math"
"reflect"
"runtime"
"sort"
"unsafe"
)
@ -240,6 +241,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if err != nil {
return nil, errMarshaler(code, err)
}
runtime.KeepAlive(v)
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
@ -7743,6 +7745,26 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
}
b = encodeComma(b)
code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = append(b, code.escapedKey...)
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeComma(b)
code = code.next
case opStructFieldBool:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)
@ -7818,8 +7840,11 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
case opStructFieldOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if code.typ.Kind() == reflect.Ptr && code.typ.Elem().Implements(marshalJSONType) {
p = e.ptrToPtr(p)
}
v := e.ptrToInterface(code, p)
if v != nil {
if v != nil && p != 0 {
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
@ -7900,7 +7925,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p == 0 || uintptr(array.data) == 0 {
code = code.nextField
} else {
b = append(b, code.escapedKey...)
code = code.next
store(ctxptr, code.idx, p)
}
case opStructFieldSlice:
b = append(b, code.escapedKey...)
@ -7915,7 +7942,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p == 0 || uintptr(slice.data) == 0 {
code = code.nextField
} else {
b = append(b, code.escapedKey...)
code = code.next
store(ctxptr, code.idx, p)
}
case opStructFieldMap:
b = append(b, code.escapedKey...)
@ -7933,7 +7962,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if mlen == 0 {
code = code.nextField
} else {
b = append(b, code.escapedKey...)
code = code.next
store(ctxptr, code.idx, p)
}
}
case opStructFieldMapLoad:
@ -7952,7 +7983,9 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if mlen == 0 {
code = code.nextField
} else {
b = append(b, code.escapedKey...)
code = code.next
store(ctxptr, code.idx, p)
}
}
case opStructFieldStruct:
@ -7984,8 +8017,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt:
ptr := load(ctxptr, code.headIdx)
@ -8012,8 +8053,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(e.ptrToInt(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagIntPtr:
b = append(b, code.escapedKey...)
@ -8057,8 +8106,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt8:
ptr := load(ctxptr, code.headIdx)
@ -8085,8 +8142,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(e.ptrToInt8(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt8Ptr:
b = append(b, code.escapedKey...)
@ -8130,8 +8195,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt16:
ptr := load(ctxptr, code.headIdx)
@ -8158,8 +8231,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(e.ptrToInt16(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt16Ptr:
b = append(b, code.escapedKey...)
@ -8203,8 +8284,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt32:
ptr := load(ctxptr, code.headIdx)
@ -8231,8 +8320,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, int64(e.ptrToInt32(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt32Ptr:
b = append(b, code.escapedKey...)
@ -8276,8 +8373,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt64:
ptr := load(ctxptr, code.headIdx)
@ -8304,8 +8409,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendInt(b, e.ptrToInt64(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagInt64Ptr:
b = append(b, code.escapedKey...)
@ -8349,8 +8462,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint:
ptr := load(ctxptr, code.headIdx)
@ -8377,8 +8498,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(e.ptrToUint(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUintPtr:
b = append(b, code.escapedKey...)
@ -8422,8 +8551,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint8:
ptr := load(ctxptr, code.headIdx)
@ -8450,8 +8587,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(e.ptrToUint8(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint8Ptr:
b = append(b, code.escapedKey...)
@ -8495,8 +8640,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint16:
ptr := load(ctxptr, code.headIdx)
@ -8523,8 +8676,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(e.ptrToUint16(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint16Ptr:
b = append(b, code.escapedKey...)
@ -8568,8 +8729,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(v))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint32:
ptr := load(ctxptr, code.headIdx)
@ -8596,8 +8765,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, uint64(e.ptrToUint32(p)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint32Ptr:
b = append(b, code.escapedKey...)
@ -8641,8 +8818,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint64:
ptr := load(ctxptr, code.headIdx)
@ -8669,8 +8854,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = appendUint(b, e.ptrToUint64(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagUint64Ptr:
b = append(b, code.escapedKey...)
@ -8714,8 +8907,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != 0 {
b = append(b, code.escapedKey...)
b = encodeFloat32(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat32:
ptr := load(ctxptr, code.headIdx)
@ -8742,8 +8943,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = encodeFloat32(b, e.ptrToFloat32(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat32Ptr:
b = append(b, code.escapedKey...)
@ -8794,8 +9003,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
}
b = append(b, code.escapedKey...)
b = encodeFloat64(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat64:
ptr := load(ctxptr, code.headIdx)
@ -8836,8 +9053,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagFloat64Ptr:
b = append(b, code.escapedKey...)
@ -8889,8 +9114,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v != "" {
b = append(b, code.escapedKey...)
b = encodeEscapedString(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagString:
ptr := load(ctxptr, code.headIdx)
@ -8916,8 +9149,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if p != 0 {
b = append(b, code.escapedKey...)
b = encodeEscapedString(b, e.ptrToString(p))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagStringPtr:
b = append(b, code.escapedKey...)
@ -8960,8 +9201,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if v {
b = append(b, code.escapedKey...)
b = encodeBool(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagBool:
ptr := load(ctxptr, code.headIdx)
@ -8994,8 +9243,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
if len(v) > 0 {
b = append(b, code.escapedKey...)
b = encodeByteSlice(b, v)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagBytes:
ptr := load(ctxptr, code.headIdx)
@ -9024,7 +9281,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
if v != nil {
if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) {
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
@ -9035,8 +9292,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
}
b = append(b, code.escapedKey...)
b = append(b, buf.Bytes()...)
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagMarshalJSON:
ptr := load(ctxptr, code.headIdx)
@ -9077,8 +9342,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
}
b = append(b, code.escapedKey...)
b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes)))
}
b = appendStructEnd(b)
} else {
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
b = encodeComma(b)
} else {
b = appendStructEnd(b)
}
}
code = code.next
case opStructEndStringTagMarshalText:
ptr := load(ctxptr, code.headIdx)

View File

@ -6,6 +6,7 @@ import (
"fmt"
"math"
"reflect"
"runtime"
"sort"
"unsafe"
)
@ -253,6 +254,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
if err != nil {
return nil, errMarshaler(code, err)
}
runtime.KeepAlive(v)
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
@ -7550,6 +7552,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s)))
b = encodeIndentComma(b)
code = code.next
case opStructFieldStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, e.ptrToString(p))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeIndentComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldBool:
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
@ -7856,9 +7895,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -7898,9 +7942,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -7941,9 +7990,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -7983,9 +8037,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8026,9 +8085,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8068,9 +8132,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8111,9 +8180,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8153,9 +8227,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8196,9 +8275,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8238,9 +8322,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8281,9 +8370,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8323,9 +8417,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8366,9 +8465,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8408,9 +8512,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8451,9 +8560,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8493,9 +8607,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8536,9 +8655,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8578,9 +8702,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8621,9 +8750,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8663,9 +8797,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8706,9 +8845,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8748,9 +8892,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8798,9 +8947,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8852,9 +9006,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8899,9 +9058,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8941,9 +9105,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8978,8 +9147,22 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
b = append(b, code.escapedKey...)
b = append(b, ' ')
b = encodeBool(b, v)
}
b = e.appendStructEndIndent(b, code.indent-1)
} else {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
}
code = code.next
case opStructEndStringTagBool:
ptr := load(ctxptr, code.headIdx)
@ -9006,8 +9189,22 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
b = append(b, code.escapedKey...)
b = append(b, ' ')
b = encodeByteSlice(b, v)
}
b = e.appendStructEndIndent(b, code.indent-1)
} else {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
}
code = code.next
case opStructEndStringTagBytes:
ptr := load(ctxptr, code.headIdx)

View File

@ -6,6 +6,7 @@ import (
"fmt"
"math"
"reflect"
"runtime"
"sort"
"unsafe"
)
@ -253,6 +254,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
if err != nil {
return nil, errMarshaler(code, err)
}
runtime.KeepAlive(v)
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
@ -7550,6 +7552,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s)))
b = encodeIndentComma(b)
code = code.next
case opStructFieldStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, e.ptrToString(p))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeIndentComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldBool:
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
@ -7856,9 +7895,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -7898,9 +7942,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -7941,9 +7990,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -7983,9 +8037,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8026,9 +8085,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8068,9 +8132,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8111,9 +8180,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8153,9 +8227,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8196,9 +8275,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8238,9 +8322,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8281,9 +8370,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8323,9 +8417,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8366,9 +8465,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8408,9 +8512,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8451,9 +8560,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8493,9 +8607,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8536,9 +8655,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8578,9 +8702,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8621,9 +8750,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8663,9 +8797,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8706,9 +8845,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8748,9 +8892,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8798,9 +8947,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8852,9 +9006,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8899,9 +9058,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8941,9 +9105,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
} else {
last := len(b) - 1
if b[last-1] == '{' {
// doesn't exist any fields
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
@ -8978,8 +9147,22 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
b = append(b, code.key...)
b = append(b, ' ')
b = encodeBool(b, v)
}
b = e.appendStructEndIndent(b, code.indent-1)
} else {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
}
code = code.next
case opStructEndStringTagBool:
ptr := load(ctxptr, code.headIdx)
@ -9006,8 +9189,22 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
b = append(b, code.key...)
b = append(b, ' ')
b = encodeByteSlice(b, v)
}
b = e.appendStructEndIndent(b, code.indent-1)
} else {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, '}')
}
b = encodeIndentComma(b)
}
code = code.next
case opStructEndStringTagBytes:
ptr := load(ctxptr, code.headIdx)