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"
|
2020-08-18 18:32:45 +03:00
|
|
|
"fmt"
|
2020-05-08 19:07:33 +03:00
|
|
|
"math"
|
2020-04-29 18:31:50 +03:00
|
|
|
"reflect"
|
2020-05-08 19:07:33 +03:00
|
|
|
"strconv"
|
2020-04-29 18:31:50 +03:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (e *Encoder) run(code *opcode) error {
|
2020-08-20 19:01:24 +03:00
|
|
|
seenPtr := map[uintptr]struct{}{}
|
2020-04-29 18:31:50 +03:00
|
|
|
for {
|
|
|
|
switch code.op {
|
|
|
|
case opPtr:
|
|
|
|
ptr := code.ptr
|
|
|
|
code = code.next
|
|
|
|
code.ptr = e.ptrToPtr(ptr)
|
|
|
|
case opInt:
|
|
|
|
e.encodeInt(e.ptrToInt(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opInt8:
|
|
|
|
e.encodeInt8(e.ptrToInt8(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opInt16:
|
|
|
|
e.encodeInt16(e.ptrToInt16(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opInt32:
|
|
|
|
e.encodeInt32(e.ptrToInt32(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opInt64:
|
|
|
|
e.encodeInt64(e.ptrToInt64(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opUint:
|
|
|
|
e.encodeUint(e.ptrToUint(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opUint8:
|
|
|
|
e.encodeUint8(e.ptrToUint8(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opUint16:
|
|
|
|
e.encodeUint16(e.ptrToUint16(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opUint32:
|
|
|
|
e.encodeUint32(e.ptrToUint32(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opUint64:
|
|
|
|
e.encodeUint64(e.ptrToUint64(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opFloat32:
|
|
|
|
e.encodeFloat32(e.ptrToFloat32(code.ptr))
|
|
|
|
code = code.next
|
|
|
|
case opFloat64:
|
2020-05-08 19:07:33 +03:00
|
|
|
v := e.ptrToFloat64(code.ptr)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeFloat64(v)
|
2020-04-29 18:31:50 +03:00
|
|
|
code = code.next
|
|
|
|
case opString:
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeString(e.ptrToString(code.ptr))
|
2020-04-29 18:31:50 +03:00
|
|
|
code = code.next
|
|
|
|
case opBool:
|
|
|
|
e.encodeBool(e.ptrToBool(code.ptr))
|
|
|
|
code = code.next
|
2020-08-19 04:34:11 +03:00
|
|
|
case opBytes:
|
2020-08-21 05:51:33 +03:00
|
|
|
ptr := code.ptr
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(ptr))
|
|
|
|
if ptr == 0 || header.Data == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
2020-08-25 11:19:41 +03:00
|
|
|
b := e.ptrToBytes(code.ptr)
|
|
|
|
encodedLen := base64.StdEncoding.EncodedLen(len(b))
|
2020-08-21 05:51:33 +03:00
|
|
|
e.encodeByte('"')
|
2020-08-25 11:19:41 +03:00
|
|
|
buf := make([]byte, encodedLen)
|
|
|
|
base64.StdEncoding.Encode(buf, b)
|
|
|
|
e.encodeBytes(buf)
|
2020-08-21 05:51:33 +03:00
|
|
|
e.encodeByte('"')
|
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
code = code.next
|
2020-04-30 07:39:47 +03:00
|
|
|
case opInterface:
|
2020-08-12 10:54:15 +03:00
|
|
|
ifaceCode := code.toInterfaceCode()
|
|
|
|
ptr := ifaceCode.ptr
|
2020-04-30 07:39:47 +03:00
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
2020-08-12 10:54:15 +03:00
|
|
|
typ: ifaceCode.typ,
|
2020-04-30 07:39:47 +03:00
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
2020-08-20 19:01:24 +03:00
|
|
|
if _, exists := seenPtr[ptr]; exists {
|
2020-08-20 17:56:12 +03:00
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: fmt.Sprintf("encountered a cycle via %s", code.typ),
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 19:01:24 +03:00
|
|
|
seenPtr[ptr] = struct{}{}
|
2020-08-12 10:54:15 +03:00
|
|
|
rv := reflect.ValueOf(v)
|
|
|
|
if rv.IsNil() {
|
|
|
|
e.encodeNull()
|
|
|
|
code = ifaceCode.next
|
|
|
|
break
|
|
|
|
}
|
|
|
|
vv := rv.Interface()
|
2020-04-30 07:39:47 +03:00
|
|
|
header := (*interfaceHeader)(unsafe.Pointer(&vv))
|
|
|
|
typ := header.typ
|
|
|
|
if typ.Kind() == reflect.Ptr {
|
|
|
|
typ = typ.Elem()
|
|
|
|
}
|
2020-08-12 10:54:15 +03:00
|
|
|
e.indent = ifaceCode.indent
|
2020-08-12 19:21:10 +03:00
|
|
|
var c *opcode
|
|
|
|
if typ.Kind() == reflect.Map {
|
|
|
|
code, err := e.compileMap(typ, false, ifaceCode.root, e.enabledIndent)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c = code
|
|
|
|
} else {
|
|
|
|
code, err := e.compile(typ, ifaceCode.root, e.enabledIndent)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c = code
|
2020-04-30 07:39:47 +03:00
|
|
|
}
|
|
|
|
c.ptr = uintptr(header.ptr)
|
|
|
|
c.beforeLastCode().next = code.next
|
|
|
|
code = c
|
2020-05-04 12:39:17 +03:00
|
|
|
case opMarshalJSON:
|
|
|
|
ptr := code.ptr
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
2020-08-18 07:36:36 +03:00
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
2020-05-04 12:39:17 +03:00
|
|
|
if err != nil {
|
2020-05-08 19:38:00 +03:00
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
2020-05-04 12:39:17 +03:00
|
|
|
}
|
2020-08-18 18:32:45 +03:00
|
|
|
if len(b) == 0 {
|
|
|
|
return 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, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(buf.Bytes())
|
2020-05-04 12:39:17 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = ptr
|
|
|
|
case opMarshalText:
|
|
|
|
ptr := code.ptr
|
2020-08-20 11:47:38 +03:00
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
p := unsafe.Pointer(ptr)
|
2020-08-21 05:07:55 +03:00
|
|
|
if p == nil {
|
|
|
|
e.encodeNull()
|
|
|
|
} else if isPtr && *(*unsafe.Pointer)(p) == nil {
|
2020-08-20 11:47:38 +03:00
|
|
|
e.encodeBytes([]byte{'"', '"'})
|
|
|
|
} 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 &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
2020-05-08 19:38:00 +03:00
|
|
|
}
|
2020-08-20 11:47:38 +03:00
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
2020-05-04 12:39:17 +03:00
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
code.ptr = ptr
|
2020-04-29 18:31:50 +03:00
|
|
|
case opSliceHead:
|
|
|
|
p := code.ptr
|
2020-04-29 19:44:48 +03:00
|
|
|
headerCode := code.toSliceHeaderCode()
|
2020-08-21 05:51:33 +03:00
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-04-29 19:44:48 +03:00
|
|
|
code = headerCode.end.next
|
2020-04-29 18:31:50 +03:00
|
|
|
} else {
|
|
|
|
e.encodeByte('[')
|
2020-04-29 19:44:48 +03:00
|
|
|
headerCode.elem.set(header)
|
|
|
|
if header.Len > 0 {
|
|
|
|
code = code.next
|
|
|
|
code.ptr = header.Data
|
|
|
|
} else {
|
|
|
|
e.encodeByte(']')
|
|
|
|
code = headerCode.end.next
|
|
|
|
}
|
2020-04-29 18:31:50 +03:00
|
|
|
}
|
|
|
|
case opSliceElem:
|
|
|
|
c := code.toSliceElemCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeByte(',')
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.data + c.idx*c.size
|
|
|
|
} else {
|
2020-04-29 19:44:48 +03:00
|
|
|
e.encodeByte(']')
|
|
|
|
code = c.end.next
|
2020-04-29 18:31:50 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opSliceHeadIndent:
|
|
|
|
p := code.ptr
|
|
|
|
headerCode := code.toSliceHeaderCode()
|
|
|
|
if p == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = headerCode.end.next
|
|
|
|
} else {
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
headerCode.elem.set(header)
|
|
|
|
if header.Len > 0 {
|
2020-08-12 10:54:15 +03:00
|
|
|
e.encodeBytes([]byte{'[', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = header.Data
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-08-22 18:53:38 +03:00
|
|
|
e.encodeBytes([]byte{'[', ']'})
|
2020-08-12 10:54:15 +03:00
|
|
|
code = headerCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opRootSliceHeadIndent:
|
|
|
|
p := code.ptr
|
|
|
|
headerCode := code.toSliceHeaderCode()
|
|
|
|
if p == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = headerCode.end.next
|
|
|
|
} else {
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
headerCode.elem.set(header)
|
|
|
|
if header.Len > 0 {
|
|
|
|
e.encodeBytes([]byte{'[', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = header.Data
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'[', ']'})
|
2020-05-02 17:35:41 +03:00
|
|
|
code = headerCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opSliceElemIndent:
|
|
|
|
c := code.toSliceElemCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.data + c.idx*c.size
|
|
|
|
} else {
|
|
|
|
e.encodeByte('\n')
|
|
|
|
e.encodeIndent(code.indent)
|
2020-08-22 18:53:38 +03:00
|
|
|
e.encodeByte(']')
|
2020-05-02 17:35:41 +03:00
|
|
|
code = c.end.next
|
|
|
|
}
|
2020-08-12 10:54:15 +03:00
|
|
|
case opRootSliceElemIndent:
|
|
|
|
c := code.toSliceElemCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.data + c.idx*c.size
|
|
|
|
} else {
|
|
|
|
e.encodeByte('\n')
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{']'})
|
|
|
|
code = c.end.next
|
|
|
|
}
|
2020-04-30 07:39:47 +03:00
|
|
|
case opArrayHead:
|
|
|
|
p := code.ptr
|
|
|
|
headerCode := code.toArrayHeaderCode()
|
|
|
|
if p == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-04-30 07:39:47 +03:00
|
|
|
code = headerCode.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('[')
|
|
|
|
if headerCode.len > 0 {
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
|
|
|
headerCode.elem.ptr = p
|
|
|
|
} else {
|
|
|
|
e.encodeByte(']')
|
|
|
|
code = headerCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opArrayElem:
|
|
|
|
c := code.toArrayElemCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeByte(',')
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.idx*c.size
|
|
|
|
} else {
|
|
|
|
e.encodeByte(']')
|
|
|
|
code = c.end.next
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opArrayHeadIndent:
|
|
|
|
p := code.ptr
|
|
|
|
headerCode := code.toArrayHeaderCode()
|
|
|
|
if p == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = headerCode.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'[', '\n'})
|
|
|
|
if headerCode.len > 0 {
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
|
|
|
headerCode.elem.ptr = p
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{']', '\n'})
|
|
|
|
code = headerCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opArrayElemIndent:
|
|
|
|
c := code.toArrayElemCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.idx*c.size
|
|
|
|
} else {
|
|
|
|
e.encodeByte('\n')
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{']', '\n'})
|
|
|
|
code = c.end.next
|
|
|
|
}
|
2020-04-30 07:39:47 +03:00
|
|
|
case opMapHead:
|
|
|
|
ptr := code.ptr
|
|
|
|
mapHeadCode := code.toMapHeadCode()
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-04-30 07:39:47 +03:00
|
|
|
code = mapHeadCode.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
mlen := maplen(unsafe.Pointer(ptr))
|
|
|
|
if mlen > 0 {
|
|
|
|
iter := mapiterinit(code.typ, unsafe.Pointer(ptr))
|
|
|
|
mapHeadCode.key.set(mlen, iter)
|
|
|
|
mapHeadCode.value.set(iter)
|
|
|
|
key := mapiterkey(iter)
|
|
|
|
code.next.ptr = uintptr(key)
|
|
|
|
code = code.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('}')
|
|
|
|
code = mapHeadCode.end.next
|
|
|
|
}
|
|
|
|
}
|
2020-08-08 12:53:01 +03:00
|
|
|
case opMapHeadLoad:
|
|
|
|
ptr := code.ptr
|
|
|
|
mapHeadCode := code.toMapHeadCode()
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = mapHeadCode.end.next
|
|
|
|
} else {
|
|
|
|
// load pointer
|
|
|
|
ptr = uintptr(*(*unsafe.Pointer)(unsafe.Pointer(ptr)))
|
|
|
|
e.encodeByte('{')
|
|
|
|
mlen := maplen(unsafe.Pointer(ptr))
|
|
|
|
if mlen > 0 {
|
|
|
|
iter := mapiterinit(code.typ, unsafe.Pointer(ptr))
|
|
|
|
mapHeadCode.key.set(mlen, iter)
|
|
|
|
mapHeadCode.value.set(iter)
|
|
|
|
key := mapiterkey(iter)
|
|
|
|
code.next.ptr = uintptr(key)
|
|
|
|
code = code.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('}')
|
|
|
|
code = mapHeadCode.end.next
|
|
|
|
}
|
|
|
|
}
|
2020-04-30 07:39:47 +03:00
|
|
|
case opMapKey:
|
|
|
|
c := code.toMapKeyCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeByte(',')
|
|
|
|
key := mapiterkey(c.iter)
|
|
|
|
c.next.ptr = uintptr(key)
|
|
|
|
code = c.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('}')
|
|
|
|
code = c.end.next
|
|
|
|
}
|
|
|
|
case opMapValue:
|
|
|
|
e.encodeByte(':')
|
|
|
|
c := code.toMapValueCode()
|
|
|
|
value := mapitervalue(c.iter)
|
|
|
|
c.next.ptr = uintptr(value)
|
|
|
|
mapiternext(c.iter)
|
|
|
|
code = c.next
|
2020-05-02 17:35:41 +03:00
|
|
|
case opMapHeadIndent:
|
|
|
|
ptr := code.ptr
|
|
|
|
mapHeadCode := code.toMapHeadCode()
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = mapHeadCode.end.next
|
|
|
|
} else {
|
|
|
|
mlen := maplen(unsafe.Pointer(ptr))
|
|
|
|
if mlen > 0 {
|
2020-08-12 10:54:15 +03:00
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
iter := mapiterinit(code.typ, unsafe.Pointer(ptr))
|
|
|
|
mapHeadCode.key.set(mlen, iter)
|
|
|
|
mapHeadCode.value.set(iter)
|
|
|
|
key := mapiterkey(iter)
|
|
|
|
code.next.ptr = uintptr(key)
|
|
|
|
code = code.next
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
} else {
|
2020-08-12 10:54:15 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-08-22 18:53:38 +03:00
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
2020-08-12 10:54:15 +03:00
|
|
|
code = mapHeadCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opMapHeadLoadIndent:
|
|
|
|
ptr := code.ptr
|
|
|
|
mapHeadCode := code.toMapHeadCode()
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = mapHeadCode.end.next
|
|
|
|
} else {
|
|
|
|
// load pointer
|
|
|
|
ptr = uintptr(*(*unsafe.Pointer)(unsafe.Pointer(ptr)))
|
|
|
|
mlen := maplen(unsafe.Pointer(ptr))
|
|
|
|
if mlen > 0 {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
iter := mapiterinit(code.typ, unsafe.Pointer(ptr))
|
|
|
|
mapHeadCode.key.set(mlen, iter)
|
|
|
|
mapHeadCode.value.set(iter)
|
|
|
|
key := mapiterkey(iter)
|
|
|
|
code.next.ptr = uintptr(key)
|
|
|
|
code = code.next
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-08-22 18:53:38 +03:00
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
2020-08-12 10:54:15 +03:00
|
|
|
code = mapHeadCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opRootMapHeadIndent:
|
|
|
|
ptr := code.ptr
|
|
|
|
mapHeadCode := code.toMapHeadCode()
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = mapHeadCode.end.next
|
|
|
|
} else {
|
|
|
|
mlen := maplen(unsafe.Pointer(ptr))
|
|
|
|
if mlen > 0 {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
iter := mapiterinit(code.typ, unsafe.Pointer(ptr))
|
|
|
|
mapHeadCode.key.set(mlen, iter)
|
|
|
|
mapHeadCode.value.set(iter)
|
|
|
|
key := mapiterkey(iter)
|
|
|
|
code.next.ptr = uintptr(key)
|
|
|
|
code = code.next
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
2020-05-02 17:35:41 +03:00
|
|
|
code = mapHeadCode.end.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case opMapKeyIndent:
|
|
|
|
c := code.toMapKeyCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
key := mapiterkey(c.iter)
|
|
|
|
c.next.ptr = uintptr(key)
|
|
|
|
code = c.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('\n')
|
|
|
|
e.encodeIndent(code.indent - 1)
|
2020-08-22 18:53:38 +03:00
|
|
|
e.encodeByte('}')
|
2020-05-02 17:35:41 +03:00
|
|
|
code = c.end.next
|
|
|
|
}
|
2020-08-12 10:54:15 +03:00
|
|
|
case opRootMapKeyIndent:
|
|
|
|
c := code.toMapKeyCode()
|
|
|
|
c.idx++
|
|
|
|
if c.idx < c.len {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
key := mapiterkey(c.iter)
|
|
|
|
c.next.ptr = uintptr(key)
|
|
|
|
code = c.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('\n')
|
|
|
|
e.encodeIndent(code.indent - 1)
|
2020-08-22 18:53:38 +03:00
|
|
|
e.encodeByte('}')
|
2020-08-12 10:54:15 +03:00
|
|
|
code = c.end.next
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opMapValueIndent:
|
|
|
|
e.encodeBytes([]byte{':', ' '})
|
|
|
|
c := code.toMapValueCode()
|
|
|
|
value := mapitervalue(c.iter)
|
|
|
|
c.next.ptr = uintptr(value)
|
|
|
|
mapiternext(c.iter)
|
|
|
|
code = c.next
|
2020-08-12 12:42:29 +03:00
|
|
|
case opStructFieldRecursive:
|
|
|
|
recursive := code.toRecursiveCode()
|
2020-08-20 19:01:24 +03:00
|
|
|
if recursive.seenPtr != 0 && recursive.seenPtr == recursive.ptr {
|
2020-08-20 17:56:12 +03:00
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(recursive.ptr),
|
|
|
|
}))
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: fmt.Sprintf("encountered a cycle via %s", code.typ),
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 19:01:24 +03:00
|
|
|
recursive.seenPtr = recursive.ptr
|
2020-08-13 09:26:35 +03:00
|
|
|
if err := e.run(newRecursiveCode(recursive)); err != nil {
|
2020-08-12 12:42:29 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
code = recursive.next
|
2020-04-29 19:44:48 +03:00
|
|
|
case opStructFieldPtrHead:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
2020-04-29 19:44:48 +03:00
|
|
|
fallthrough
|
|
|
|
case opStructFieldHead:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
2020-04-29 18:31:50 +03:00
|
|
|
if ptr == 0 {
|
2020-08-22 12:16:06 +03:00
|
|
|
if code.op == opStructFieldPtrHead {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
2020-04-29 18:31:50 +03:00
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
2020-08-15 11:41:38 +03:00
|
|
|
if !field.anonymousKey {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
}
|
2020-04-29 19:44:48 +03:00
|
|
|
code = field.next
|
2020-08-25 11:19:19 +03:00
|
|
|
code.ptr = ptr + field.offset
|
2020-08-15 12:36:02 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-29 19:44:48 +03:00
|
|
|
}
|
2020-08-22 06:58:34 +03:00
|
|
|
case opStructFieldAnonymousHead:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
code = field.next
|
|
|
|
code.ptr = ptr
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-04-29 19:44:48 +03:00
|
|
|
case opStructFieldPtrHeadInt:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadInt {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-29 19:44:48 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt(e.ptrToInt(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadInt:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadInt:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:16:06 +03:00
|
|
|
e.encodeInt(e.ptrToInt(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-29 19:44:48 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
case opStructFieldPtrHeadInt8:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadInt8 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt8(e.ptrToInt8(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadInt8:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadInt8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt8(e.ptrToInt8(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadInt16:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadInt16 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt16(e.ptrToInt16(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadInt16:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadInt16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt16(e.ptrToInt16(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadInt32:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadInt32 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt32(e.ptrToInt32(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadInt32:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadInt32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt32(e.ptrToInt32(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadInt64:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadInt64 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt64(e.ptrToInt64(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadInt64:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadInt64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeInt64(e.ptrToInt64(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadUint {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint(e.ptrToUint(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadUint:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadUint:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint(e.ptrToUint(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint8:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadUint8 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint8(e.ptrToUint8(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadUint8:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadUint8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint8(e.ptrToUint8(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint16:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadUint16 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint16(e.ptrToUint16(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadUint16:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadUint16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint16(e.ptrToUint16(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint32:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadUint32 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint32(e.ptrToUint32(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadUint32:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadUint32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint32(e.ptrToUint32(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint64:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadUint64 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint64(e.ptrToUint64(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadUint64:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadUint64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeUint64(e.ptrToUint64(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadFloat32:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadFloat32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadFloat32 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeFloat32(e.ptrToFloat32(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadFloat32:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadFloat32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeFloat32(e.ptrToFloat32(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadFloat64:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadFloat64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadFloat64 {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
2020-08-22 12:28:03 +03:00
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
2020-05-08 19:07:33 +03:00
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-05-08 19:07:33 +03:00
|
|
|
e.encodeFloat64(v)
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadFloat64:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadFloat64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
2020-08-22 12:28:03 +03:00
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
2020-08-15 11:41:38 +03:00
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeFloat64(v)
|
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
2020-04-29 19:44:48 +03:00
|
|
|
case opStructFieldPtrHeadString:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadString:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadString {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-29 19:44:48 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeString(e.ptrToString(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadString:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadString:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeString(e.ptrToString(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-29 19:44:48 +03:00
|
|
|
code = field.next
|
2020-04-29 18:31:50 +03:00
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
case opStructFieldPtrHeadBool:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadBool:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadBool {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeBool(e.ptrToBool(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadBool:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadBool:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
e.encodeBool(e.ptrToBool(ptr + field.offset))
|
2020-08-15 11:41:38 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-04-30 05:56:56 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
case opStructFieldPtrHeadBytes:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadBytes:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-08-22 12:28:03 +03:00
|
|
|
if code.op == opStructFieldPtrHeadBytes {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(ptr + field.offset))
|
2020-08-19 04:34:11 +03:00
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadBytes:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadBytes:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-08-22 12:28:03 +03:00
|
|
|
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(code.ptr + field.offset))
|
2020-08-19 04:34:11 +03:00
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-23 19:50:18 +03:00
|
|
|
case opStructFieldPtrHeadArray:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadArray:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
if ptr == 0 {
|
|
|
|
if code.op == opStructFieldPtrHeadArray {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'[', ']'})
|
|
|
|
}
|
|
|
|
code = c.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
if !c.anonymousKey {
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
}
|
|
|
|
code = c.next
|
|
|
|
code.ptr = ptr
|
|
|
|
c.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadArray:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadArray:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
if ptr == 0 {
|
|
|
|
code = c.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code.ptr = ptr
|
|
|
|
c.nextField.ptr = ptr
|
|
|
|
code = c.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadSlice:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadSlice:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
if ptr == 0 {
|
|
|
|
if code.op == opStructFieldPtrHeadSlice {
|
|
|
|
e.encodeNull()
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'[', ']'})
|
|
|
|
}
|
|
|
|
code = c.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
if !c.anonymousKey {
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
}
|
|
|
|
code = c.next
|
|
|
|
code.ptr = ptr
|
|
|
|
c.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadSlice:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadSlice:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
if ptr == 0 {
|
|
|
|
code = c.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code.ptr = ptr
|
|
|
|
c.nextField.ptr = ptr
|
|
|
|
code = c.next
|
|
|
|
}
|
2020-08-18 18:32:45 +03:00
|
|
|
case opStructFieldPtrHeadMarshalJSON:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadMarshalJSON:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
2020-08-22 12:28:03 +03:00
|
|
|
ptr: unsafe.Pointer(ptr + field.offset),
|
2020-08-18 18:32:45 +03:00
|
|
|
}))
|
2020-08-21 05:51:33 +03:00
|
|
|
rv := reflect.ValueOf(v)
|
|
|
|
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
|
2020-08-21 05:07:55 +03:00
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
break
|
|
|
|
}
|
2020-08-21 05:51:33 +03:00
|
|
|
b, err := rv.Interface().(Marshaler).MarshalJSON()
|
2020-08-18 18:32:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(b) == 0 {
|
|
|
|
return errUnexpectedEndOfJSON(
|
|
|
|
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(buf.Bytes())
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadMarshalJSON:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadMarshalJSON:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
2020-08-22 12:28:03 +03:00
|
|
|
ptr: unsafe.Pointer(ptr + field.offset),
|
2020-08-18 18:32:45 +03:00
|
|
|
}))
|
2020-08-21 05:51:33 +03:00
|
|
|
rv := reflect.ValueOf(v)
|
|
|
|
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
break
|
|
|
|
}
|
|
|
|
b, err := rv.Interface().(Marshaler).MarshalJSON()
|
2020-08-18 18:32:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(b) == 0 {
|
|
|
|
return errUnexpectedEndOfJSON(
|
|
|
|
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(buf.Bytes())
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadMarshalText:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadMarshalText:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
2020-08-22 12:28:03 +03:00
|
|
|
ptr: unsafe.Pointer(ptr + field.offset),
|
2020-08-18 18:32:45 +03:00
|
|
|
}))
|
2020-08-21 05:51:33 +03:00
|
|
|
rv := reflect.ValueOf(v)
|
|
|
|
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
|
2020-08-21 05:07:55 +03:00
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
break
|
|
|
|
}
|
2020-08-21 05:51:33 +03:00
|
|
|
bytes, err := rv.Interface().(encoding.TextMarshaler).MarshalText()
|
2020-08-18 18:32:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadMarshalText:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadMarshalText:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
2020-08-22 12:28:03 +03:00
|
|
|
ptr: unsafe.Pointer(ptr + field.offset),
|
2020-08-18 18:32:45 +03:00
|
|
|
}))
|
2020-08-21 05:51:33 +03:00
|
|
|
rv := reflect.ValueOf(v)
|
|
|
|
if rv.Type().Kind() == reflect.Interface && rv.IsNil() {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
break
|
|
|
|
}
|
|
|
|
bytes, err := rv.Interface().(encoding.TextMarshaler).MarshalText()
|
2020-08-18 18:32:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldPtrHeadIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldHeadIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
2020-08-22 18:54:43 +03:00
|
|
|
} else if field.next == field.end {
|
|
|
|
// not exists fields
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
code = field.next
|
|
|
|
code.ptr = ptr
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-01 07:12:01 +03:00
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = field.next
|
2020-08-15 12:36:02 +03:00
|
|
|
code.ptr = ptr
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldPtrHeadIntIndent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadIntIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeInt(e.ptrToInt(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldPtrHeadInt8Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
2020-05-01 07:12:01 +03:00
|
|
|
fallthrough
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldHeadInt8Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeInt8(e.ptrToInt8(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadInt16Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt16Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeInt16(e.ptrToInt16(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadInt32Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt32Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeInt32(e.ptrToInt32(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadInt64Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadInt64Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeInt64(e.ptrToInt64(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUintIndent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUintIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeUint(e.ptrToUint(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint8Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint8Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeUint8(e.ptrToUint8(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint16Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint16Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeUint16(e.ptrToUint16(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint32Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint32Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeUint32(e.ptrToUint32(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadUint64Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadUint64Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeUint64(e.ptrToUint64(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadFloat32Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadFloat32Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeFloat32(e.ptrToFloat32(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadFloat64Indent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadFloat64Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
2020-08-15 12:36:02 +03:00
|
|
|
v := e.ptrToFloat64(ptr)
|
2020-05-08 19:07:33 +03:00
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-05-08 19:07:33 +03:00
|
|
|
e.encodeFloat64(v)
|
2020-08-15 12:36:02 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringIndent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeString(e.ptrToString(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadBoolIndent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadBoolIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
2020-08-15 12:36:02 +03:00
|
|
|
e.encodeBool(e.ptrToBool(ptr))
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
case opStructFieldPtrHeadBytesIndent:
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadBytesIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(ptr))
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmpty:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadOmitEmpty:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
p := ptr + field.offset
|
|
|
|
if p == 0 || *(*uintptr)(unsafe.Pointer(p)) == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
code = field.next
|
|
|
|
code.ptr = p
|
|
|
|
}
|
2020-08-15 12:36:02 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmpty:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmpty:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
p := ptr + field.offset
|
|
|
|
if p == 0 || *(*uintptr)(unsafe.Pointer(p)) == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
code = field.next
|
|
|
|
code.ptr = p
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToInt(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyInt:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyInt:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToInt(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt8:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt8:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToInt8(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt8(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyInt8:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyInt8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToInt8(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt8(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt16:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt16:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToInt16(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt16(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyInt16:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyInt16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToInt16(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt16(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt32:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt32:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToInt32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyInt32:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyInt32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToInt32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt64:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt64:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToInt64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyInt64:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyInt64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToInt64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeInt64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToUint(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyUint:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyUint:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToUint(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint8:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint8:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToUint8(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint8(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyUint8:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyUint8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToUint8(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint8(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint16:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint16:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToUint16(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint16(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyUint16:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyUint16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToUint16(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint16(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint32:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint32:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToUint32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyUint32:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyUint32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToUint32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint64:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint64:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToUint64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyUint64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyUint64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToUint64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeUint64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyFloat32:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyFloat32:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToFloat32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeFloat32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyFloat32:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldAnonymousHeadOmitEmptyFloat32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToFloat32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeFloat32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyFloat64:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyFloat64:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-08 19:07:33 +03:00
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeFloat64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyFloat64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyFloat64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeFloat64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyString:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyString:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToString(ptr + field.offset)
|
|
|
|
if v == "" {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeString(v)
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyString:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyString:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToString(ptr + field.offset)
|
|
|
|
if v == "" {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyBool:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyBool:
|
2020-05-02 17:35:41 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToBool(ptr + field.offset)
|
|
|
|
if !v {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeBool(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
2020-08-15 12:17:48 +03:00
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyBool:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyBool:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToBool(ptr + field.offset)
|
|
|
|
if !v {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeBool(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyBytes:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadOmitEmptyBytes:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToBytes(ptr + field.offset)
|
|
|
|
if len(v) == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(v)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyBytes:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyBytes:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToBytes(ptr + field.offset)
|
|
|
|
if len(v) == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(v)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-08-18 18:32:45 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyMarshalJSON:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadOmitEmptyMarshalJSON:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(b) == 0 {
|
|
|
|
if isPtr {
|
|
|
|
return errUnexpectedEndOfJSON(
|
|
|
|
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeBytes(buf.Bytes())
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyMarshalJSON:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyMarshalJSON:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(b) == 0 {
|
|
|
|
if isPtr {
|
|
|
|
return errUnexpectedEndOfJSON(
|
|
|
|
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeBytes(buf.Bytes())
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadOmitEmptyMarshalText:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadOmitEmptyMarshalText:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadOmitEmptyMarshalText:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadOmitEmptyMarshalText:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
if p == nil || (!isPtr && *(*unsafe.Pointer)(p) == nil) {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadOmitEmptyIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
p := ptr + field.offset
|
|
|
|
if p == 0 || *(*uintptr)(unsafe.Pointer(p)) == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = field.next
|
|
|
|
code.ptr = p
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyIntIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyIntIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToInt(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeInt(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt8Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt8Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToInt8(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeInt8(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt16Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt16Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToInt16(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeInt16(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt32Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt32Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToInt32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeInt32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyInt64Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyInt64Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToInt64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeInt64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUintIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUintIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToUint(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeUint(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint8Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint8Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToUint8(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeUint8(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint16Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint16Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToUint16(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeUint16(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint32Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint32Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToUint32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeUint32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyUint64Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyUint64Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToUint64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeUint64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyFloat32Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyFloat32Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToFloat32(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeFloat32(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyFloat64Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyFloat64Indent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
|
|
|
if v == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-08 19:07:33 +03:00
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeFloat64(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyStringIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyStringIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToString(ptr + field.offset)
|
|
|
|
if v == "" {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeString(v)
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyBoolIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
2020-08-15 11:41:38 +03:00
|
|
|
case opStructFieldHeadOmitEmptyBoolIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
2020-05-03 11:41:33 +03:00
|
|
|
e.encodeNull()
|
2020-05-01 07:12:01 +03:00
|
|
|
code = field.end.next
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
v := e.ptrToBool(ptr + field.offset)
|
|
|
|
if !v {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeIndent(code.indent + 1)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(field.key)
|
2020-05-02 17:35:41 +03:00
|
|
|
e.encodeByte(' ')
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBool(v)
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
case opStructFieldPtrHeadOmitEmptyBytesIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadOmitEmptyBytesIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
v := e.ptrToBytes(ptr + field.offset)
|
|
|
|
if len(v) == 0 {
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
s := base64.StdEncoding.EncodeToString(v)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldPtrHeadStringTag:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTag:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
p := ptr + field.offset
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
code = field.next
|
|
|
|
code.ptr = p
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTag:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTag:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
code = field.next
|
|
|
|
code.ptr = ptr + field.offset
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagInt:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagInt:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt8:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt8(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagInt8:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagInt8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt8(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt16:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt16(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagInt16:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagInt16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt16(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt32:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagInt32:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagInt32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt64(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagInt64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagInt64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt64(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagUint:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagUint:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint8:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint8(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagUint8:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagUint8:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint8(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint16:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint16(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagUint16:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagUint16:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint16(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint32:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagUint32:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagUint32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint64(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagUint64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagUint64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint64(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagFloat32:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagFloat32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToFloat32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagFloat32:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagFloat32:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToFloat32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagFloat64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagFloat64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(v))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagFloat64:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagFloat64:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(v))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagString:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagString:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(strconv.Quote(e.ptrToString(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagString:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagString:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(strconv.Quote(e.ptrToString(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagBool:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagBool:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToBool(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagBool:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagBool:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToBool(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagBytes:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagBytes:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(
|
|
|
|
e.ptrToBytes(ptr + field.offset),
|
|
|
|
)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagBytes:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagBytes:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(
|
|
|
|
e.ptrToBytes(ptr + field.offset),
|
|
|
|
)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagMarshalJSON:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagMarshalJSON:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(b) == 0 {
|
|
|
|
if isPtr {
|
|
|
|
return errUnexpectedEndOfJSON(
|
|
|
|
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeBytes([]byte{'"', '"'})
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeString(buf.String())
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagMarshalJSON:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagMarshalJSON:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
isPtr := code.typ.Kind() == reflect.Ptr
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(b) == 0 {
|
|
|
|
if isPtr {
|
|
|
|
return errUnexpectedEndOfJSON(
|
|
|
|
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeBytes([]byte{'"', '"'})
|
|
|
|
code = field.nextField
|
|
|
|
} else {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(buf.String())
|
|
|
|
code = field.next
|
|
|
|
}
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagMarshalText:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagMarshalText:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeByte('{')
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrAnonymousHeadStringTagMarshalText:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldAnonymousHeadStringTagMarshalText:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
p := unsafe.Pointer(ptr + field.offset)
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{typ: code.typ, ptr: p}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
p := ptr + field.offset
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = field.next
|
|
|
|
code.ptr = p
|
|
|
|
field.nextField.ptr = field.ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagIntIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagIntIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt8Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt8Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt8(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt16Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt16Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt16(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt32Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt32Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagInt64Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagInt64Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt64(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUintIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUintIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint8Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint8Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint8(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint16Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint16Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint16(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint32Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint32Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagUint64Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagUint64Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint64(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagFloat32Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagFloat32Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToFloat32(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagFloat64Indent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagFloat64Indent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
v := e.ptrToFloat64(ptr + field.offset)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(v))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagStringIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagStringIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(strconv.Quote(e.ptrToString(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagBoolIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagBoolIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToBool(ptr + field.offset)))
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
|
|
|
case opStructFieldPtrHeadStringTagBytesIndent:
|
|
|
|
if code.ptr != 0 {
|
|
|
|
code.ptr = e.ptrToPtr(code.ptr)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case opStructFieldHeadStringTagBytesIndent:
|
|
|
|
field := code.toStructFieldCode()
|
|
|
|
ptr := field.ptr
|
|
|
|
if ptr == 0 {
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeNull()
|
|
|
|
code = field.end.next
|
|
|
|
} else {
|
|
|
|
e.encodeBytes([]byte{'{', '\n'})
|
|
|
|
e.encodeIndent(code.indent + 1)
|
|
|
|
e.encodeBytes(field.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
s := base64.StdEncoding.EncodeToString(
|
|
|
|
e.ptrToBytes(ptr + field.offset),
|
|
|
|
)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = field.next
|
|
|
|
field.nextField.ptr = ptr
|
|
|
|
}
|
2020-04-29 18:31:50 +03:00
|
|
|
case opStructField:
|
2020-08-08 12:53:01 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
2020-04-29 18:31:50 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 06:58:34 +03:00
|
|
|
if !c.anonymousKey {
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
}
|
2020-04-29 18:31:50 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldInt:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt(e.ptrToInt(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldInt8:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt8(e.ptrToInt8(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldInt16:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt16(e.ptrToInt16(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldInt32:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt32(e.ptrToInt32(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldInt64:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt64(e.ptrToInt64(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldUint:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint(e.ptrToUint(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldUint8:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint8(e.ptrToUint8(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldUint16:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint16(e.ptrToUint16(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldUint32:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint32(e.ptrToUint32(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldUint64:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint64(e.ptrToUint64(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldFloat32:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeFloat32(e.ptrToFloat32(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldFloat64:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
v := e.ptrToFloat64(c.ptr + c.offset)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeFloat64(v)
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldString:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(e.ptrToString(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldBool:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeBool(e.ptrToBool(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldBytes:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(c.ptr + c.offset))
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldMarshalJSON:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(buf.Bytes())
|
|
|
|
code = code.next
|
|
|
|
case opStructFieldMarshalText:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
|
|
|
code = code.next
|
2020-08-23 19:50:18 +03:00
|
|
|
case opStructFieldArray:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
case opStructFieldSlice:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
case opStructFieldMap:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldMapLoad:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldStruct:
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr + c.offset
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldIntIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt(e.ptrToInt(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldInt8Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt8(e.ptrToInt8(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldInt16Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt16(e.ptrToInt16(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldInt32Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt32(e.ptrToInt32(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldInt64Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt64(e.ptrToInt64(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldUintIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint(e.ptrToUint(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldUint8Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint8(e.ptrToUint8(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldUint16Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint16(e.ptrToUint16(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldUint32Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint32(e.ptrToUint32(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldUint64Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint64(e.ptrToUint64(c.ptr + c.offset))
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldFloat32Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeFloat32(e.ptrToFloat32(c.ptr + c.offset))
|
|
|
|
code = code.next
|
2020-04-29 18:31:50 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldFloat64Indent:
|
2020-04-29 18:31:50 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
v := e.ptrToFloat64(c.ptr + c.offset)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeFloat64(v)
|
|
|
|
code = code.next
|
2020-04-30 05:56:56 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(e.ptrToString(c.ptr + c.offset))
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldBoolIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeBool(e.ptrToBool(c.ptr + c.offset))
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldBytesIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(c.ptr + c.offset))
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldMarshalJSONIndent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-08 12:53:01 +03:00
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
2020-04-30 05:56:56 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(buf.Bytes())
|
|
|
|
code = code.next
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-23 19:50:18 +03:00
|
|
|
case opStructFieldArrayIndent:
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldSliceIndent:
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldMapIndent:
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
mlen := maplen(unsafe.Pointer(p))
|
|
|
|
if mlen == 0 {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
mapCode := code.next
|
|
|
|
mapHeadCode := mapCode.toMapHeadCode()
|
|
|
|
code = mapHeadCode.end.next
|
|
|
|
} else {
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldMapLoadIndent:
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
e.encodeNull()
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
p = uintptr(*(*unsafe.Pointer)(unsafe.Pointer(p)))
|
|
|
|
mlen := maplen(unsafe.Pointer(p))
|
|
|
|
if mlen == 0 {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldStructIndent:
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
if p == 0 {
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
headCode := c.next.toStructFieldCode()
|
|
|
|
if headCode.next == headCode.end {
|
|
|
|
// not exists fields
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldOmitEmpty:
|
2020-04-30 05:56:56 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 || *(*uintptr)(unsafe.Pointer(p)) == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldOmitEmptyInt:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToInt(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt(v)
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt8:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToInt8(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt8(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt16:
|
2020-04-30 05:56:56 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt16(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt16(v)
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt32:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToInt32(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt32(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt64:
|
2020-04-30 05:56:56 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt64(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeInt64(v)
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToUint(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint8:
|
2020-04-30 05:56:56 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint8(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint8(v)
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint16:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToUint16(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint16(v)
|
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint32:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToUint32(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint32(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint64:
|
2020-04-30 05:56:56 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint64(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeUint64(v)
|
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyFloat32:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToFloat32(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeFloat32(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyFloat64:
|
2020-04-30 05:56:56 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-05-08 19:07:33 +03:00
|
|
|
v := e.ptrToFloat64(c.ptr + c.offset)
|
2020-08-19 13:56:02 +03:00
|
|
|
if v != 0 {
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-08 19:07:33 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeFloat64(v)
|
2020-05-08 19:07:33 +03:00
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyString:
|
2020-04-29 18:31:50 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToString(c.ptr + c.offset)
|
|
|
|
if v != "" {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-04-30 05:56:56 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyBool:
|
2020-08-19 04:34:11 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToBool(c.ptr + c.offset)
|
|
|
|
if v {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeBool(v)
|
|
|
|
}
|
2020-08-19 04:34:11 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyBytes:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToBytes(c.ptr + c.offset)
|
|
|
|
if len(v) > 0 {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(v)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyMarshalJSON:
|
2020-08-18 18:32:45 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
2020-08-19 13:56:02 +03:00
|
|
|
if v != nil {
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeBytes(buf.Bytes())
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyMarshalText:
|
2020-08-18 18:32:45 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
2020-08-19 13:56:02 +03:00
|
|
|
if v != nil {
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
|
|
|
}
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
2020-08-23 19:50:18 +03:00
|
|
|
case opStructFieldOmitEmptyArray:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptySlice:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyMap:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
mlen := maplen(unsafe.Pointer(p))
|
|
|
|
if mlen == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyMapLoad:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
p = uintptr(*(*unsafe.Pointer)(unsafe.Pointer(p)))
|
|
|
|
mlen := maplen(unsafe.Pointer(p))
|
|
|
|
if mlen == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldOmitEmptyIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 || *(*uintptr)(unsafe.Pointer(p)) == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldOmitEmptyIntIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt8Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt8(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt8(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt16Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt16(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt16(v)
|
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt32Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt32(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt32(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyInt64Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToInt64(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeInt64(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUintIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint8Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint8(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint8(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint16Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint16(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint16(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint32Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint32(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-08 19:07:33 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint32(v)
|
2020-05-08 19:07:33 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyUint64Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToUint64(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeUint64(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyFloat32Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToFloat32(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeFloat32(v)
|
2020-08-08 12:53:01 +03:00
|
|
|
}
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyFloat64Indent:
|
2020-08-19 04:34:11 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToFloat64(c.ptr + c.offset)
|
|
|
|
if v != 0 {
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
|
|
|
}
|
|
|
|
}
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeFloat64(v)
|
2020-08-19 04:34:11 +03:00
|
|
|
}
|
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyStringIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToString(c.ptr + c.offset)
|
|
|
|
if v != "" {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(v)
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyBoolIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToBool(c.ptr + c.offset)
|
|
|
|
if v {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeBool(v)
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldOmitEmptyBytesIndent:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToBytes(c.ptr + c.offset)
|
|
|
|
if len(v) > 0 {
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
2020-05-01 07:12:01 +03:00
|
|
|
e.encodeBytes(c.key)
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeByte(' ')
|
|
|
|
s := base64.StdEncoding.EncodeToString(v)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
|
|
|
}
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-23 19:50:18 +03:00
|
|
|
case opStructFieldOmitEmptyArrayIndent:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptySliceIndent:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
|
|
|
if p == 0 || header.Data == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyMapIndent:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
mlen := maplen(unsafe.Pointer(p))
|
|
|
|
if mlen == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyMapLoadIndent:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
p = uintptr(*(*unsafe.Pointer)(unsafe.Pointer(p)))
|
|
|
|
mlen := maplen(unsafe.Pointer(p))
|
|
|
|
if mlen == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldOmitEmptyStructIndent:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if p == 0 {
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
headCode := c.next.toStructFieldCode()
|
|
|
|
if headCode.next == headCode.end {
|
|
|
|
// not exists fields
|
|
|
|
e.encodeBytes([]byte{'{', '}'})
|
|
|
|
code = c.nextField
|
|
|
|
} else {
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTag:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldStringTagInt:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt(c.ptr + c.offset)))
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldStringTagInt8:
|
|
|
|
c := code.toStructFieldCode()
|
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt8(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagInt16:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt16(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagInt32:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt32(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagInt64:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt64(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint8:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint8(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint16:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint16(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint32:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint32(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint64:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint64(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagFloat32:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToFloat32(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagFloat64:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToFloat64(c.ptr + c.offset)
|
2020-08-19 13:56:02 +03:00
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
|
|
|
}
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(v))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagString:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(strconv.Quote(e.ptrToString(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagBool:
|
2020-05-01 07:12:01 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-05-01 07:12:01 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToBool(c.ptr + c.offset)))
|
2020-05-01 07:12:01 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagBytes:
|
2020-08-19 04:34:11 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
v := e.ptrToBytes(c.ptr + c.offset)
|
2020-08-19 13:56:02 +03:00
|
|
|
if e.buf[len(e.buf)-1] != '{' {
|
|
|
|
e.encodeByte(',')
|
2020-08-19 04:34:11 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes(c.key)
|
|
|
|
s := base64.StdEncoding.EncodeToString(v)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
2020-08-19 04:34:11 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagMarshalJSON:
|
2020-08-18 18:32:45 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
2020-08-19 13:56:02 +03:00
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := compact(&buf, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeString(buf.String())
|
2020-08-18 18:32:45 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagMarshalText:
|
2020-08-18 18:32:45 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
2020-08-19 13:56:02 +03:00
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
2020-08-18 18:32:45 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
2020-08-18 18:32:45 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
|
|
|
p := c.ptr + c.offset
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
code = code.next
|
|
|
|
code.ptr = p
|
2020-05-02 17:35:41 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagIntIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagInt8Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt8(c.ptr + c.offset)))
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldStringTagInt16Indent:
|
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt16(c.ptr + c.offset)))
|
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
|
|
|
case opStructFieldStringTagInt32Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt32(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagInt64Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToInt64(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUintIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint8Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint8(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint16Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint16(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint32Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint32(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagUint64Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToUint64(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagFloat32Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToFloat32(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagFloat64Indent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-19 13:56:02 +03:00
|
|
|
v := e.ptrToFloat64(c.ptr + c.offset)
|
|
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
|
|
return &UnsupportedValueError{
|
|
|
|
Value: reflect.ValueOf(v),
|
|
|
|
Str: strconv.FormatFloat(v, 'g', -1, 64),
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(v))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagStringIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
var b bytes.Buffer
|
|
|
|
enc := NewEncoder(&b)
|
|
|
|
enc.encodeString(e.ptrToString(c.ptr + c.offset))
|
|
|
|
e.encodeString(string(enc.buf))
|
|
|
|
enc.release()
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagBoolIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
e.encodeString(fmt.Sprint(e.ptrToBool(c.ptr + c.offset)))
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagBytesIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
2020-05-02 17:35:41 +03:00
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
s := base64.StdEncoding.EncodeToString(
|
|
|
|
e.ptrToBytes(c.ptr + c.offset),
|
|
|
|
)
|
|
|
|
e.encodeByte('"')
|
|
|
|
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s)))
|
|
|
|
e.encodeByte('"')
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
|
|
|
code.ptr = c.ptr
|
2020-08-19 13:56:02 +03:00
|
|
|
case opStructFieldStringTagMarshalJSONIndent:
|
2020-05-02 17:35:41 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
|
|
|
b, err := v.(Marshaler).MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: 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, b, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.encodeString(buf.String())
|
2020-05-02 17:35:41 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
|
|
|
case opStructFieldStringTagMarshalTextIndent:
|
2020-08-19 04:34:11 +03:00
|
|
|
c := code.toStructFieldCode()
|
2020-08-22 18:54:19 +03:00
|
|
|
if e.buf[len(e.buf)-2] != '{' || e.buf[len(e.buf)-1] == '}' {
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeBytes([]byte{',', '\n'})
|
|
|
|
}
|
|
|
|
e.encodeIndent(c.indent)
|
|
|
|
e.encodeBytes(c.key)
|
|
|
|
e.encodeByte(' ')
|
|
|
|
ptr := c.ptr + c.offset
|
|
|
|
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
|
|
|
|
typ: code.typ,
|
|
|
|
ptr: unsafe.Pointer(ptr),
|
|
|
|
}))
|
|
|
|
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
return &MarshalerError{
|
|
|
|
Type: rtype2type(code.typ),
|
|
|
|
Err: err,
|
2020-08-19 04:34:11 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 13:56:02 +03:00
|
|
|
e.encodeString(*(*string)(unsafe.Pointer(&bytes)))
|
2020-08-19 04:34:11 +03:00
|
|
|
code = code.next
|
2020-08-19 13:56:02 +03:00
|
|
|
c.nextField.ptr = c.ptr
|
2020-04-29 18:31:50 +03:00
|
|
|
case opStructEnd:
|
|
|
|
e.encodeByte('}')
|
|
|
|
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:
|
|
|
|
e.encodeByte('\n')
|
|
|
|
e.encodeIndent(code.indent)
|
|
|
|
e.encodeByte('}')
|
|
|
|
code = code.next
|
2020-04-29 18:31:50 +03:00
|
|
|
case opEnd:
|
|
|
|
goto END
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END:
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-30 07:52:24 +03:00
|
|
|
|
|
|
|
func (e *Encoder) ptrToPtr(p uintptr) uintptr { return *(*uintptr)(unsafe.Pointer(p)) }
|
|
|
|
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)) }
|