go-json/encode_vm.go

6187 lines
166 KiB
Go
Raw Normal View History

2020-04-29 18:31:50 +03:00
package json
import (
2020-08-18 07:36:36 +03:00
"bytes"
2020-05-08 14:22:57 +03:00
"encoding"
2020-08-19 04:34:11 +03:00
"encoding/base64"
"fmt"
"math"
2020-04-29 18:31:50 +03:00
"reflect"
2020-09-16 08:51:37 +03:00
"sort"
"strconv"
2020-04-29 18:31:50 +03:00
"unsafe"
)
2020-09-01 16:26:26 +03:00
const startDetectingCyclesAfter = 1000
2020-08-30 21:14:37 +03:00
func load(base uintptr, idx uintptr) uintptr {
addr := base + idx
return **(**uintptr)(unsafe.Pointer(&addr))
}
2020-08-30 21:14:37 +03:00
func store(base uintptr, idx uintptr, p uintptr) {
addr := base + idx
**(**uintptr)(unsafe.Pointer(&addr)) = p
}
2020-09-15 14:48:02 +03:00
func errUnsupportedValue(code *opcode, ptr uintptr) *UnsupportedValueError {
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
typ: code.typ,
ptr: *(*unsafe.Pointer)(unsafe.Pointer(&ptr)),
2020-09-15 14:48:02 +03:00
}))
return &UnsupportedValueError{
Value: reflect.ValueOf(v),
Str: fmt.Sprintf("encountered a cycle via %s", code.typ),
}
}
2020-11-17 09:06:05 +03:00
func errUnsupportedFloat(v float64) *UnsupportedValueError {
return &UnsupportedValueError{
Value: reflect.ValueOf(v),
Str: strconv.FormatFloat(v, 'g', -1, 64),
}
}
2020-11-17 09:08:12 +03:00
func errMarshaler(code *opcode, err error) *MarshalerError {
return &MarshalerError{
Type: rtype2type(code.typ),
Err: err,
}
}
func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte, error) {
2020-09-04 07:53:25 +03:00
recursiveLevel := 0
2020-12-20 13:08:20 +03:00
var seenPtr map[uintptr]struct{}
2020-09-03 09:36:11 +03:00
ptrOffset := uintptr(0)
ctxptr := ctx.ptr()
2020-04-29 18:31:50 +03:00
for {
switch code.op {
default:
return nil, fmt.Errorf("failed to handle opcode. doesn't implement %s", code.op)
case opPtr, opPtrIndent:
ptr := load(ctxptr, code.idx)
2020-04-29 18:31:50 +03:00
code = code.next
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-04-29 18:31:50 +03:00
case opInt:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opIntIndent:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opInt8:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt8Indent:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opInt16:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt16Indent:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opInt32:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt32Indent:
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opInt64:
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(load(ctxptr, code.idx)))
b = encodeComma(b)
code = code.next
case opInt64Indent:
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(load(ctxptr, code.idx)))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opUint:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUintIndent:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opUint8:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint8Indent:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opUint16:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint16Indent:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opUint32:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint32Indent:
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opUint64:
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(load(ctxptr, code.idx)))
b = encodeComma(b)
code = code.next
case opUint64Indent:
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(load(ctxptr, code.idx)))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opIntString:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opIntStringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opInt8String:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt8StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opInt16String:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt16StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opInt32String:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt32StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opInt64String:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opInt64StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opUintString:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUintStringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opUint8String:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint8StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opUint16String:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint16StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opUint32String:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint32StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
case opUint64String:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(load(ctxptr, code.idx))))
b = encodeComma(b)
code = code.next
case opUint64StringIndent:
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(load(ctxptr, code.idx))))
b = encodeIndentComma(b)
code = code.next
2020-04-29 18:31:50 +03:00
case opFloat32:
b = encodeFloat32(b, e.ptrToFloat32(load(ctxptr, code.idx)))
b = encodeComma(b)
code = code.next
case opFloat32Indent:
b = encodeFloat32(b, e.ptrToFloat32(load(ctxptr, code.idx)))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opFloat64:
v := e.ptrToFloat64(load(ctxptr, code.idx))
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
b = encodeComma(b)
code = code.next
case opFloat64Indent:
v := e.ptrToFloat64(load(ctxptr, code.idx))
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opString:
b = e.encodeString(b, e.ptrToString(load(ctxptr, code.idx)))
b = encodeComma(b)
code = code.next
case opStringIndent:
b = e.encodeString(b, e.ptrToString(load(ctxptr, code.idx)))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
case opBool:
b = encodeBool(b, e.ptrToBool(load(ctxptr, code.idx)))
b = encodeComma(b)
code = code.next
case opBoolIndent:
b = encodeBool(b, e.ptrToBool(load(ctxptr, code.idx)))
b = encodeIndentComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
case opBytes:
ptr := load(ctxptr, code.idx)
slice := e.ptrToSlice(ptr)
if ptr == 0 || uintptr(slice.data) == 0 {
b = encodeNull(b)
2020-08-21 05:51:33 +03:00
} else {
b = encodeByteSlice(b, e.ptrToBytes(ptr))
2020-08-21 05:51:33 +03:00
}
b = encodeComma(b)
code = code.next
case opBytesIndent:
ptr := load(ctxptr, code.idx)
slice := e.ptrToSlice(ptr)
if ptr == 0 || uintptr(slice.data) == 0 {
b = encodeNull(b)
} else {
b = encodeByteSlice(b, e.ptrToBytes(ptr))
}
b = encodeIndentComma(b)
2020-08-19 04:34:11 +03:00
code = code.next
case opInterface:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.idx)
2020-09-17 15:50:27 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.next
break
}
2020-12-20 13:08:20 +03:00
if seenPtr == nil {
seenPtr = map[uintptr]struct{}{}
}
if _, exists := seenPtr[ptr]; exists {
return nil, errUnsupportedValue(code, ptr)
}
seenPtr[ptr] = struct{}{}
v := e.ptrToInterface(code, ptr)
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v))
rv := reflect.ValueOf(v)
if rv.IsNil() {
b = encodeNull(b)
b = encodeComma(b)
code = code.next
break
}
vv := rv.Interface()
header := (*interfaceHeader)(unsafe.Pointer(&vv))
2020-12-07 04:44:24 +03:00
if header.typ.Kind() == reflect.Ptr {
if rv.Elem().IsNil() {
b = encodeNull(b)
b = encodeComma(b)
2020-12-07 04:44:24 +03:00
code = code.next
break
}
}
2020-12-07 04:44:24 +03:00
c, err := e.compileHead(&encodeCompileContext{
typ: header.typ,
root: code.root,
withIndent: e.enabledIndent,
indent: code.indent,
})
if err != nil {
return nil, err
2020-12-07 04:44:24 +03:00
}
beforeLastCode := c.beforeLastCode()
lastCode := beforeLastCode.next
lastCode.idx = beforeLastCode.idx + uintptrSize
totalLength := uintptr(code.totalLength())
nextTotalLength := uintptr(c.totalLength())
curlen := uintptr(len(ctx.ptrs))
offsetNum := ptrOffset / uintptrSize
oldOffset := ptrOffset
ptrOffset += totalLength * uintptrSize
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.ptrs = append(ctx.ptrs, make([]uintptr, newLen-curlen)...)
}
ctxptr = ctx.ptr() + ptrOffset // assign new ctxptr
store(ctxptr, 0, uintptr(header.ptr))
store(ctxptr, lastCode.idx, oldOffset)
// link lastCode ( opInterfaceEnd ) => code.next
lastCode.op = opInterfaceEnd
lastCode.next = code.next
code = c
recursiveLevel++
case opInterfaceIndent:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
break
}
2020-12-20 13:08:20 +03:00
if seenPtr == nil {
seenPtr = map[uintptr]struct{}{}
}
2020-08-20 19:01:24 +03:00
if _, exists := seenPtr[ptr]; exists {
return nil, errUnsupportedValue(code, ptr)
2020-08-20 17:56:12 +03:00
}
2020-08-20 19:01:24 +03:00
seenPtr[ptr] = struct{}{}
v := e.ptrToInterface(code, ptr)
ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v))
2020-08-12 10:54:15 +03:00
rv := reflect.ValueOf(v)
if rv.IsNil() {
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-12 10:54:15 +03:00
break
}
vv := rv.Interface()
header := (*interfaceHeader)(unsafe.Pointer(&vv))
typ := header.typ
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
2020-08-12 19:21:10 +03:00
var c *opcode
if typ.Kind() == reflect.Map {
2020-08-29 09:11:31 +03:00
code, err := e.compileMap(&encodeCompileContext{
typ: typ,
2020-08-31 15:59:22 +03:00
root: code.root,
2020-08-29 09:11:31 +03:00
withIndent: e.enabledIndent,
2020-08-31 15:59:22 +03:00
indent: code.indent,
2020-08-29 09:11:31 +03:00
}, false)
2020-08-12 19:21:10 +03:00
if err != nil {
return nil, err
2020-08-12 19:21:10 +03:00
}
c = code
} else {
2020-08-29 09:11:31 +03:00
code, err := e.compile(&encodeCompileContext{
typ: typ,
2020-08-31 15:59:22 +03:00
root: code.root,
2020-08-29 09:11:31 +03:00
withIndent: e.enabledIndent,
2020-08-31 15:59:22 +03:00
indent: code.indent,
2020-08-29 09:11:31 +03:00
})
2020-08-12 19:21:10 +03:00
if err != nil {
return nil, err
2020-08-12 19:21:10 +03:00
}
c = code
}
2020-09-03 09:36:11 +03:00
beforeLastCode := c.beforeLastCode()
lastCode := beforeLastCode.next
lastCode.idx = beforeLastCode.idx + uintptrSize
totalLength := uintptr(code.totalLength())
nextTotalLength := uintptr(c.totalLength())
curlen := uintptr(len(ctx.ptrs))
offsetNum := ptrOffset / uintptrSize
oldOffset := ptrOffset
2020-09-03 16:05:46 +03:00
ptrOffset += totalLength * uintptrSize
2020-09-03 09:36:11 +03:00
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.ptrs = append(ctx.ptrs, make([]uintptr, newLen-curlen)...)
}
2020-09-03 09:36:11 +03:00
ctxptr = ctx.ptr() + ptrOffset // assign new ctxptr
2020-09-03 16:05:46 +03:00
store(ctxptr, 0, uintptr(header.ptr))
2020-09-03 09:36:11 +03:00
store(ctxptr, lastCode.idx, oldOffset)
// link lastCode ( opInterfaceEnd ) => code.next
lastCode.op = opInterfaceEnd
lastCode.next = code.next
code = c
recursiveLevel++
case opInterfaceEnd, opInterfaceEndIndent:
2020-09-03 09:36:11 +03:00
recursiveLevel--
// restore ctxptr
offset := load(ctxptr, code.idx)
ctxptr = ctx.ptr() + offset
ptrOffset = offset
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-04 12:39:17 +03:00
case opMarshalJSON:
ptr := load(ctxptr, code.idx)
v := e.ptrToInterface(code, ptr)
bb, err := v.(Marshaler).MarshalJSON()
2020-05-04 12:39:17 +03:00
if err != nil {
return nil, errMarshaler(code, err)
2020-05-04 12:39:17 +03:00
}
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
2020-08-18 07:36:36 +03:00
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-18 07:36:36 +03:00
}
b = append(append(b, buf.Bytes()...), ',')
code = code.next
case opMarshalJSONIndent:
ptr := load(ctxptr, code.idx)
v := e.ptrToInterface(code, ptr)
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
}
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
var buf bytes.Buffer
if err := encodeWithIndent(
&buf,
bb,
string(e.prefix)+string(bytes.Repeat(e.indentStr, code.indent)),
string(e.indentStr),
); err != nil {
return nil, err
}
b = append(b, buf.Bytes()...)
b = encodeIndentComma(b)
2020-05-04 12:39:17 +03:00
code = code.next
case opMarshalText:
ptr := load(ctxptr, code.idx)
2020-08-20 11:47:38 +03:00
isPtr := code.typ.Kind() == reflect.Ptr
p := e.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 = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
}
code = code.next
case opMarshalTextIndent:
ptr := load(ctxptr, code.idx)
isPtr := code.typ.Kind() == reflect.Ptr
p := e.ptrToUnsafePtr(ptr)
if p == nil {
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-21 05:07:55 +03:00
} else if isPtr && *(*unsafe.Pointer)(p) == nil {
b = append(b, '"', '"', ',', '\n')
2020-08-20 11:47:38 +03:00
} else {
if isPtr && code.typ.Elem().Implements(marshalTextType) {
p = *(*unsafe.Pointer)(p)
}
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
typ: code.typ,
ptr: p,
}))
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
2020-05-08 19:38:00 +03:00
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeIndentComma(b)
2020-05-04 12:39:17 +03:00
}
code = code.next
2020-04-29 18:31:50 +03:00
case opSliceHead:
p := load(ctxptr, code.idx)
slice := e.ptrToSlice(p)
if p == 0 || uintptr(slice.data) == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-04-29 18:31:50 +03:00
} else {
2020-08-31 15:59:22 +03:00
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, '[')
2020-04-29 19:44:48 +03:00
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
2020-04-29 19:44:48 +03:00
} else {
b = append(b, '[', ']', ',')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-04-29 19:44:48 +03:00
}
2020-04-29 18:31:50 +03:00
}
case opSliceElem:
2020-08-31 15:59:22 +03:00
idx := load(ctxptr, code.elemIdx)
length := load(ctxptr, code.length)
idx++
if idx < length {
store(ctxptr, code.elemIdx, idx)
data := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
size := code.size
code = code.next
store(ctxptr, code.idx, data+idx*size)
2020-04-29 18:31:50 +03:00
} else {
last := len(b) - 1
b[last] = ']'
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-04-29 18:31:50 +03:00
}
2020-05-02 17:35:41 +03:00
case opSliceHeadIndent:
p := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if p == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
slice := e.ptrToSlice(p)
2020-08-31 15:59:22 +03:00
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, '[', '\n')
b = e.encodeIndent(b, code.indent+1)
2020-05-02 17:35:41 +03:00
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '[', ']', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-12 10:54:15 +03:00
}
}
case opRootSliceHeadIndent:
p := load(ctxptr, code.idx)
2020-08-12 10:54:15 +03:00
if p == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-12 10:54:15 +03:00
} else {
slice := e.ptrToSlice(p)
2020-08-31 15:59:22 +03:00
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, '[', '\n')
b = e.encodeIndent(b, code.indent+1)
2020-08-12 10:54:15 +03:00
code = code.next
store(ctxptr, code.idx, uintptr(slice.data))
2020-08-12 10:54:15 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '[', ']', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
}
}
case opSliceElemIndent:
2020-08-31 15:59:22 +03:00
idx := load(ctxptr, code.elemIdx)
length := load(ctxptr, code.length)
idx++
if idx < length {
b = e.encodeIndent(b, code.indent+1)
2020-08-31 15:59:22 +03:00
store(ctxptr, code.elemIdx, idx)
data := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
size := code.size
code = code.next
store(ctxptr, code.idx, data+idx*size)
2020-05-02 17:35:41 +03:00
} else {
b = b[:len(b)-2]
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, ']', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
}
2020-08-12 10:54:15 +03:00
case opRootSliceElemIndent:
2020-08-31 15:59:22 +03:00
idx := load(ctxptr, code.elemIdx)
length := load(ctxptr, code.length)
idx++
if idx < length {
b = e.encodeIndent(b, code.indent+1)
2020-08-31 15:59:22 +03:00
store(ctxptr, code.elemIdx, idx)
2020-08-12 10:54:15 +03:00
code = code.next
2020-08-31 15:59:22 +03:00
data := load(ctxptr, code.headIdx)
store(ctxptr, code.idx, data+idx*code.size)
2020-08-12 10:54:15 +03:00
} else {
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, ']')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-12 10:54:15 +03:00
}
case opArrayHead:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
2020-08-31 15:59:22 +03:00
if code.length > 0 {
b = append(b, '[')
2020-09-01 16:26:26 +03:00
store(ctxptr, code.elemIdx, 0)
code = code.next
store(ctxptr, code.idx, p)
} else {
b = append(b, '[', ']', ',')
2020-08-31 15:59:22 +03:00
code = code.end.next
}
}
case opArrayElem:
2020-08-31 15:59:22 +03:00
idx := load(ctxptr, code.elemIdx)
idx++
if idx < code.length {
store(ctxptr, code.elemIdx, idx)
p := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
size := code.size
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p+idx*size)
} else {
last := len(b) - 1
b[last] = ']'
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
}
2020-05-02 17:35:41 +03:00
case opArrayHeadIndent:
p := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if p == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
2020-08-31 15:59:22 +03:00
if code.length > 0 {
b = append(b, '[', '\n')
b = e.encodeIndent(b, code.indent+1)
2020-09-01 16:26:26 +03:00
store(ctxptr, code.elemIdx, 0)
2020-05-02 17:35:41 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '[', ']', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
}
}
case opArrayElemIndent:
2020-08-31 15:59:22 +03:00
idx := load(ctxptr, code.elemIdx)
idx++
if idx < code.length {
b = e.encodeIndent(b, code.indent+1)
2020-08-31 15:59:22 +03:00
store(ctxptr, code.elemIdx, idx)
p := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
size := code.size
2020-05-02 17:35:41 +03:00
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p+idx*size)
2020-05-02 17:35:41 +03:00
} else {
b = b[:len(b)-2]
b = append(b, '\n')
b = e.encodeIndent(b, code.indent)
b = append(b, ']', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
}
case opMapHead:
2020-09-16 08:51:37 +03:00
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-16 08:51:37 +03:00
code = code.end.next
} else {
uptr := e.ptrToUnsafePtr(ptr)
mlen := maplen(uptr)
2020-09-16 08:51:37 +03:00
if mlen > 0 {
b = append(b, '{')
iter := mapiterinit(code.typ, uptr)
2020-09-16 08:51:37 +03:00
ctx.keepRefs = append(ctx.keepRefs, iter)
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
if !e.unorderedMap {
pos := make([]int, 0, mlen)
pos = append(pos, len(b))
posPtr := unsafe.Pointer(&pos)
ctx.keepRefs = append(ctx.keepRefs, posPtr)
store(ctxptr, code.end.mapPos, uintptr(posPtr))
}
2020-09-16 08:51:37 +03:00
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
b = append(b, '{', '}', ',')
2020-09-16 08:51:37 +03:00
code = code.end.next
}
}
case opMapHeadLoad:
2020-09-16 08:51:37 +03:00
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-16 08:51:37 +03:00
code = code.end.next
} else {
// load pointer
ptr = e.ptrToPtr(ptr)
uptr := e.ptrToUnsafePtr(ptr)
2020-09-17 15:50:27 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
mlen := maplen(uptr)
2020-09-16 08:51:37 +03:00
if mlen > 0 {
b = append(b, '{')
iter := mapiterinit(code.typ, uptr)
2020-09-16 08:51:37 +03:00
ctx.keepRefs = append(ctx.keepRefs, iter)
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
if !e.unorderedMap {
pos := make([]int, 0, mlen)
pos = append(pos, len(b))
posPtr := unsafe.Pointer(&pos)
ctx.keepRefs = append(ctx.keepRefs, posPtr)
store(ctxptr, code.end.mapPos, uintptr(posPtr))
}
2020-09-16 08:51:37 +03:00
code = code.next
} else {
b = append(b, '{', '}', ',')
2020-09-16 08:51:37 +03:00
code = code.end.next
}
}
case opMapKey:
2020-09-16 08:51:37 +03:00
idx := load(ctxptr, code.elemIdx)
length := load(ctxptr, code.length)
idx++
if e.unorderedMap {
if idx < length {
ptr := load(ctxptr, code.mapIter)
iter := e.ptrToUnsafePtr(ptr)
store(ctxptr, code.elemIdx, idx)
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
last := len(b) - 1
b[last] = '}'
b = encodeComma(b)
code = code.end.next
}
2020-09-16 08:51:37 +03:00
} else {
ptr := load(ctxptr, code.end.mapPos)
posPtr := (*[]int)(*(*unsafe.Pointer)(unsafe.Pointer(&ptr)))
*posPtr = append(*posPtr, len(b))
if idx < length {
ptr := load(ctxptr, code.mapIter)
iter := e.ptrToUnsafePtr(ptr)
store(ctxptr, code.elemIdx, idx)
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
code = code.end
}
}
case opMapValue:
if e.unorderedMap {
last := len(b) - 1
b[last] = ':'
} else {
ptr := load(ctxptr, code.end.mapPos)
posPtr := (*[]int)(*(*unsafe.Pointer)(unsafe.Pointer(&ptr)))
*posPtr = append(*posPtr, len(b))
2020-09-16 08:51:37 +03:00
}
ptr := load(ctxptr, code.mapIter)
iter := e.ptrToUnsafePtr(ptr)
2020-09-16 08:51:37 +03:00
value := mapitervalue(iter)
store(ctxptr, code.next.idx, uintptr(value))
mapiternext(iter)
code = code.next
case opMapEnd:
// this operation only used by sorted map.
2020-09-16 08:51:37 +03:00
length := int(load(ctxptr, code.length))
type mapKV struct {
key string
value string
}
kvs := make([]mapKV, 0, length)
ptr := load(ctxptr, code.mapPos)
posPtr := e.ptrToUnsafePtr(ptr)
2020-09-16 08:51:37 +03:00
pos := *(*[]int)(posPtr)
for i := 0; i < length; i++ {
startKey := pos[i*2]
startValue := pos[i*2+1]
var endValue int
if i+1 < length {
endValue = pos[i*2+2]
} else {
endValue = len(b)
2020-09-16 08:51:37 +03:00
}
kvs = append(kvs, mapKV{
key: string(b[startKey:startValue]),
value: string(b[startValue:endValue]),
2020-09-16 08:51:37 +03:00
})
}
sort.Slice(kvs, func(i, j int) bool {
return kvs[i].key < kvs[j].key
})
buf := b[pos[0]:]
2020-09-16 08:51:37 +03:00
buf = buf[:0]
for _, kv := range kvs {
2020-09-16 08:51:37 +03:00
buf = append(buf, []byte(kv.key)...)
buf[len(buf)-1] = ':'
2020-09-16 08:51:37 +03:00
buf = append(buf, []byte(kv.value)...)
}
buf[len(buf)-1] = '}'
buf = append(buf, ',')
b = b[:pos[0]]
b = append(b, buf...)
2020-09-16 08:51:37 +03:00
code = code.next
case opMapHeadIndent:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
uptr := e.ptrToUnsafePtr(ptr)
mlen := maplen(uptr)
if mlen > 0 {
b = append(b, '{', '\n')
iter := mapiterinit(code.typ, uptr)
2020-09-04 14:28:27 +03:00
ctx.keepRefs = append(ctx.keepRefs, iter)
2020-09-01 16:26:26 +03:00
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
if !e.unorderedMap {
pos := make([]int, 0, mlen)
pos = append(pos, len(b))
posPtr := unsafe.Pointer(&pos)
ctx.keepRefs = append(ctx.keepRefs, posPtr)
store(ctxptr, code.end.mapPos, uintptr(posPtr))
} else {
b = e.encodeIndent(b, code.next.indent)
}
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '}', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
}
}
case opMapHeadLoadIndent:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
// load pointer
ptr = e.ptrToPtr(ptr)
uptr := e.ptrToUnsafePtr(ptr)
if uintptr(uptr) == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
mlen := maplen(uptr)
if mlen > 0 {
b = append(b, '{', '\n')
iter := mapiterinit(code.typ, uptr)
2020-09-04 14:28:27 +03:00
ctx.keepRefs = append(ctx.keepRefs, iter)
2020-09-01 16:26:26 +03:00
store(ctxptr, code.elemIdx, 0)
store(ctxptr, code.length, uintptr(mlen))
store(ctxptr, code.mapIter, uintptr(iter))
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
if !e.unorderedMap {
pos := make([]int, 0, mlen)
pos = append(pos, len(b))
posPtr := unsafe.Pointer(&pos)
ctx.keepRefs = append(ctx.keepRefs, posPtr)
store(ctxptr, code.end.mapPos, uintptr(posPtr))
} else {
b = e.encodeIndent(b, code.next.indent)
}
code = code.next
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '}', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.end.next
}
}
case opMapKeyIndent:
idx := load(ctxptr, code.elemIdx)
length := load(ctxptr, code.length)
idx++
if e.unorderedMap {
if idx < length {
b = e.encodeIndent(b, code.indent)
store(ctxptr, code.elemIdx, idx)
ptr := load(ctxptr, code.mapIter)
iter := e.ptrToUnsafePtr(ptr)
2020-09-16 08:51:37 +03:00
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
last := len(b) - 1
b[last] = '\n'
b = e.encodeIndent(b, code.indent-1)
b = append(b, '}', ',', '\n')
2020-09-16 08:51:37 +03:00
code = code.end.next
}
} else {
ptr := load(ctxptr, code.end.mapPos)
posPtr := (*[]int)(*(*unsafe.Pointer)(unsafe.Pointer(&ptr)))
*posPtr = append(*posPtr, len(b))
if idx < length {
ptr := load(ctxptr, code.mapIter)
iter := e.ptrToUnsafePtr(ptr)
store(ctxptr, code.elemIdx, idx)
key := mapiterkey(iter)
store(ctxptr, code.next.idx, uintptr(key))
code = code.next
} else {
code = code.end
}
2020-09-16 08:51:37 +03:00
}
case opMapValueIndent:
if e.unorderedMap {
b = append(b, ':', ' ')
} else {
ptr := load(ctxptr, code.end.mapPos)
posPtr := (*[]int)(*(*unsafe.Pointer)(unsafe.Pointer(&ptr)))
*posPtr = append(*posPtr, len(b))
2020-09-16 08:51:37 +03:00
}
ptr := load(ctxptr, code.mapIter)
iter := e.ptrToUnsafePtr(ptr)
2020-09-16 08:51:37 +03:00
value := mapitervalue(iter)
store(ctxptr, code.next.idx, uintptr(value))
mapiternext(iter)
code = code.next
case opMapEndIndent:
// this operation only used by sorted map
2020-09-16 08:51:37 +03:00
length := int(load(ctxptr, code.length))
type mapKV struct {
key string
value string
}
kvs := make([]mapKV, 0, length)
ptr := load(ctxptr, code.mapPos)
pos := *(*[]int)(*(*unsafe.Pointer)(unsafe.Pointer(&ptr)))
2020-09-16 08:51:37 +03:00
for i := 0; i < length; i++ {
startKey := pos[i*2]
startValue := pos[i*2+1]
var endValue int
if i+1 < length {
endValue = pos[i*2+2]
} else {
endValue = len(b)
2020-09-16 08:51:37 +03:00
}
kvs = append(kvs, mapKV{
key: string(b[startKey:startValue]),
value: string(b[startValue:endValue]),
2020-09-16 08:51:37 +03:00
})
}
sort.Slice(kvs, func(i, j int) bool {
return kvs[i].key < kvs[j].key
})
buf := b[pos[0]:]
2020-09-16 08:51:37 +03:00
buf = buf[:0]
for _, kv := range kvs {
2020-09-16 08:51:37 +03:00
buf = append(buf, e.prefix...)
buf = append(buf, bytes.Repeat(e.indentStr, code.indent+1)...)
buf = append(buf, []byte(kv.key)...)
buf[len(buf)-2] = ':'
buf[len(buf)-1] = ' '
2020-09-16 08:51:37 +03:00
buf = append(buf, []byte(kv.value)...)
}
buf = buf[:len(buf)-2]
2020-09-16 08:51:37 +03:00
buf = append(buf, '\n')
buf = append(buf, e.prefix...)
buf = append(buf, bytes.Repeat(e.indentStr, code.indent)...)
buf = append(buf, '}', ',', '\n')
b = b[:pos[0]]
b = append(b, buf...)
2020-09-16 08:51:37 +03:00
code = code.next
2020-11-16 15:28:33 +03:00
case opStructFieldPtrAnonymousHeadRecursive:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadRecursive:
fallthrough
2020-08-12 12:42:29 +03:00
case opStructFieldRecursive:
ptr := load(ctxptr, code.idx)
2020-08-31 15:59:22 +03:00
if ptr != 0 {
2020-09-01 16:26:26 +03:00
if recursiveLevel > startDetectingCyclesAfter {
if _, exists := seenPtr[ptr]; exists {
return nil, errUnsupportedValue(code, ptr)
2020-08-31 15:59:22 +03:00
}
2020-08-20 17:56:12 +03:00
}
}
2020-12-20 13:08:20 +03:00
if seenPtr == nil {
seenPtr = map[uintptr]struct{}{}
}
2020-09-01 16:26:26 +03:00
seenPtr[ptr] = struct{}{}
2020-09-04 07:48:21 +03:00
c := code.jmp.code
2020-08-31 15:59:22 +03:00
c.end.next = newEndOp(&encodeCompileContext{})
c.op = c.op.ptrHeadToHead()
2020-09-04 07:48:21 +03:00
beforeLastCode := c.end
lastCode := beforeLastCode.next
lastCode.idx = beforeLastCode.idx + uintptrSize
lastCode.elemIdx = lastCode.idx + uintptrSize
// extend length to alloc slot for elemIdx
totalLength := uintptr(code.totalLength() + 1)
nextTotalLength := uintptr(c.totalLength() + 1)
curlen := uintptr(len(ctx.ptrs))
offsetNum := ptrOffset / uintptrSize
oldOffset := ptrOffset
ptrOffset += totalLength * uintptrSize
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.ptrs = append(ctx.ptrs, make([]uintptr, newLen-curlen)...)
2020-08-12 12:42:29 +03:00
}
2020-09-04 07:48:21 +03:00
ctxptr = ctx.ptr() + ptrOffset // assign new ctxptr
2020-09-15 14:48:16 +03:00
store(ctxptr, c.idx, ptr)
2020-09-04 07:48:21 +03:00
store(ctxptr, lastCode.idx, oldOffset)
store(ctxptr, lastCode.elemIdx, uintptr(unsafe.Pointer(code.next)))
// link lastCode ( opStructFieldRecursiveEnd ) => code.next
lastCode.op = opStructFieldRecursiveEnd
code = c
recursiveLevel++
case opStructFieldRecursiveEnd:
recursiveLevel--
// restore ctxptr
offset := load(ctxptr, code.idx)
ptr := load(ctxptr, code.elemIdx)
code = (*opcode)(e.ptrToUnsafePtr(ptr))
2020-09-04 07:48:21 +03:00
ctxptr = ctx.ptr() + offset
ptrOffset = offset
2020-04-29 19:44:48 +03:00
case opStructFieldPtrHead:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
2020-05-01 07:12:01 +03:00
}
2020-09-17 15:50:27 +03:00
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-29 19:44:48 +03:00
fallthrough
case opStructFieldHead:
ptr := load(ctxptr, code.idx)
2020-04-29 18:31:50 +03:00
if ptr == 0 {
2020-08-22 12:16:06 +03:00
if code.op == opStructFieldPtrHead {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:16:06 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:16:06 +03:00
}
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-04-29 18:31:50 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
if !code.anonymousKey {
b = e.encodeKey(b, code)
2020-08-15 11:41:38 +03:00
}
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
2020-08-31 15:59:22 +03:00
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
2020-04-29 19:44:48 +03:00
}
2020-08-22 06:58:34 +03:00
case opStructFieldAnonymousHead:
ptr := load(ctxptr, code.idx)
2020-08-22 06:58:34 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-22 06:58:34 +03:00
} else {
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, ptr)
2020-08-22 06:58:34 +03:00
}
2020-04-29 19:44:48 +03:00
case opStructFieldPtrHeadInt:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-29 19:44:48 +03:00
fallthrough
case opStructFieldHeadInt:
ptr := load(ctxptr, code.idx)
2020-04-29 19:44:48 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadInt {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-29 19:44:48 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
2020-12-23 07:13:34 +03:00
case opStructFieldHeadIntPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
p = e.ptrToPtr(p)
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadIntNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = e.ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
}
}
b = encodeComma(b)
code = code.next
2020-08-15 11:41:38 +03:00
case opStructFieldPtrAnonymousHeadInt:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadInt:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-29 19:44:48 +03:00
}
2020-04-30 05:56:56 +03:00
case opStructFieldPtrHeadInt8:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadInt8:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadInt8 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadInt8:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadInt8:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadInt16:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadInt16:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadInt16 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadInt16:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadInt16:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadInt32:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadInt32:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadInt32 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadInt32:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadInt32:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadInt64:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadInt64:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadInt64 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadInt64:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadInt64:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadUint:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadUint:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadUint {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadUint:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadUint:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadUint8:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadUint8:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadUint8 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadUint8:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadUint8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadUint16:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadUint16:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadUint16 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadUint16:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadUint16:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadUint32:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadUint32:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadUint32 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadUint32:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadUint32:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadUint64:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadUint64:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadUint64 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadUint64:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadUint64:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadFloat32:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadFloat32:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadFloat32 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadFloat32:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadFloat32:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
case opStructFieldPtrHeadFloat64:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadFloat64:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadFloat64 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = append(b, '{')
b = e.encodeKey(b, code)
b = encodeFloat64(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadFloat64:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadFloat64:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-08-15 11:41:38 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-15 11:41:38 +03:00
}
b = e.encodeKey(b, code)
b = encodeFloat64(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
2020-04-29 19:44:48 +03:00
case opStructFieldPtrHeadString:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-29 19:44:48 +03:00
fallthrough
case opStructFieldHeadString:
ptr := load(ctxptr, code.idx)
2020-04-29 19:44:48 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadString {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-29 19:44:48 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, e.ptrToString(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadString:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadString:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, e.ptrToString(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-29 18:31:50 +03:00
}
2020-04-30 05:56:56 +03:00
case opStructFieldPtrHeadBool:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-04-30 05:56:56 +03:00
fallthrough
case opStructFieldHeadBool:
ptr := load(ctxptr, code.idx)
2020-04-30 05:56:56 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadBool {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-04-30 05:56:56 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = encodeBool(b, e.ptrToBool(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
}
case opStructFieldPtrAnonymousHeadBool:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-15 11:41:38 +03:00
fallthrough
case opStructFieldAnonymousHeadBool:
ptr := load(ctxptr, code.idx)
2020-08-15 11:41:38 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-15 11:41:38 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeBool(b, e.ptrToBool(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-04-30 05:56:56 +03:00
}
2020-08-19 04:34:11 +03:00
case opStructFieldPtrHeadBytes:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
2020-08-19 04:34:11 +03:00
fallthrough
case opStructFieldHeadBytes:
ptr := load(ctxptr, code.idx)
2020-08-19 04:34:11 +03:00
if ptr == 0 {
2020-08-22 12:28:03 +03:00
if code.op == opStructFieldPtrHeadBytes {
b = encodeNull(b)
b = encodeComma(b)
2020-08-22 12:28:03 +03:00
} else {
b = append(b, '{', '}', ',')
2020-08-22 12:28:03 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-19 04:34:11 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
}
case opStructFieldPtrAnonymousHeadBytes:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-19 04:34:11 +03:00
fallthrough
case opStructFieldAnonymousHeadBytes:
ptr := load(ctxptr, code.idx)
2020-08-19 04:34:11 +03:00
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-19 04:34:11 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
}
case opStructFieldPtrHeadArray:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructFieldHeadArray:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.idx) + code.offset
if ptr == 0 {
if code.op == opStructFieldPtrHeadArray {
b = encodeNull(b)
b = encodeComma(b)
} else {
b = append(b, '[', ']', ',')
}
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
if !code.anonymousKey {
b = e.encodeKey(b, code)
}
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, ptr)
}
case opStructFieldPtrAnonymousHeadArray:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadArray:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.idx) + code.offset
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = e.encodeKey(b, code)
store(ctxptr, code.idx, ptr)
2020-08-31 15:59:22 +03:00
code = code.next
}
case opStructFieldPtrHeadSlice:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructFieldHeadSlice:
ptr := load(ctxptr, code.idx)
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
if p == 0 {
if code.op == opStructFieldPtrHeadSlice {
b = encodeNull(b)
b = encodeComma(b)
} else {
b = append(b, '[', ']', ',')
}
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
if !code.anonymousKey {
b = e.encodeKey(b, code)
}
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, p)
}
case opStructFieldPtrAnonymousHeadSlice:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadSlice:
ptr := load(ctxptr, code.idx)
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
if p == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = e.encodeKey(b, code)
store(ctxptr, code.idx, p)
2020-08-31 15:59:22 +03:00
code = code.next
}
case opStructFieldPtrHeadMarshalJSON:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructFieldHeadMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
ptr += code.offset
v := e.ptrToInterface(code, ptr)
2020-08-21 05:51:33 +03:00
rv := reflect.ValueOf(v)
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
b = encodeNull(b)
2020-08-31 15:59:22 +03:00
code = code.end
2020-08-21 05:07:55 +03:00
break
}
bb, err := rv.Interface().(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
}
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
}
b = append(b, buf.Bytes()...)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
case opStructFieldPtrAnonymousHeadMarshalJSON:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = e.encodeKey(b, code)
ptr += code.offset
v := e.ptrToInterface(code, ptr)
2020-08-21 05:51:33 +03:00
rv := reflect.ValueOf(v)
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-21 05:51:33 +03:00
break
}
bb, err := rv.Interface().(Marshaler).MarshalJSON()
if err != nil {
return nil, errMarshaler(code, err)
}
if len(bb) == 0 {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
}
b = append(b, buf.Bytes()...)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
case opStructFieldPtrHeadMarshalText:
2020-09-17 15:50:27 +03:00
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
break
}
store(ctxptr, code.idx, e.ptrToPtr(p))
fallthrough
case opStructFieldHeadMarshalText:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
ptr += code.offset
v := e.ptrToInterface(code, ptr)
2020-08-21 05:51:33 +03:00
rv := reflect.ValueOf(v)
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end
2020-08-21 05:07:55 +03:00
break
}
2020-08-21 05:51:33 +03:00
bytes, err := rv.Interface().(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
case opStructFieldPtrAnonymousHeadMarshalText:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
fallthrough
case opStructFieldAnonymousHeadMarshalText:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
2020-09-17 15:50:27 +03:00
code = code.end.next
} else {
b = e.encodeKey(b, code)
ptr += code.offset
v := e.ptrToInterface(code, ptr)
2020-08-21 05:51:33 +03:00
rv := reflect.ValueOf(v)
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-21 05:51:33 +03:00
break
}
bytes, err := rv.Interface().(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-05-02 17:35:41 +03:00
case opStructFieldHeadIndent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
} else if code.next == code.end {
2020-08-22 18:54:43 +03:00
// not exists fields
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '}', ',', '\n')
2020-09-17 15:50:27 +03:00
code = code.end.next
store(ctxptr, code.idx, ptr)
2020-05-01 07:12:01 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, ptr)
2020-05-01 07:12:01 +03:00
}
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadIntIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadIntIndent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
2020-08-27 15:01:53 +03:00
if code.op == opStructFieldPtrHeadIntIndent {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-27 15:01:53 +03:00
} else {
b = append(b, '{', '}', ',', '\n')
2020-08-27 15:01:53 +03:00
}
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadInt8Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-01 07:12:01 +03:00
fallthrough
2020-05-02 17:35:41 +03:00
case opStructFieldHeadInt8Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = encodeIndentComma(b)
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(ptr)))
b = append(b, ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadInt16Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadInt16Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(ptr)))
b = append(b, ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadInt32Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadInt32Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(ptr)))
b = append(b, ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadInt64Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadInt64Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt64(ptr)))
b = append(b, ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadUintIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadUintIndent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(ptr)))
b = append(b, ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadUint8Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadUint8Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(ptr)))
b = append(b, ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadUint16Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadUint16Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(ptr)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadUint32Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadUint32Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(ptr)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadUint64Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadUint64Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(ptr))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadFloat32Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadFloat32Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeFloat32(b, e.ptrToFloat32(ptr))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadFloat64Indent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadFloat64Indent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
2020-08-15 12:36:02 +03:00
v := e.ptrToFloat64(ptr)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeFloat64(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadStringIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadStringIndent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, e.ptrToString(ptr))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
case opStructFieldPtrHeadBoolIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-05-02 17:35:41 +03:00
fallthrough
case opStructFieldHeadBoolIndent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeBool(b, e.ptrToBool(ptr))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
2020-08-19 04:34:11 +03:00
case opStructFieldPtrHeadBytesIndent:
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
2020-08-19 04:34:11 +03:00
fallthrough
case opStructFieldHeadBytesIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 04:34:11 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-09-17 15:50:27 +03:00
code = code.end.next
2020-08-19 04:34:11 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 04:34:11 +03:00
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(ptr))
b = append(b, '"')
b = encodeBytes(b, *(*[]byte)(unsafe.Pointer(&s)))
b = append(b, '"', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
}
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadOmitEmpty:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
case opStructFieldHeadOmitEmpty:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
if p == 0 || *(*uintptr)(*(*unsafe.Pointer)(unsafe.Pointer(&p))) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmpty:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
2020-08-15 12:17:48 +03:00
fallthrough
case opStructFieldAnonymousHeadOmitEmpty:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
if p == 0 || *(*uintptr)(*(*unsafe.Pointer)(unsafe.Pointer(&p))) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyInt:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyInt:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToInt(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt8:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt8(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyInt8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyInt8:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToInt8(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt16:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt16(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyInt16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyInt16:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToInt16(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt32:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt32(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyInt32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyInt32:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToInt32(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt64:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt64(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyInt64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyInt64:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToInt64(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyUint:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyUint:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToUint(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint8:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint8(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
2020-08-15 12:17:48 +03:00
}
case opStructFieldPtrAnonymousHeadOmitEmptyUint8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyUint8:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToUint8(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint16:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint16(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyUint16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyUint16:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToUint16(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint32:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint32(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyUint32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyUint32:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToUint32(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint64:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint64(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyUint64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyUint64:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToUint64(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyFloat32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyFloat32:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat32(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeFloat32(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyFloat32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 12:17:48 +03:00
case opStructFieldAnonymousHeadOmitEmptyFloat32:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat32(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeFloat32(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyFloat64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyFloat64:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = e.encodeKey(b, code)
b = encodeFloat64(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 12:17:48 +03:00
case opStructFieldPtrAnonymousHeadOmitEmptyFloat64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyFloat64:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-15 12:17:48 +03:00
}
b = e.encodeKey(b, code)
b = encodeFloat64(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyString:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyString:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToString(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if v == "" {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
2020-08-15 12:17:48 +03:00
}
case opStructFieldPtrAnonymousHeadOmitEmptyString:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyString:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToString(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if v == "" {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyBool:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyBool:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToBool(ptr + code.offset)
2020-05-02 17:35:41 +03:00
if !v {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeBool(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-02 17:35:41 +03:00
}
2020-08-15 12:17:48 +03:00
}
case opStructFieldPtrAnonymousHeadOmitEmptyBool:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-15 12:17:48 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyBool:
ptr := load(ctxptr, code.idx)
2020-08-15 12:17:48 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-15 12:17:48 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToBool(ptr + code.offset)
2020-08-15 12:17:48 +03:00
if !v {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-15 12:17:48 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeBool(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-15 12:17:48 +03:00
}
2020-05-02 17:35:41 +03:00
}
2020-08-19 04:34:11 +03:00
case opStructFieldPtrHeadOmitEmptyBytes:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 04:34:11 +03:00
}
fallthrough
case opStructFieldHeadOmitEmptyBytes:
ptr := load(ctxptr, code.idx)
2020-08-19 04:34:11 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 04:34:11 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToBytes(ptr + code.offset)
2020-08-19 04:34:11 +03:00
if len(v) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 04:34:11 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeByteSlice(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
}
}
case opStructFieldPtrAnonymousHeadOmitEmptyBytes:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 04:34:11 +03:00
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyBytes:
ptr := load(ctxptr, code.idx)
2020-08-19 04:34:11 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 04:34:11 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToBytes(ptr + code.offset)
2020-08-19 04:34:11 +03:00
if len(v) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 04:34:11 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeByteSlice(b, v)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
}
}
case opStructFieldPtrHeadOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
}
fallthrough
case opStructFieldHeadOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
b = append(b, '{')
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
isPtr := code.typ.Kind() == reflect.Ptr
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, &MarshalerError{
Type: rtype2type(code.typ),
Err: err,
}
}
if len(bb) == 0 {
if isPtr {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
}
b = e.encodeKey(b, code)
b = append(b, buf.Bytes()...)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
}
}
case opStructFieldPtrAnonymousHeadOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
isPtr := code.typ.Kind() == reflect.Ptr
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bb, err := v.(Marshaler).MarshalJSON()
if err != nil {
return nil, &MarshalerError{
Type: rtype2type(code.typ),
Err: err,
}
}
if len(bb) == 0 {
if isPtr {
return nil, errUnexpectedEndOfJSON(
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
}
b = e.encodeKey(b, code)
b = append(b, buf.Bytes()...)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
}
}
case opStructFieldPtrHeadOmitEmptyMarshalText:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
}
fallthrough
case opStructFieldHeadOmitEmptyMarshalText:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
b = append(b, '{')
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
isPtr := code.typ.Kind() == reflect.Ptr
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, &MarshalerError{
Type: rtype2type(code.typ),
Err: err,
}
}
b = e.encodeKey(b, code)
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
}
case opStructFieldPtrAnonymousHeadOmitEmptyMarshalText:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
}
fallthrough
case opStructFieldAnonymousHeadOmitEmptyMarshalText:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
} else {
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
isPtr := code.typ.Kind() == reflect.Ptr
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, &MarshalerError{
Type: rtype2type(code.typ),
Err: err,
}
}
b = e.encodeKey(b, code)
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
}
}
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadOmitEmptyIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
case opStructFieldHeadOmitEmptyIndent:
ptr := load(ctxptr, code.idx)
2020-05-02 17:35:41 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
if p == 0 || *(*uintptr)(*(*unsafe.Pointer)(unsafe.Pointer(&p))) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-02 17:35:41 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-05-02 17:35:41 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyIntIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-02 17:35:41 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyIntIndent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt8Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt8Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt8(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt16Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt16Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt16(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt32Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt32Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt32(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyInt64Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyInt64Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToInt64(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUintIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUintIndent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint8Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint8Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint8(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint16Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint16Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint16(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint32Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint32Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint32(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyUint64Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyUint64Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToUint64(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyFloat32Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyFloat32Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat32(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeFloat32(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyFloat64Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyFloat64Indent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeFloat64(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyStringIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyStringIndent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToString(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if v == "" {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-15 11:41:38 +03:00
case opStructFieldPtrHeadOmitEmptyBoolIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-05-01 07:12:01 +03:00
}
fallthrough
2020-08-15 11:41:38 +03:00
case opStructFieldHeadOmitEmptyBoolIndent:
ptr := load(ctxptr, code.idx)
2020-05-01 07:12:01 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToBool(ptr + code.offset)
2020-05-01 07:12:01 +03:00
if !v {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-05-01 07:12:01 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeBool(b, v)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-05-01 07:12:01 +03:00
}
}
2020-08-19 04:34:11 +03:00
case opStructFieldPtrHeadOmitEmptyBytesIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 04:34:11 +03:00
}
fallthrough
case opStructFieldHeadOmitEmptyBytesIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 04:34:11 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 04:34:11 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToBytes(ptr + code.offset)
2020-08-19 04:34:11 +03:00
if len(v) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 04:34:11 +03:00
} else {
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 04:34:11 +03:00
s := base64.StdEncoding.EncodeToString(v)
b = append(b, '"')
b = encodeBytes(b, *(*[]byte)(unsafe.Pointer(&s)))
b = append(b, '"')
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 04:34:11 +03:00
}
}
2020-08-19 13:56:02 +03:00
case opStructFieldPtrHeadStringTag:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTag:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTag:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTag:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, ptr+code.offset)
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagInt:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagInt:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt8:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagInt8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagInt8:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt16:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagInt16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagInt16:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt32:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagInt32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagInt32:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt64:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagInt64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagInt64:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagUint:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagUint:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint8:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagUint8:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagUint8:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint16:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagUint16:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagUint16:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint32:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagUint32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagUint32:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint64:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagUint64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagUint64:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagFloat32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagFloat32:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToFloat32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagFloat32:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagFloat32:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToFloat32(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagFloat64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagFloat64:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-19 13:56:02 +03:00
}
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagFloat64:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagFloat64:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-19 13:56:02 +03:00
}
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(v))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagString:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagString:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
2020-09-16 19:26:39 +03:00
var buf bytes.Buffer
enc := NewEncoder(&buf)
s := e.ptrToString(ptr + code.offset)
if e.enabledHTMLEscape {
enc.buf = encodeEscapedString(enc.buf, s)
2020-09-16 19:26:39 +03:00
} else {
enc.buf = encodeNoEscapedString(enc.buf, s)
2020-09-16 19:26:39 +03:00
}
b = e.encodeString(b, string(enc.buf))
b = encodeComma(b)
2020-09-16 19:26:39 +03:00
enc.release()
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagString:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagString:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, strconv.Quote(e.ptrToString(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagBool:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagBool:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToBool(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagBool:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagBool:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToBool(ptr+code.offset)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagBytes:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagBytes:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
b = e.encodeKey(b, code)
b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagBytes:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagBytes:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagMarshalJSON:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
2020-08-19 13:56:02 +03:00
isPtr := code.typ.Kind() == reflect.Ptr
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, &MarshalerError{
2020-08-19 13:56:02 +03:00
Type: rtype2type(code.typ),
Err: err,
}
}
if len(bb) == 0 {
2020-08-19 13:56:02 +03:00
if isPtr {
return nil, errUnexpectedEndOfJSON(
2020-08-19 13:56:02 +03:00
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
b = e.encodeKey(b, code)
b = append(b, '"', '"')
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 13:56:02 +03:00
} else {
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-19 13:56:02 +03:00
}
b = e.encodeString(b, buf.String())
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
}
case opStructFieldPtrAnonymousHeadStringTagMarshalJSON:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagMarshalJSON:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
2020-08-19 13:56:02 +03:00
isPtr := code.typ.Kind() == reflect.Ptr
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, &MarshalerError{
2020-08-19 13:56:02 +03:00
Type: rtype2type(code.typ),
Err: err,
}
}
if len(bb) == 0 {
2020-08-19 13:56:02 +03:00
if isPtr {
return nil, errUnexpectedEndOfJSON(
2020-08-19 13:56:02 +03:00
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
0,
)
}
b = e.encodeKey(b, code)
b = append(b, '"', '"')
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 13:56:02 +03:00
} else {
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-19 13:56:02 +03:00
}
b = e.encodeKey(b, code)
b = e.encodeString(b, buf.String())
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
}
case opStructFieldPtrHeadStringTagMarshalText:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagMarshalText:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{')
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
2020-08-19 13:56:02 +03:00
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, &MarshalerError{
2020-08-19 13:56:02 +03:00
Type: rtype2type(code.typ),
Err: err,
}
}
b = e.encodeKey(b, code)
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrAnonymousHeadStringTagMarshalText:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldAnonymousHeadStringTagMarshalText:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
ptr += code.offset
p := e.ptrToUnsafePtr(ptr)
2020-08-19 13:56:02 +03:00
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
2020-08-19 13:56:02 +03:00
}
b = e.encodeKey(b, code)
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagIntIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagIntIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt8Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt8Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt16Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt16Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt32Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt32Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagInt64Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagInt64Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUintIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUintIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint8Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint8Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint16Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint16Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint32Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint32Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagUint64Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagUint64Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagFloat32Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagFloat32Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToFloat32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagFloat64Indent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagFloat64Indent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-19 13:56:02 +03:00
}
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(v))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagStringIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagStringIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
var buf bytes.Buffer
enc := NewEncoder(&buf)
s := e.ptrToString(ptr + code.offset)
if e.enabledHTMLEscape {
enc.buf = encodeEscapedString(enc.buf, s)
} else {
enc.buf = encodeNoEscapedString(enc.buf, s)
}
b = e.encodeString(b, string(enc.buf))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagBoolIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagBoolIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToBool(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
case opStructFieldPtrHeadStringTagBytesIndent:
ptr := load(ctxptr, code.idx)
if ptr != 0 {
store(ctxptr, code.idx, e.ptrToPtr(ptr))
2020-08-19 13:56:02 +03:00
}
fallthrough
case opStructFieldHeadStringTagBytesIndent:
ptr := load(ctxptr, code.idx)
2020-08-19 13:56:02 +03:00
if ptr == 0 {
b = e.encodeIndent(b, code.indent)
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.end.next
2020-08-19 13:56:02 +03:00
} else {
b = append(b, '{', '\n')
b = e.encodeIndent(b, code.indent+1)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 13:56:02 +03:00
s := base64.StdEncoding.EncodeToString(
2020-08-31 15:59:22 +03:00
e.ptrToBytes(ptr + code.offset),
2020-08-19 13:56:02 +03:00
)
b = append(b, '"')
b = encodeBytes(b, *(*[]byte)(unsafe.Pointer(&s)))
b = append(b, '"')
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
}
2020-04-29 18:31:50 +03:00
case opStructField:
2020-08-31 15:59:22 +03:00
if !code.anonymousKey {
b = e.encodeKey(b, code)
2020-08-22 06:58:34 +03:00
}
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx) + code.offset
2020-04-29 18:31:50 +03:00
code = code.next
2020-08-31 15:59:22 +03:00
store(ctxptr, code.idx, ptr)
2020-12-23 07:13:34 +03:00
case opStructFieldIntPtr:
b = e.encodeKey(b, code)
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, int64(e.ptrToInt(p)))
}
b = encodeComma(b)
code = code.next
case opStructFieldIntNPtr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
2020-12-23 07:13:34 +03:00
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = e.ptrToPtr(p)
}
2020-09-17 15:50:27 +03:00
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldInt:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldInt8Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldInt8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldInt16Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldInt16:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldInt32Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldInt32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldInt64Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(p))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldInt64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(ptr+code.offset))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldUintPtr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldUint:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldUint8Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldUint8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldUint16Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldUint16:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldUint32Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(p)))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldUint32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldUint64Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(p))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldUint64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(ptr+code.offset))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldFloat32Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
b = encodeFloat32(b, e.ptrToFloat32(p))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldFloat32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldFloat64Ptr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
break
}
v := e.ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-09-17 15:50:27 +03:00
}
b = encodeFloat64(b, v)
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldFloat64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-19 13:56:02 +03:00
}
b = encodeFloat64(b, v)
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldStringPtr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
b = e.encodeString(b, e.ptrToString(p))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldString:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, e.ptrToString(ptr+code.offset))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
2020-12-23 07:13:34 +03:00
case opStructFieldBoolPtr:
b = e.encodeKey(b, code)
2020-09-17 15:50:27 +03:00
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
2020-09-17 15:50:27 +03:00
} else {
b = encodeBool(b, e.ptrToBool(p))
2020-09-17 15:50:27 +03:00
}
b = encodeComma(b)
2020-09-17 15:50:27 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldBool:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = encodeBool(b, e.ptrToBool(ptr+code.offset))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldBytes:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldMarshalJSON:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
v := e.ptrToInterface(code, p)
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, errMarshaler(code, err)
2020-08-19 13:56:02 +03:00
}
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-19 13:56:02 +03:00
}
b = append(b, buf.Bytes()...)
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldMarshalText:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
v := e.ptrToInterface(code, p)
2020-08-19 13:56:02 +03:00
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
2020-08-19 13:56:02 +03:00
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldArray:
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
case opStructFieldSlice:
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
case opStructFieldMap:
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
case opStructFieldMapLoad:
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
case opStructFieldStruct:
b = e.encodeKey(b, code)
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
case opStructFieldIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-09-01 16:26:26 +03:00
p := ptr + code.offset
2020-08-19 13:56:02 +03:00
code = code.next
2020-09-01 16:26:26 +03:00
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
case opStructFieldIntIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldInt8Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldInt16Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldInt32Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldInt64Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendInt(b, e.ptrToInt64(ptr+code.offset))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldUintIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldUint8Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldUint16Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldUint32Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldUint64Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
2020-12-20 16:59:23 +03:00
b = appendUint(b, e.ptrToUint64(ptr+code.offset))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldFloat32Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldFloat64Indent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldStringIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeString(b, e.ptrToString(ptr+code.offset))
b = encodeIndentComma(b)
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldBoolIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = encodeBool(b, e.ptrToBool(ptr+code.offset))
b = encodeIndentComma(b)
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldBytesIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(ptr + code.offset))
b = append(b, '"')
b = append(b, *(*[]byte)(unsafe.Pointer(&s))...)
b = append(b, '"')
b = encodeIndentComma(b)
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldMarshalJSONIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, errMarshaler(code, err)
2020-08-19 13:56:02 +03:00
}
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
}
b = append(b, buf.Bytes()...)
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldArrayIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
array := e.ptrToSlice(p)
if p == 0 || uintptr(array.data) == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
case opStructFieldSliceIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
slice := e.ptrToSlice(p)
if p == 0 || uintptr(slice.data) == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
case opStructFieldMapIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
b = encodeNull(b)
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
p = e.ptrToPtr(p)
mlen := maplen(e.ptrToUnsafePtr(p))
if mlen == 0 {
b = append(b, '{', '}', ',', '\n')
mapCode := code.next
2020-08-31 15:59:22 +03:00
code = mapCode.end.next
} else {
code = code.next
}
}
case opStructFieldMapLoadIndent:
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
b = encodeNull(b)
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
p = e.ptrToPtr(p)
mlen := maplen(e.ptrToUnsafePtr(p))
if mlen == 0 {
b = append(b, '{', '}', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
}
case opStructFieldStructIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
if p == 0 {
b = append(b, '{', '}', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
2020-08-31 15:59:22 +03:00
headCode := code.next
if headCode.next == headCode.end {
// not exists fields
b = append(b, '{', '}', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
store(ctxptr, code.idx, p)
}
}
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmpty:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeKey(b, code)
2020-08-19 13:56:02 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
}
case opStructFieldOmitEmptyInt:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyInt8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt8(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
}
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldOmitEmptyInt16:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt16(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyInt32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt32(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeComma(b)
}
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldOmitEmptyInt64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendInt(b, v)
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUint:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
}
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldOmitEmptyUint8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint8(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUint16:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint16(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
code = code.next
case opStructFieldOmitEmptyUint32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint32(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeComma(b)
}
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldOmitEmptyUint64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
2020-12-20 16:59:23 +03:00
b = appendUint(b, v)
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyFloat32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat32(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeKey(b, code)
b = encodeFloat32(b, v)
b = encodeComma(b)
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyFloat64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-19 13:56:02 +03:00
}
b = e.encodeKey(b, code)
b = encodeFloat64(b, v)
b = encodeComma(b)
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyString:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToString(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != "" {
b = e.encodeKey(b, code)
b = e.encodeString(b, v)
b = encodeComma(b)
}
2020-04-30 05:56:56 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyBool:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToBool(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v {
b = e.encodeKey(b, code)
b = encodeBool(b, v)
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
}
2020-08-19 04:34:11 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyBytes:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToBytes(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if len(v) > 0 {
b = e.encodeKey(b, code)
b = encodeByteSlice(b, v)
b = encodeComma(b)
}
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldOmitEmptyMarshalJSON:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
2020-08-19 13:56:02 +03:00
if v != nil {
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, errMarshaler(code, err)
}
2020-08-19 13:56:02 +03:00
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-19 13:56:02 +03:00
}
b = append(b, buf.Bytes()...)
b = encodeComma(b)
}
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyMarshalText:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
2020-08-19 13:56:02 +03:00
if v != nil {
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
case opStructFieldOmitEmptyArray:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
array := e.ptrToSlice(p)
if p == 0 || uintptr(array.data) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
case opStructFieldOmitEmptySlice:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
slice := e.ptrToSlice(p)
if p == 0 || uintptr(slice.data) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
case opStructFieldOmitEmptyMap:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
if mlen == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
}
case opStructFieldOmitEmptyMapLoad:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
if mlen == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
}
}
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
2020-08-19 13:56:02 +03:00
} else {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 13:56:02 +03:00
code = code.next
store(ctxptr, code.idx, p)
}
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyIntIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyInt8Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt8(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyInt16Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt16(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyInt32Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt32(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, int64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyInt64Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToInt64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendInt(b, v)
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUintIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUint8Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint8(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUint16Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint16(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUint32Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint32(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, uint64(v))
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyUint64Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToUint64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-12-20 16:59:23 +03:00
b = appendUint(b, v)
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyFloat32Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat32(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeFloat32(b, v)
b = encodeIndentComma(b)
}
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyFloat64Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != 0 {
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-08-19 13:56:02 +03:00
}
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeFloat64(b, v)
b = encodeIndentComma(b)
2020-08-19 04:34:11 +03:00
}
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyStringIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToString(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v != "" {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, v)
b = encodeIndentComma(b)
2020-05-01 07:12:01 +03:00
}
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldOmitEmptyBoolIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToBool(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if v {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = encodeBool(b, v)
b = encodeIndentComma(b)
2020-05-01 07:12:01 +03:00
}
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldOmitEmptyBytesIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToBytes(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if len(v) > 0 {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 13:56:02 +03:00
s := base64.StdEncoding.EncodeToString(v)
b = append(b, '"')
b = append(b, *(*[]byte)(unsafe.Pointer(&s))...)
b = append(b, '"')
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
}
code = code.next
case opStructFieldOmitEmptyArrayIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
array := e.ptrToSlice(p)
if p == 0 || uintptr(array.data) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
code = code.next
}
case opStructFieldOmitEmptySliceIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
slice := e.ptrToSlice(p)
if p == 0 || uintptr(slice.data) == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
code = code.next
}
case opStructFieldOmitEmptyMapIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
if mlen == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
code = code.next
}
}
case opStructFieldOmitEmptyMapLoadIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
if mlen == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
code = code.next
}
}
case opStructFieldOmitEmptyStructIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
if p == 0 {
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
headCode := code.next
if headCode.next == headCode.end {
// not exists fields
b = append(b, '{', '}', ',', '\n')
2020-08-31 15:59:22 +03:00
code = code.nextField
} else {
code = code.next
store(ctxptr, code.idx, p)
}
}
2020-08-19 13:56:02 +03:00
case opStructFieldStringTag:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
b = e.encodeKey(b, code)
2020-08-19 13:56:02 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagInt:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(ptr+code.offset)))
b = encodeComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldStringTagInt8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagInt16:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagInt32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagInt64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint8:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint16:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagFloat32:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToFloat32(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagFloat64:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-05-01 07:12:01 +03:00
}
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(v))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagString:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
var buf bytes.Buffer
enc := NewEncoder(&buf)
enc.buf = enc.encodeString(enc.buf, e.ptrToString(ptr+code.offset))
b = e.encodeString(b, string(enc.buf))
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagBool:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeKey(b, code)
b = e.encodeString(b, fmt.Sprint(e.ptrToBool(ptr+code.offset)))
b = encodeComma(b)
2020-05-01 07:12:01 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagBytes:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToBytes(ptr + code.offset)
b = e.encodeKey(b, code)
b = encodeByteSlice(b, v)
b = encodeComma(b)
2020-08-19 04:34:11 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagMarshalJSON:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, errMarshaler(code, err)
}
2020-08-19 13:56:02 +03:00
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-19 13:56:02 +03:00
}
b = e.encodeString(b, buf.String())
b = encodeComma(b)
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagMarshalText:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
v := e.ptrToInterface(code, p)
2020-08-19 13:56:02 +03:00
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeComma(b)
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 13:56:02 +03:00
code = code.next
store(ctxptr, code.idx, p)
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagIntIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagInt8Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt8(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldStringTagInt16Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt16(ptr+code.offset)))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
code = code.next
case opStructFieldStringTagInt32Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagInt64Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToInt64(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUintIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint8Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint8(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint16Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint16(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint32Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagUint64Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToUint64(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagFloat32Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToFloat32(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagFloat64Indent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
v := e.ptrToFloat64(ptr + code.offset)
2020-08-19 13:56:02 +03:00
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
2020-05-02 17:35:41 +03:00
}
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(v))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagStringIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
var buf bytes.Buffer
enc := NewEncoder(&buf)
enc.buf = enc.encodeString(enc.buf, e.ptrToString(ptr+code.offset))
b = e.encodeString(b, string(enc.buf))
b = encodeIndentComma(b)
2020-08-19 13:56:02 +03:00
enc.release()
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagBoolIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
b = e.encodeString(b, fmt.Sprint(e.ptrToBool(ptr+code.offset)))
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagBytesIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-19 13:56:02 +03:00
s := base64.StdEncoding.EncodeToString(
2020-08-31 15:59:22 +03:00
e.ptrToBytes(ptr + code.offset),
2020-08-19 13:56:02 +03:00
)
b = append(b, '"')
b = append(b, *(*[]byte)(unsafe.Pointer(&s))...)
b = append(b, '"')
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagMarshalJSONIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
v := e.ptrToInterface(code, p)
bb, err := v.(Marshaler).MarshalJSON()
2020-08-19 13:56:02 +03:00
if err != nil {
return nil, errMarshaler(code, err)
2020-05-02 17:35:41 +03:00
}
2020-08-19 13:56:02 +03:00
var buf bytes.Buffer
if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil {
return nil, err
2020-08-19 13:56:02 +03:00
}
b = e.encodeString(b, buf.String())
b = encodeIndentComma(b)
2020-05-02 17:35:41 +03:00
code = code.next
2020-08-19 13:56:02 +03:00
case opStructFieldStringTagMarshalTextIndent:
2020-08-31 15:59:22 +03:00
ptr := load(ctxptr, code.headIdx)
b = e.encodeIndent(b, code.indent)
b = e.encodeKey(b, code)
b = append(b, ' ')
2020-08-31 15:59:22 +03:00
p := ptr + code.offset
v := e.ptrToInterface(code, p)
2020-08-19 13:56:02 +03:00
bytes, err := v.(encoding.TextMarshaler).MarshalText()
if err != nil {
return nil, errMarshaler(code, err)
2020-08-19 04:34:11 +03:00
}
b = e.encodeString(b, *(*string)(unsafe.Pointer(&bytes)))
b = encodeIndentComma(b)
2020-08-19 04:34:11 +03:00
code = code.next
2020-04-29 18:31:50 +03:00
case opStructEnd:
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
} else {
b = append(b, '}')
}
b = encodeComma(b)
2020-04-29 18:31:50 +03:00
code = code.next
2020-08-15 11:41:38 +03:00
case opStructAnonymousEnd:
code = code.next
2020-05-02 17:35:41 +03:00
case opStructEndIndent:
last := len(b) - 1
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)
2020-05-02 17:35:41 +03:00
code = code.next
2020-04-29 18:31:50 +03:00
case opEnd:
goto END
}
}
END:
return b, nil
2020-04-29 18:31:50 +03:00
}
2020-04-30 07:52:24 +03:00
func (e *Encoder) ptrToInt(p uintptr) int { return **(**int)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToInt8(p uintptr) int8 { return **(**int8)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToInt16(p uintptr) int16 { return **(**int16)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToInt32(p uintptr) int32 { return **(**int32)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToInt64(p uintptr) int64 { return **(**int64)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToUint(p uintptr) uint { return **(**uint)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToUint8(p uintptr) uint8 { return **(**uint8)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToUint16(p uintptr) uint16 { return **(**uint16)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToUint32(p uintptr) uint32 { return **(**uint32)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToByte(p uintptr) byte { return **(**byte)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToBytes(p uintptr) []byte { return **(**[]byte)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToString(p uintptr) string { return **(**string)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToSlice(p uintptr) *sliceHeader { return *(**sliceHeader)(unsafe.Pointer(&p)) }
func (e *Encoder) ptrToPtr(p uintptr) uintptr {
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
}
func (e *Encoder) ptrToUnsafePtr(p uintptr) unsafe.Pointer {
return *(*unsafe.Pointer)(unsafe.Pointer(&p))
}
func (e *Encoder) ptrToInterface(code *opcode, p uintptr) interface{} {
return *(*interface{})(unsafe.Pointer(&interfaceHeader{
typ: code.typ,
ptr: *(*unsafe.Pointer)(unsafe.Pointer(&p)),
}))
}