This commit is contained in:
Masaaki Goshima 2021-03-10 19:27:37 +09:00
parent d0fb2a9a4e
commit 55cfca3b0a
7 changed files with 343 additions and 258 deletions

View File

@ -367,8 +367,18 @@ func appendIndent(ctx *encodeRuntimeContext, b []byte, indent int) []byte {
return append(b, bytes.Repeat(ctx.indentStr, ctx.baseIndent+indent)...)
}
func encodeMarshalJSON(b []byte, v interface{}) ([]byte, error) {
v = reflect.ValueOf(v).Interface() // convert by dynamic interface type
func encodeMarshalJSON(code *opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.addrForMarshaler {
if rv.CanAddr() {
rv = rv.Addr()
} else {
newV := reflect.New(rv.Type())
newV.Elem().Set(rv)
rv = newV
}
}
v = rv.Interface()
marshaler, ok := v.(Marshaler)
if !ok {
return encodeNull(b), nil
@ -385,14 +395,24 @@ func encodeMarshalJSON(b []byte, v interface{}) ([]byte, error) {
}
buf := bytes.NewBuffer(b)
//TODO: we should validate buffer with `compact`
if err := compact(buf, bb, false); err != nil {
if err := compact(buf, bb, escape); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func encodeMarshalJSONIndent(ctx *encodeRuntimeContext, b []byte, v interface{}, indent int) ([]byte, error) {
v = reflect.ValueOf(v).Interface() // convert by dynamic interface type
func encodeMarshalJSONIndent(ctx *encodeRuntimeContext, code *opcode, b []byte, v interface{}, indent int, escape bool) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.addrForMarshaler {
if rv.CanAddr() {
rv = rv.Addr()
} else {
newV := reflect.New(rv.Type())
newV.Elem().Set(rv)
rv = newV
}
}
v = rv.Interface()
marshaler, ok := v.(Marshaler)
if !ok {
return encodeNull(b), nil
@ -408,7 +428,7 @@ func encodeMarshalJSONIndent(ctx *encodeRuntimeContext, b []byte, v interface{},
)
}
var compactBuf bytes.Buffer
if err := compact(&compactBuf, bb, false); err != nil {
if err := compact(&compactBuf, bb, escape); err != nil {
return nil, err
}
var indentBuf bytes.Buffer
@ -423,8 +443,18 @@ func encodeMarshalJSONIndent(ctx *encodeRuntimeContext, b []byte, v interface{},
return append(b, indentBuf.Bytes()...), nil
}
func encodeMarshalText(b []byte, v interface{}) ([]byte, error) {
v = reflect.ValueOf(v).Interface() // convert by dynamic interface type
func encodeMarshalText(code *opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.addrForMarshaler {
if rv.CanAddr() {
rv = rv.Addr()
} else {
newV := reflect.New(rv.Type())
newV.Elem().Set(rv)
rv = newV
}
}
v = rv.Interface()
marshaler, ok := v.(encoding.TextMarshaler)
if !ok {
return encodeNull(b), nil
@ -433,11 +463,24 @@ func encodeMarshalText(b []byte, v interface{}) ([]byte, error) {
if err != nil {
return nil, &MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
if escape {
return encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
}
return encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
}
func encodeMarshalTextIndent(b []byte, v interface{}) ([]byte, error) {
v = reflect.ValueOf(v).Interface() // convert by dynamic interface type
func encodeMarshalTextIndent(code *opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.addrForMarshaler {
if rv.CanAddr() {
rv = rv.Addr()
} else {
newV := reflect.New(rv.Type())
newV.Elem().Set(rv)
rv = newV
}
}
v = rv.Interface()
marshaler, ok := v.(encoding.TextMarshaler)
if !ok {
return encodeNull(b), nil
@ -446,5 +489,8 @@ func encodeMarshalTextIndent(b []byte, v interface{}) ([]byte, error) {
if err != nil {
return nil, &MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
if escape {
return encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
}
return encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
}

View File

@ -810,8 +810,6 @@ func encodeTypeToFieldType(ctx *encodeCompileContext, code *opcode) opType {
case opSlicePtr:
code.op = opSlice
return opStructFieldSlicePtr
case opStructFieldHead:
return opStructFieldStruct
case opMarshalJSON:
return opStructFieldMarshalJSON
case opMarshalJSONPtr:
@ -820,6 +818,8 @@ func encodeTypeToFieldType(ctx *encodeCompileContext, code *opcode) opType {
return opStructFieldMarshalText
case opMarshalTextPtr:
return opStructFieldMarshalTextPtr
case opStructFieldRecursive:
return opStructFieldRecursive
}
return opStructField
}
@ -914,6 +914,7 @@ func encodeStructField(ctx *encodeCompileContext, fieldCode *opcode, valueCode *
fieldCode.ptrNum = valueCode.ptrNum
fieldCode.mask = valueCode.mask
fieldCode.rshiftNum = valueCode.rshiftNum
fieldCode.jmp = valueCode.jmp
switch op {
case opStructField,
opStructFieldSlice,
@ -949,6 +950,12 @@ func encodeIsNotExistsField(head *opcode) bool {
if head == nil {
return false
}
if head.op != opStructFieldHead {
return false
}
if !head.anonymousHead {
return false
}
if head.next == nil {
return false
}
@ -1008,8 +1015,18 @@ func encodeAnonymousStructFieldPairMap(tags structTags, named string, valueCode
removedFields := map[*opcode]struct{}{}
for {
existsKey := tags.existsKey(f.displayKey)
if existsKey && (f.next.op == opStructFieldPtrHeadRecursive || f.next.op == opStructFieldHeadRecursive) {
isHeadOp := strings.Contains(f.op.String(), "Head")
if existsKey && strings.Contains(f.op.String(), "Recursive") {
// through
} else if isHeadOp && !f.anonymousHead {
if existsKey {
// TODO: need to remove this head
f.op = opStructFieldHead
f.anonymousKey = true
f.anonymousHead = true
} else if named == "" {
f.anonymousHead = true
}
} else if named == "" && f.op == opStructEnd {
f.op = opStructAnonymousEnd
} else if existsKey {
@ -1054,7 +1071,7 @@ func encodeAnonymousFieldPairRecursively(named string, valueCode *opcode) map[st
f := valueCode
var prevAnonymousField *opcode
for {
if f.displayKey != "" && strings.Contains(f.op.String(), "Anonymous") {
if f.displayKey != "" && f.anonymousHead {
key := fmt.Sprintf("%s.%s", named, f.displayKey)
anonymousFields[key] = append(anonymousFields[key], structFieldPair{
prevField: prevAnonymousField,
@ -1092,6 +1109,8 @@ func encodeOptimizeConflictAnonymousFields(anonymousFields map[string][]structFi
if fieldPair.prevField == nil {
// head operation
fieldPair.curField.op = opStructFieldHead
fieldPair.curField.anonymousHead = true
fieldPair.curField.anonymousKey = true
} else {
diff := fieldPair.curField.nextField.displayIdx - fieldPair.curField.displayIdx
for i := 0; i < diff; i++ {
@ -1110,6 +1129,8 @@ func encodeOptimizeConflictAnonymousFields(anonymousFields map[string][]structFi
if fieldPair.prevField == nil {
// head operation
fieldPair.curField.op = opStructFieldHead
fieldPair.curField.anonymousHead = true
fieldPair.curField.anonymousKey = true
} else {
diff := fieldPair.curField.nextField.displayIdx - fieldPair.curField.displayIdx
removedFields[fieldPair.curField] = struct{}{}
@ -1169,8 +1190,8 @@ func encodeCompileStruct(ctx *encodeCompileContext, isPtr bool) (*opcode, error)
ctx.incIndex()
nilcheck := true
var valueCode *opcode
fmt.Println("fieldType.Kind() = ", fieldType.Kind())
isNilValue := fieldType.Kind() == reflect.Ptr || fieldType.Kind() == reflect.Interface
addrForMarshaler := false
if i == 0 && fieldNum == 1 && isPtr && !isNilValue && rtype_ptrTo(fieldType).Implements(marshalJSONType) && !fieldType.Implements(marshalJSONType) {
// *struct{ field T } => struct { field *T }
// func (*T) MarshalJSON() ([]byte, error)
@ -1198,19 +1219,21 @@ func encodeCompileStruct(ctx *encodeCompileContext, isPtr bool) (*opcode, error)
} else if isPtr && !isNilValue && !fieldType.Implements(marshalJSONType) && rtype_ptrTo(fieldType).Implements(marshalJSONType) {
// *struct{ field T }
// func (*T) MarshalJSON() ([]byte, error)
code, err := encodeCompileMarshalJSON(ctx.withType(rtype_ptrTo(fieldType)))
code, err := encodeCompileMarshalJSON(ctx.withType(fieldType))
if err != nil {
return nil, err
}
addrForMarshaler = true
nilcheck = false
valueCode = code
} else if isPtr && !isNilValue && !fieldType.Implements(marshalTextType) && rtype_ptrTo(fieldType).Implements(marshalTextType) {
// *struct{ field T }
// func (*T) MarshalText() ([]byte, error)
code, err := encodeCompileMarshalText(ctx.withType(rtype_ptrTo(fieldType)))
code, err := encodeCompileMarshalText(ctx.withType(fieldType))
if err != nil {
return nil, err
}
addrForMarshaler = true
nilcheck = false
valueCode = code
} else if fieldType.Implements(marshalJSONType) && fieldType.Kind() != reflect.Ptr {
@ -1259,28 +1282,26 @@ func encodeCompileStruct(ctx *encodeCompileContext, isPtr bool) (*opcode, error)
for k, v := range encodeAnonymousStructFieldPairMap(tags, tagKey, valueCode) {
anonymousFields[k] = append(anonymousFields[k], v...)
}
}
if field.Anonymous {
valueCode.anonymousHead = true
valueCode.decIndent()
}
key := fmt.Sprintf(`"%s":`, tag.key)
escapedKey := fmt.Sprintf(`%s:`, string(encodeEscapedString([]byte{}, tag.key)))
valueCode.indirect = indirect
fieldCode := &opcode{
typ: valueCode.typ,
displayIdx: fieldOpcodeIndex,
idx: opcodeOffset(fieldPtrIndex),
next: valueCode,
indent: ctx.indent,
anonymousKey: field.Anonymous,
key: []byte(key),
escapedKey: []byte(escapedKey),
isTaggedKey: tag.isTaggedKey,
displayKey: tag.key,
offset: field.Offset,
indirect: indirect,
nilcheck: nilcheck,
typ: valueCode.typ,
displayIdx: fieldOpcodeIndex,
idx: opcodeOffset(fieldPtrIndex),
next: valueCode,
indent: ctx.indent,
anonymousKey: field.Anonymous,
key: []byte(key),
escapedKey: []byte(escapedKey),
isTaggedKey: tag.isTaggedKey,
displayKey: tag.key,
offset: field.Offset,
indirect: indirect,
nilcheck: nilcheck,
addrForMarshaler: addrForMarshaler,
}
if fieldIdx == 0 {
fieldCode.headIdx = fieldCode.idx

View File

@ -9,22 +9,23 @@ import (
const uintptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
type opcode struct {
op opType // operation type
typ *rtype // go type
displayIdx int // opcode index
key []byte // struct field key
escapedKey []byte // struct field key ( HTML escaped )
ptrNum int // pointer number: e.g. double pointer is 2.
displayKey string // key text to display
isTaggedKey bool // whether tagged key
anonymousKey bool // whether anonymous key
anonymousHead bool // whether anonymous head or not
root bool // whether root
indirect bool // whether indirect or not
nilcheck bool // whether needs to nilcheck or not
rshiftNum uint8 // use to take bit for judging whether negative integer or not
mask uint64 // mask for number
indent int // indent number
op opType // operation type
typ *rtype // go type
displayIdx int // opcode index
key []byte // struct field key
escapedKey []byte // struct field key ( HTML escaped )
ptrNum int // pointer number: e.g. double pointer is 2.
displayKey string // key text to display
isTaggedKey bool // whether tagged key
anonymousKey bool // whether anonymous key
anonymousHead bool // whether anonymous head or not
root bool // whether root
indirect bool // whether indirect or not
nilcheck bool // whether needs to nilcheck or not
addrForMarshaler bool // whether needs to addr for marshaler or not
rshiftNum uint8 // use to take bit for judging whether negative integer or not
mask uint64 // mask for number
indent int // indent number
idx uintptr // offset to access ptr
headIdx uintptr // offset to access slice/struct head
@ -82,30 +83,31 @@ func (c *opcode) copy(codeMap map[uintptr]*opcode) *opcode {
return code
}
copied := &opcode{
op: c.op,
typ: c.typ,
displayIdx: c.displayIdx,
key: c.key,
escapedKey: c.escapedKey,
displayKey: c.displayKey,
ptrNum: c.ptrNum,
mask: c.mask,
rshiftNum: c.rshiftNum,
isTaggedKey: c.isTaggedKey,
anonymousKey: c.anonymousKey,
anonymousHead: c.anonymousHead,
root: c.root,
indirect: c.indirect,
nilcheck: c.nilcheck,
indent: c.indent,
idx: c.idx,
headIdx: c.headIdx,
elemIdx: c.elemIdx,
length: c.length,
mapIter: c.mapIter,
mapPos: c.mapPos,
offset: c.offset,
size: c.size,
op: c.op,
typ: c.typ,
displayIdx: c.displayIdx,
key: c.key,
escapedKey: c.escapedKey,
displayKey: c.displayKey,
ptrNum: c.ptrNum,
mask: c.mask,
rshiftNum: c.rshiftNum,
isTaggedKey: c.isTaggedKey,
anonymousKey: c.anonymousKey,
anonymousHead: c.anonymousHead,
root: c.root,
indirect: c.indirect,
nilcheck: c.nilcheck,
addrForMarshaler: c.addrForMarshaler,
indent: c.indent,
idx: c.idx,
headIdx: c.headIdx,
elemIdx: c.elemIdx,
length: c.length,
mapIter: c.mapIter,
mapPos: c.mapPos,
offset: c.offset,
size: c.size,
}
codeMap[addr] = copied
copied.mapKey = c.mapKey.copy(codeMap)

View File

@ -1,12 +1,9 @@
package json
import (
"bytes"
"encoding"
"fmt"
"math"
"reflect"
"runtime"
"sort"
"strconv"
"strings"
@ -75,7 +72,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
ptrOffset := uintptr(0)
ctxptr := ctx.ptr()
code := codeSet.code
//fmt.Println(code.dump())
for {
switch code.op {
@ -191,52 +187,43 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
b = bb
code = code.next
case opMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.next
break
}
v := ptrToInterface(code, ptr)
bb, err := v.(Marshaler).MarshalJSON()
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
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),
0,
)
}
buf := bytes.NewBuffer(b)
//TODO: we should validate buffer with `compact`
if err := compact(buf, bb, false); err != nil {
return nil, err
}
b = buf.Bytes()
b = encodeComma(b)
b = encodeComma(bb)
code = code.next
case opMarshalText:
ptr := load(ctxptr, code.idx)
isPtr := code.typ.Kind() == reflect.Ptr
p := ptrToUnsafePtr(ptr)
if p == nil || isPtr && *(*unsafe.Pointer)(p) == nil {
b = append(b, '"', '"', ',')
} else {
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
typ: code.typ,
ptr: p,
}))
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
}
b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes)))
p := load(ctxptr, code.idx)
if p == 0 {
b = append(b, `""`...)
b = encodeComma(b)
code = code.next
break
}
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
b = encodeComma(bb)
code = code.next
case opSlicePtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
break
}
store(ctxptr, code.idx, ptrToPtr(p))
fallthrough
case opSlice:
p := load(ctxptr, code.idx)
slice := ptrToSlice(p)
@ -244,18 +231,18 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
} else {
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(slice.len))
break
}
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(slice.len))
store(ctxptr, code.idx, uintptr(slice.data))
if slice.len > 0 {
b = append(b, '[')
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
if slice.len > 0 {
b = append(b, '[')
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
} else {
b = append(b, '[', ']', ',')
code = code.end.next
}
} else {
b = append(b, '[', ']', ',')
code = code.end.next
}
case opSliceElem:
idx := load(ctxptr, code.elemIdx)
@ -305,35 +292,45 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
b = encodeComma(b)
code = code.end.next
}
case opMap:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
case opMapPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
} else {
uptr := ptrToUnsafePtr(ptr)
mlen := maplen(uptr)
if mlen > 0 {
b = append(b, '{')
iter := mapiterinit(code.typ, uptr)
ctx.keepRefs = append(ctx.keepRefs, iter)
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
if (opt & EncodeOptionUnorderedMap) == 0 {
mapCtx := newMapContext(mlen)
mapCtx.pos = append(mapCtx.pos, len(b))
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(mapCtx))
store(ctxptr, code.end.mapPos, uintptr(unsafe.Pointer(mapCtx)))
}
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
b = append(b, '{', '}', ',')
code = code.end.next
break
}
store(ctxptr, code.idx, ptrToPtr(p))
fallthrough
case opMap:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
break
}
uptr := ptrToUnsafePtr(p)
mlen := maplen(uptr)
if mlen > 0 {
b = append(b, '{')
iter := mapiterinit(code.typ, uptr)
ctx.keepRefs = append(ctx.keepRefs, iter)
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
if (opt & EncodeOptionUnorderedMap) == 0 {
mapCtx := newMapContext(mlen)
mapCtx.pos = append(mapCtx.pos, len(b))
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(mapCtx))
store(ctxptr, code.end.mapPos, uintptr(unsafe.Pointer(mapCtx)))
}
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
b = append(b, '{', '}', ',')
code = code.end.next
}
case opMapKey:
idx := load(ctxptr, code.elemIdx)
@ -2174,7 +2171,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2218,7 +2215,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2262,7 +2259,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
code = code.nextField
} else {
b = append(b, code.key...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2302,7 +2299,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2342,7 +2339,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
code = code.nextField
} else {
b = append(b, code.key...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2386,7 +2383,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2430,7 +2427,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2474,7 +2471,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
code = code.nextField
} else {
b = append(b, code.key...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2514,7 +2511,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2554,7 +2551,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
code = code.nextField
} else {
b = append(b, code.key...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3008,7 +3005,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3027,7 +3024,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
break
}
b = append(b, code.key...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3040,7 +3037,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3053,7 +3050,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
p = ptrToPtr(p + code.offset)
if p != 0 {
b = append(b, code.key...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3070,7 +3067,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3089,7 +3086,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
break
}
b = append(b, code.key...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3102,7 +3099,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3115,7 +3112,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
p = ptrToPtr(p + code.offset)
if p != 0 {
b = append(b, code.key...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}

View File

@ -14,7 +14,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
ptrOffset := uintptr(0)
ctxptr := ctx.ptr()
code := codeSet.code
fmt.Println(code.dump())
//fmt.Println(code.dump())
for {
switch code.op {
@ -157,7 +157,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
code = code.next
break
}
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -180,12 +180,22 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
code = code.next
break
}
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
b = encodeComma(bb)
code = code.next
case opSlicePtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
break
}
store(ctxptr, code.idx, ptrToPtr(p))
fallthrough
case opSlice:
p := load(ctxptr, code.idx)
slice := ptrToSlice(p)
@ -193,18 +203,18 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
} else {
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(slice.len))
break
}
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(slice.len))
store(ctxptr, code.idx, uintptr(slice.data))
if slice.len > 0 {
b = append(b, '[')
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
if slice.len > 0 {
b = append(b, '[')
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
} else {
b = append(b, '[', ']', ',')
code = code.end.next
}
} else {
b = append(b, '[', ']', ',')
code = code.end.next
}
case opSliceElem:
idx := load(ctxptr, code.elemIdx)
@ -254,35 +264,45 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
b = encodeComma(b)
code = code.end.next
}
case opMap:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
case opMapPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
} else {
uptr := ptrToUnsafePtr(ptr)
mlen := maplen(uptr)
if mlen > 0 {
b = append(b, '{')
iter := mapiterinit(code.typ, uptr)
ctx.keepRefs = append(ctx.keepRefs, iter)
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
if (opt & EncodeOptionUnorderedMap) == 0 {
mapCtx := newMapContext(mlen)
mapCtx.pos = append(mapCtx.pos, len(b))
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(mapCtx))
store(ctxptr, code.end.mapPos, uintptr(unsafe.Pointer(mapCtx)))
}
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
b = append(b, '{', '}', ',')
code = code.end.next
break
}
store(ctxptr, code.idx, ptrToPtr(p))
fallthrough
case opMap:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.end.next
break
}
uptr := ptrToUnsafePtr(p)
mlen := maplen(uptr)
if mlen > 0 {
b = append(b, '{')
iter := mapiterinit(code.typ, uptr)
ctx.keepRefs = append(ctx.keepRefs, iter)
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
if (opt & EncodeOptionUnorderedMap) == 0 {
mapCtx := newMapContext(mlen)
mapCtx.pos = append(mapCtx.pos, len(b))
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(mapCtx))
store(ctxptr, code.end.mapPos, uintptr(unsafe.Pointer(mapCtx)))
}
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
b = append(b, '{', '}', ',')
code = code.end.next
}
case opMapKey:
idx := load(ctxptr, code.elemIdx)
@ -2137,7 +2157,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2181,7 +2201,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2225,7 +2245,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
code = code.nextField
} else {
b = append(b, code.escapedKey...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2265,7 +2285,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2305,7 +2325,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
code = code.nextField
} else {
b = append(b, code.escapedKey...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2349,7 +2369,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2393,7 +2413,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2437,7 +2457,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
code = code.nextField
} else {
b = append(b, code.escapedKey...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2477,7 +2497,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2517,7 +2537,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
code = code.nextField
} else {
b = append(b, code.escapedKey...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2971,7 +2991,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2990,7 +3010,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
break
}
b = append(b, code.escapedKey...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3003,7 +3023,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3016,7 +3036,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
p = ptrToPtr(p + code.offset)
if p != 0 {
b = append(b, code.escapedKey...)
bb, err := encodeMarshalJSON(b, ptrToInterface(code, p))
bb, err := encodeMarshalJSON(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3033,7 +3053,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3052,7 +3072,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
break
}
b = append(b, code.escapedKey...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3065,7 +3085,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3078,7 +3098,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
p = ptrToPtr(p + code.offset)
if p != 0 {
b = append(b, code.escapedKey...)
bb, err := encodeMarshalText(b, ptrToInterface(code, p))
bb, err := encodeMarshalText(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}

View File

@ -17,7 +17,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
ptrOffset := uintptr(0)
ctxptr := ctx.ptr()
code := codeSet.code
fmt.Println(code.dump())
for {
switch code.op {
@ -2295,7 +2294,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -2341,7 +2340,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -2387,7 +2386,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -2429,7 +2428,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -2471,7 +2470,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -2517,7 +2516,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2563,7 +2562,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2609,7 +2608,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2651,7 +2650,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -2693,7 +2692,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3230,7 +3229,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -3251,7 +3250,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -3266,7 +3265,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -3281,7 +3280,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, true)
if err != nil {
return nil, err
}
@ -3300,7 +3299,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3321,7 +3320,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3336,7 +3335,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}
@ -3351,7 +3350,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = appendIndent(ctx, b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), true)
if err != nil {
return nil, err
}

View File

@ -2295,7 +2295,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -2341,7 +2341,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -2387,7 +2387,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -2429,7 +2429,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -2471,7 +2471,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -2517,7 +2517,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2563,7 +2563,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if code.nilcheck && p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2609,7 +2609,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2651,7 +2651,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -2693,7 +2693,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3230,7 +3230,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -3251,7 +3251,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -3266,7 +3266,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -3281,7 +3281,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalJSONIndent(ctx, b, ptrToInterface(code, p), code.indent)
bb, err := encodeMarshalJSONIndent(ctx, code, b, ptrToInterface(code, p), code.indent, false)
if err != nil {
return nil, err
}
@ -3300,7 +3300,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if p == 0 && code.nilcheck {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3321,7 +3321,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3336,7 +3336,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
if p == 0 {
b = encodeNull(b)
} else {
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}
@ -3351,7 +3351,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = appendIndent(ctx, b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
bb, err := encodeMarshalTextIndent(b, ptrToInterface(code, p))
bb, err := encodeMarshalTextIndent(code, b, ptrToInterface(code, p), false)
if err != nil {
return nil, err
}