go-json/encode_opcode.go

949 lines
26 KiB
Go
Raw Normal View History

2020-04-29 18:31:50 +03:00
package json
import (
"fmt"
"reflect"
"strings"
"unsafe"
)
type opType int
const (
opEnd opType = iota
opInt
opInt8
opInt16
opInt32
opInt64
opUint
opUint8
opUint16
opUint32
opUint64
opFloat32
opFloat64
opString
opBool
opInterface
2020-04-29 18:31:50 +03:00
opPtr
2020-05-04 12:39:17 +03:00
opMarshalJSON
opMarshalText
2020-05-02 17:35:41 +03:00
2020-04-29 18:31:50 +03:00
opSliceHead
opSliceElem
opSliceEnd
2020-05-02 17:35:41 +03:00
opSliceHeadIndent
opSliceElemIndent
opSliceEndIndent
opArrayHead
opArrayElem
opArrayEnd
2020-05-02 17:35:41 +03:00
opArrayHeadIndent
opArrayElemIndent
opArrayEndIndent
opMapHead
opMapKey
opMapValue
opMapEnd
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
opMapHeadIndent
opMapKeyIndent
opMapValueIndent
opMapEndIndent
2020-05-01 07:12:01 +03:00
// StructFieldHead
2020-04-29 19:44:48 +03:00
opStructFieldHead
opStructFieldHeadInt
2020-04-30 05:56:56 +03:00
opStructFieldHeadInt8
opStructFieldHeadInt16
opStructFieldHeadInt32
opStructFieldHeadInt64
opStructFieldHeadUint
opStructFieldHeadUint8
opStructFieldHeadUint16
opStructFieldHeadUint32
opStructFieldHeadUint64
opStructFieldHeadFloat32
opStructFieldHeadFloat64
2020-04-29 19:44:48 +03:00
opStructFieldHeadString
2020-04-30 05:56:56 +03:00
opStructFieldHeadBool
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
opStructFieldHeadIndent
opStructFieldHeadIntIndent
opStructFieldHeadInt8Indent
opStructFieldHeadInt16Indent
opStructFieldHeadInt32Indent
opStructFieldHeadInt64Indent
opStructFieldHeadUintIndent
opStructFieldHeadUint8Indent
opStructFieldHeadUint16Indent
opStructFieldHeadUint32Indent
opStructFieldHeadUint64Indent
opStructFieldHeadFloat32Indent
opStructFieldHeadFloat64Indent
opStructFieldHeadStringIndent
opStructFieldHeadBoolIndent
2020-05-01 07:12:01 +03:00
// StructFieldHead with omitempty
opStructFieldHeadOmitEmpty
opStructFieldHeadIntOmitEmpty
opStructFieldHeadInt8OmitEmpty
opStructFieldHeadInt16OmitEmpty
opStructFieldHeadInt32OmitEmpty
opStructFieldHeadInt64OmitEmpty
opStructFieldHeadUintOmitEmpty
opStructFieldHeadUint8OmitEmpty
opStructFieldHeadUint16OmitEmpty
opStructFieldHeadUint32OmitEmpty
opStructFieldHeadUint64OmitEmpty
opStructFieldHeadFloat32OmitEmpty
opStructFieldHeadFloat64OmitEmpty
opStructFieldHeadStringOmitEmpty
opStructFieldHeadBoolOmitEmpty
2020-05-02 17:35:41 +03:00
opStructFieldHeadOmitEmptyIndent
opStructFieldHeadIntOmitEmptyIndent
opStructFieldHeadInt8OmitEmptyIndent
opStructFieldHeadInt16OmitEmptyIndent
opStructFieldHeadInt32OmitEmptyIndent
opStructFieldHeadInt64OmitEmptyIndent
opStructFieldHeadUintOmitEmptyIndent
opStructFieldHeadUint8OmitEmptyIndent
opStructFieldHeadUint16OmitEmptyIndent
opStructFieldHeadUint32OmitEmptyIndent
opStructFieldHeadUint64OmitEmptyIndent
opStructFieldHeadFloat32OmitEmptyIndent
opStructFieldHeadFloat64OmitEmptyIndent
opStructFieldHeadStringOmitEmptyIndent
opStructFieldHeadBoolOmitEmptyIndent
2020-05-01 07:12:01 +03:00
// StructFieldHead for pointer structure
2020-04-29 19:44:48 +03:00
opStructFieldPtrHead
opStructFieldPtrHeadInt
2020-04-30 05:56:56 +03:00
opStructFieldPtrHeadInt8
opStructFieldPtrHeadInt16
opStructFieldPtrHeadInt32
opStructFieldPtrHeadInt64
opStructFieldPtrHeadUint
opStructFieldPtrHeadUint8
opStructFieldPtrHeadUint16
opStructFieldPtrHeadUint32
opStructFieldPtrHeadUint64
opStructFieldPtrHeadFloat32
opStructFieldPtrHeadFloat64
2020-04-29 19:44:48 +03:00
opStructFieldPtrHeadString
2020-04-30 05:56:56 +03:00
opStructFieldPtrHeadBool
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
opStructFieldPtrHeadIndent
opStructFieldPtrHeadIntIndent
opStructFieldPtrHeadInt8Indent
opStructFieldPtrHeadInt16Indent
opStructFieldPtrHeadInt32Indent
opStructFieldPtrHeadInt64Indent
opStructFieldPtrHeadUintIndent
opStructFieldPtrHeadUint8Indent
opStructFieldPtrHeadUint16Indent
opStructFieldPtrHeadUint32Indent
opStructFieldPtrHeadUint64Indent
opStructFieldPtrHeadFloat32Indent
opStructFieldPtrHeadFloat64Indent
opStructFieldPtrHeadStringIndent
opStructFieldPtrHeadBoolIndent
2020-05-01 07:12:01 +03:00
// StructFieldPtrHead with omitempty
opStructFieldPtrHeadOmitEmpty
opStructFieldPtrHeadIntOmitEmpty
opStructFieldPtrHeadInt8OmitEmpty
opStructFieldPtrHeadInt16OmitEmpty
opStructFieldPtrHeadInt32OmitEmpty
opStructFieldPtrHeadInt64OmitEmpty
opStructFieldPtrHeadUintOmitEmpty
opStructFieldPtrHeadUint8OmitEmpty
opStructFieldPtrHeadUint16OmitEmpty
opStructFieldPtrHeadUint32OmitEmpty
opStructFieldPtrHeadUint64OmitEmpty
opStructFieldPtrHeadFloat32OmitEmpty
opStructFieldPtrHeadFloat64OmitEmpty
opStructFieldPtrHeadStringOmitEmpty
opStructFieldPtrHeadBoolOmitEmpty
2020-05-02 17:35:41 +03:00
opStructFieldPtrHeadOmitEmptyIndent
opStructFieldPtrHeadIntOmitEmptyIndent
opStructFieldPtrHeadInt8OmitEmptyIndent
opStructFieldPtrHeadInt16OmitEmptyIndent
opStructFieldPtrHeadInt32OmitEmptyIndent
opStructFieldPtrHeadInt64OmitEmptyIndent
opStructFieldPtrHeadUintOmitEmptyIndent
opStructFieldPtrHeadUint8OmitEmptyIndent
opStructFieldPtrHeadUint16OmitEmptyIndent
opStructFieldPtrHeadUint32OmitEmptyIndent
opStructFieldPtrHeadUint64OmitEmptyIndent
opStructFieldPtrHeadFloat32OmitEmptyIndent
opStructFieldPtrHeadFloat64OmitEmptyIndent
opStructFieldPtrHeadStringOmitEmptyIndent
opStructFieldPtrHeadBoolOmitEmptyIndent
2020-05-01 07:12:01 +03:00
// StructField
2020-04-29 18:31:50 +03:00
opStructField
opStructFieldInt
2020-04-30 05:56:56 +03:00
opStructFieldInt8
opStructFieldInt16
opStructFieldInt32
opStructFieldInt64
opStructFieldUint
opStructFieldUint8
opStructFieldUint16
opStructFieldUint32
opStructFieldUint64
opStructFieldFloat32
opStructFieldFloat64
2020-04-29 18:31:50 +03:00
opStructFieldString
2020-04-30 05:56:56 +03:00
opStructFieldBool
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
opStructFieldIndent
opStructFieldIntIndent
opStructFieldInt8Indent
opStructFieldInt16Indent
opStructFieldInt32Indent
opStructFieldInt64Indent
opStructFieldUintIndent
opStructFieldUint8Indent
opStructFieldUint16Indent
opStructFieldUint32Indent
opStructFieldUint64Indent
opStructFieldFloat32Indent
opStructFieldFloat64Indent
opStructFieldStringIndent
opStructFieldBoolIndent
2020-05-01 07:12:01 +03:00
// StructField with omitempty
opStructFieldOmitEmpty
opStructFieldIntOmitEmpty
opStructFieldInt8OmitEmpty
opStructFieldInt16OmitEmpty
opStructFieldInt32OmitEmpty
opStructFieldInt64OmitEmpty
opStructFieldUintOmitEmpty
opStructFieldUint8OmitEmpty
opStructFieldUint16OmitEmpty
opStructFieldUint32OmitEmpty
opStructFieldUint64OmitEmpty
opStructFieldFloat32OmitEmpty
opStructFieldFloat64OmitEmpty
opStructFieldStringOmitEmpty
opStructFieldBoolOmitEmpty
2020-05-02 17:35:41 +03:00
opStructFieldOmitEmptyIndent
opStructFieldIntOmitEmptyIndent
opStructFieldInt8OmitEmptyIndent
opStructFieldInt16OmitEmptyIndent
opStructFieldInt32OmitEmptyIndent
opStructFieldInt64OmitEmptyIndent
opStructFieldUintOmitEmptyIndent
opStructFieldUint8OmitEmptyIndent
opStructFieldUint16OmitEmptyIndent
opStructFieldUint32OmitEmptyIndent
opStructFieldUint64OmitEmptyIndent
opStructFieldFloat32OmitEmptyIndent
opStructFieldFloat64OmitEmptyIndent
opStructFieldStringOmitEmptyIndent
opStructFieldBoolOmitEmptyIndent
2020-04-29 18:31:50 +03:00
opStructEnd
2020-05-02 17:35:41 +03:00
opStructEndIndent
2020-04-29 18:31:50 +03:00
)
func (t opType) String() string {
switch t {
case opEnd:
return "END"
case opInt:
return "INT"
case opInt8:
return "INT8"
case opInt16:
return "INT16"
case opInt32:
return "INT32"
case opInt64:
return "INT64"
case opUint:
return "UINT"
case opUint8:
return "UINT8"
case opUint16:
return "UINT16"
case opUint32:
return "UINT32"
case opUint64:
return "UINT64"
case opFloat32:
return "FLOAT32"
case opFloat64:
return "FLOAT64"
case opString:
return "STRING"
case opBool:
return "BOOL"
case opInterface:
return "INTERFACE"
2020-04-29 18:31:50 +03:00
case opPtr:
return "PTR"
2020-05-04 12:39:17 +03:00
case opMarshalJSON:
return "MARSHAL_JSON"
case opMarshalText:
return "MARSHAL_TEXT"
2020-05-02 17:35:41 +03:00
2020-04-29 18:31:50 +03:00
case opSliceHead:
return "SLICE_HEAD"
case opSliceElem:
return "SLICE_ELEM"
case opSliceEnd:
return "SLICE_END"
2020-05-02 17:35:41 +03:00
case opSliceHeadIndent:
return "SLICE_HEAD_INDENT"
case opSliceElemIndent:
return "SLICE_ELEM_INDENT"
case opSliceEndIndent:
return "SLICE_END_INDENT"
case opArrayHead:
return "ARRAY_HEAD"
case opArrayElem:
return "ARRAY_ELEM"
case opArrayEnd:
return "ARRAY_END"
2020-05-02 17:35:41 +03:00
case opArrayHeadIndent:
return "ARRAY_HEAD_INDENT"
case opArrayElemIndent:
return "ARRAY_ELEM_INDENT"
case opArrayEndIndent:
return "ARRAY_END_INDENT"
case opMapHead:
2020-05-02 17:35:41 +03:00
return "MAP_HEAD"
case opMapKey:
return "MAP_KEY"
case opMapValue:
return "MAP_VALUE"
case opMapEnd:
return "MAP_END"
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
case opMapHeadIndent:
return "MAP_HEAD_INDENT"
case opMapKeyIndent:
return "MAP_KEY_INDENT"
case opMapValueIndent:
return "MAP_VALUE_INDENT"
case opMapEndIndent:
return "MAP_END_INDENT"
2020-04-29 19:44:48 +03:00
case opStructFieldHead:
return "STRUCT_FIELD_HEAD"
case opStructFieldHeadInt:
return "STRUCT_FIELD_HEAD_INT"
2020-04-30 05:56:56 +03:00
case opStructFieldHeadInt8:
return "STRUCT_FIELD_HEAD_INT8"
case opStructFieldHeadInt16:
return "STRUCT_FIELD_HEAD_INT16"
case opStructFieldHeadInt32:
return "STRUCT_FIELD_HEAD_INT32"
case opStructFieldHeadInt64:
return "STRUCT_FIELD_HEAD_INT64"
case opStructFieldHeadUint:
return "STRUCT_FIELD_HEAD_UINT"
case opStructFieldHeadUint8:
return "STRUCT_FIELD_HEAD_UINT8"
case opStructFieldHeadUint16:
return "STRUCT_FIELD_HEAD_UINT16"
case opStructFieldHeadUint32:
return "STRUCT_FIELD_HEAD_UINT32"
case opStructFieldHeadUint64:
return "STRUCT_FIELD_HEAD_UINT64"
case opStructFieldHeadFloat32:
return "STRUCT_FIELD_HEAD_FLOAT32"
case opStructFieldHeadFloat64:
return "STRUCT_FIELD_HEAD_FLOAT64"
2020-04-29 19:44:48 +03:00
case opStructFieldHeadString:
return "STRUCT_FIELD_HEAD_STRING"
2020-04-30 05:56:56 +03:00
case opStructFieldHeadBool:
return "STRUCT_FIELD_HEAD_BOOL"
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
case opStructFieldHeadIndent:
return "STRUCT_FIELD_HEAD_INDENT"
case opStructFieldHeadIntIndent:
return "STRUCT_FIELD_HEAD_INT_INDENT"
case opStructFieldHeadInt8Indent:
return "STRUCT_FIELD_HEAD_INT8_INDENT"
case opStructFieldHeadInt16Indent:
return "STRUCT_FIELD_HEAD_INT16_INDENT"
case opStructFieldHeadInt32Indent:
return "STRUCT_FIELD_HEAD_INT32_INDENT"
case opStructFieldHeadInt64Indent:
return "STRUCT_FIELD_HEAD_INT64_INDENT"
case opStructFieldHeadUintIndent:
return "STRUCT_FIELD_HEAD_UINT_INDENT"
case opStructFieldHeadUint8Indent:
return "STRUCT_FIELD_HEAD_UINT8_INDENT"
case opStructFieldHeadUint16Indent:
return "STRUCT_FIELD_HEAD_UINT16_INDENT"
case opStructFieldHeadUint32Indent:
return "STRUCT_FIELD_HEAD_UINT32_INDENT"
case opStructFieldHeadUint64Indent:
return "STRUCT_FIELD_HEAD_UINT64_INDENT"
case opStructFieldHeadFloat32Indent:
return "STRUCT_FIELD_HEAD_FLOAT32_INDENT"
case opStructFieldHeadFloat64Indent:
return "STRUCT_FIELD_HEAD_FLOAT64_INDENT"
case opStructFieldHeadStringIndent:
return "STRUCT_FIELD_HEAD_STRING_INDENT"
case opStructFieldHeadBoolIndent:
return "STRUCT_FIELD_HEAD_BOOL_INDENT"
2020-05-01 07:12:01 +03:00
case opStructFieldHeadOmitEmpty:
return "STRUCT_FIELD_HEAD_OMIT_EMPTY"
case opStructFieldHeadIntOmitEmpty:
return "STRUCT_FIELD_HEAD_INT_OMIT_EMPTY"
case opStructFieldHeadInt8OmitEmpty:
return "STRUCT_FIELD_HEAD_INT8_OMIT_EMPTY"
case opStructFieldHeadInt16OmitEmpty:
return "STRUCT_FIELD_HEAD_INT16_OMIT_EMPTY"
case opStructFieldHeadInt32OmitEmpty:
return "STRUCT_FIELD_HEAD_INT32_OMIT_EMPTY"
case opStructFieldHeadInt64OmitEmpty:
return "STRUCT_FIELD_HEAD_INT64_OMIT_EMPTY"
case opStructFieldHeadUintOmitEmpty:
return "STRUCT_FIELD_HEAD_UINT_OMIT_EMPTY"
case opStructFieldHeadUint8OmitEmpty:
return "STRUCT_FIELD_HEAD_UINT8_OMIT_EMPTY"
case opStructFieldHeadUint16OmitEmpty:
return "STRUCT_FIELD_HEAD_UINT16_OMIT_EMPTY"
case opStructFieldHeadUint32OmitEmpty:
return "STRUCT_FIELD_HEAD_UINT32_OMIT_EMPTY"
case opStructFieldHeadUint64OmitEmpty:
return "STRUCT_FIELD_HEAD_UINT64_OMIT_EMPTY"
case opStructFieldHeadFloat32OmitEmpty:
return "STRUCT_FIELD_HEAD_FLOAT32_OMIT_EMPTY"
case opStructFieldHeadFloat64OmitEmpty:
return "STRUCT_FIELD_HEAD_FLOAT64_OMIT_EMPTY"
case opStructFieldHeadStringOmitEmpty:
return "STRUCT_FIELD_HEAD_STRING_OMIT_EMPTY"
case opStructFieldHeadBoolOmitEmpty:
return "STRUCT_FIELD_HEAD_BOOL_OMIT_EMPTY"
2020-05-02 17:35:41 +03:00
case opStructFieldHeadOmitEmptyIndent:
return "STRUCT_FIELD_HEAD_OMIT_EMPTY_INDENT"
case opStructFieldHeadIntOmitEmptyIndent:
return "STRUCT_FIELD_HEAD_INT_OMIT_EMPTY_INDENT"
case opStructFieldHeadInt8OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_INT8_OMIT_EMPTY_INDENT"
case opStructFieldHeadInt16OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_INT16_OMIT_EMPTY_INDENT"
case opStructFieldHeadInt32OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_INT32_OMIT_EMPTY_INDENT"
case opStructFieldHeadInt64OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_INT64_OMIT_EMPTY_INDENT"
case opStructFieldHeadUintOmitEmptyIndent:
return "STRUCT_FIELD_HEAD_UINT_OMIT_EMPTY_INDENT"
case opStructFieldHeadUint8OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_UINT8_OMIT_EMPTY_INDENT"
case opStructFieldHeadUint16OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_UINT16_OMIT_EMPTY_INDENT"
case opStructFieldHeadUint32OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_UINT32_OMIT_EMPTY_INDENT"
case opStructFieldHeadUint64OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_UINT64_OMIT_EMPTY_INDENT"
case opStructFieldHeadFloat32OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_FLOAT32_OMIT_EMPTY_INDENT"
case opStructFieldHeadFloat64OmitEmptyIndent:
return "STRUCT_FIELD_HEAD_FLOAT64_OMIT_EMPTY_INDENT"
case opStructFieldHeadStringOmitEmptyIndent:
return "STRUCT_FIELD_HEAD_STRING_OMIT_EMPTY_INDENT"
case opStructFieldHeadBoolOmitEmptyIndent:
return "STRUCT_FIELD_HEAD_BOOL_OMIT_EMPTY_INDENT"
2020-04-29 19:44:48 +03:00
case opStructFieldPtrHead:
return "STRUCT_FIELD_PTR_HEAD"
case opStructFieldPtrHeadInt:
return "STRUCT_FIELD_PTR_HEAD_INT"
2020-04-30 05:56:56 +03:00
case opStructFieldPtrHeadInt8:
return "STRUCT_FIELD_PTR_HEAD_INT8"
case opStructFieldPtrHeadInt16:
return "STRUCT_FIELD_PTR_HEAD_INT16"
case opStructFieldPtrHeadInt32:
return "STRUCT_FIELD_PTR_HEAD_INT32"
case opStructFieldPtrHeadInt64:
return "STRUCT_FIELD_PTR_HEAD_INT64"
case opStructFieldPtrHeadUint:
return "STRUCT_FIELD_PTR_HEAD_UINT"
case opStructFieldPtrHeadUint8:
return "STRUCT_FIELD_PTR_HEAD_UINT8"
case opStructFieldPtrHeadUint16:
return "STRUCT_FIELD_PTR_HEAD_UINT16"
case opStructFieldPtrHeadUint32:
return "STRUCT_FIELD_PTR_HEAD_UINT32"
case opStructFieldPtrHeadUint64:
return "STRUCT_FIELD_PTR_HEAD_UINT64"
case opStructFieldPtrHeadFloat32:
return "STRUCT_FIELD_PTR_HEAD_FLOAT32"
case opStructFieldPtrHeadFloat64:
return "STRUCT_FIELD_PTR_HEAD_FLOAT64"
2020-04-29 19:44:48 +03:00
case opStructFieldPtrHeadString:
return "STRUCT_FIELD_PTR_HEAD_STRING"
2020-04-30 05:56:56 +03:00
case opStructFieldPtrHeadBool:
return "STRUCT_FIELD_PTR_HEAD_BOOL"
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadIndent:
return "STRUCT_FIELD_PTR_HEAD_INDENT"
case opStructFieldPtrHeadIntIndent:
return "STRUCT_FIELD_PTR_HEAD_INT_INDENT"
case opStructFieldPtrHeadInt8Indent:
return "STRUCT_FIELD_PTR_HEAD_INT8_INDENT"
case opStructFieldPtrHeadInt16Indent:
return "STRUCT_FIELD_PTR_HEAD_INT16_INDENT"
case opStructFieldPtrHeadInt32Indent:
return "STRUCT_FIELD_PTR_HEAD_INT32_INDENT"
case opStructFieldPtrHeadInt64Indent:
return "STRUCT_FIELD_PTR_HEAD_INT64_INDENT"
case opStructFieldPtrHeadUintIndent:
return "STRUCT_FIELD_PTR_HEAD_UINT_INDENT"
case opStructFieldPtrHeadUint8Indent:
return "STRUCT_FIELD_PTR_HEAD_UINT8_INDENT"
case opStructFieldPtrHeadUint16Indent:
return "STRUCT_FIELD_PTR_HEAD_UINT16_INDENT"
case opStructFieldPtrHeadUint32Indent:
return "STRUCT_FIELD_PTR_HEAD_UINT32_INDENT"
case opStructFieldPtrHeadUint64Indent:
return "STRUCT_FIELD_PTR_HEAD_UINT64_INDENT"
case opStructFieldPtrHeadFloat32Indent:
return "STRUCT_FIELD_PTR_HEAD_FLOAT32_INDENT"
case opStructFieldPtrHeadFloat64Indent:
return "STRUCT_FIELD_PTR_HEAD_FLOAT64_INDENT"
case opStructFieldPtrHeadStringIndent:
return "STRUCT_FIELD_PTR_HEAD_STRING_INDENT"
case opStructFieldPtrHeadBoolIndent:
return "STRUCT_FIELD_PTR_HEAD_BOOL_INDENT"
2020-05-01 07:12:01 +03:00
case opStructFieldPtrHeadOmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_OMIT_EMPTY"
case opStructFieldPtrHeadIntOmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_INT_OMIT_EMPTY"
case opStructFieldPtrHeadInt8OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_INT8_OMIT_EMPTY"
case opStructFieldPtrHeadInt16OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_INT16_OMIT_EMPTY"
case opStructFieldPtrHeadInt32OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_INT32_OMIT_EMPTY"
case opStructFieldPtrHeadInt64OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_INT64_OMIT_EMPTY"
case opStructFieldPtrHeadUintOmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_UINT_OMIT_EMPTY"
case opStructFieldPtrHeadUint8OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_UINT8_OMIT_EMPTY"
case opStructFieldPtrHeadUint16OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_UINT16_OMIT_EMPTY"
case opStructFieldPtrHeadUint32OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_UINT32_OMIT_EMPTY"
case opStructFieldPtrHeadUint64OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_UINT64_OMIT_EMPTY"
case opStructFieldPtrHeadFloat32OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_FLOAT32_OMIT_EMPTY"
case opStructFieldPtrHeadFloat64OmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_FLOAT64_OMIT_EMPTY"
case opStructFieldPtrHeadStringOmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_STRING_OMIT_EMPTY"
case opStructFieldPtrHeadBoolOmitEmpty:
return "STRUCT_FIELD_PTR_HEAD_BOOL_OMIT_EMPTY"
2020-05-02 17:35:41 +03:00
case opStructFieldPtrHeadOmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadIntOmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_INT_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadInt8OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_INT8_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadInt16OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_INT16_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadInt32OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_INT32_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadInt64OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_INT64_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadUintOmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_UINT_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadUint8OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_UINT8_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadUint16OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_UINT16_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadUint32OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_UINT32_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadUint64OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_UINT64_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadFloat32OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_FLOAT32_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadFloat64OmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_FLOAT64_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadStringOmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_STRING_OMIT_EMPTY_INDENT"
case opStructFieldPtrHeadBoolOmitEmptyIndent:
return "STRUCT_FIELD_PTR_HEAD_BOOL_OMIT_EMPTY_INDENT"
2020-04-29 18:31:50 +03:00
case opStructField:
return "STRUCT_FIELD"
case opStructFieldInt:
return "STRUCT_FIELD_INT"
2020-04-30 05:56:56 +03:00
case opStructFieldInt8:
return "STRUCT_FIELD_INT8"
case opStructFieldInt16:
return "STRUCT_FIELD_INT16"
case opStructFieldInt32:
return "STRUCT_FIELD_INT32"
case opStructFieldInt64:
return "STRUCT_FIELD_INT64"
case opStructFieldUint:
return "STRUCT_FIELD_UINT"
case opStructFieldUint8:
return "STRUCT_FIELD_UINT8"
case opStructFieldUint16:
return "STRUCT_FIELD_UINT16"
case opStructFieldUint32:
return "STRUCT_FIELD_UINT32"
case opStructFieldUint64:
return "STRUCT_FIELD_UINT64"
case opStructFieldFloat32:
return "STRUCT_FIELD_FLOAT32"
case opStructFieldFloat64:
return "STRUCT_FIELD_FLOAT64"
2020-04-29 18:31:50 +03:00
case opStructFieldString:
return "STRUCT_FIELD_STRING"
2020-04-30 05:56:56 +03:00
case opStructFieldBool:
return "STRUCT_FIELD_BOOL"
2020-05-01 07:12:01 +03:00
2020-05-02 17:35:41 +03:00
case opStructFieldIndent:
return "STRUCT_FIELD_INDENT"
case opStructFieldIntIndent:
return "STRUCT_FIELD_INT_INDENT"
case opStructFieldInt8Indent:
return "STRUCT_FIELD_INT8_INDENT"
case opStructFieldInt16Indent:
return "STRUCT_FIELD_INT16_INDENT"
case opStructFieldInt32Indent:
return "STRUCT_FIELD_INT32_INDENT"
case opStructFieldInt64Indent:
return "STRUCT_FIELD_INT64_INDENT"
case opStructFieldUintIndent:
return "STRUCT_FIELD_UINT_INDENT"
case opStructFieldUint8Indent:
return "STRUCT_FIELD_UINT8_INDENT"
case opStructFieldUint16Indent:
return "STRUCT_FIELD_UINT16_INDENT"
case opStructFieldUint32Indent:
return "STRUCT_FIELD_UINT32_INDENT"
case opStructFieldUint64Indent:
return "STRUCT_FIELD_UINT64_INDENT"
case opStructFieldFloat32Indent:
return "STRUCT_FIELD_FLOAT32_INDENT"
case opStructFieldFloat64Indent:
return "STRUCT_FIELD_FLOAT64_INDENT"
case opStructFieldStringIndent:
return "STRUCT_FIELD_STRING_INDENT"
case opStructFieldBoolIndent:
return "STRUCT_FIELD_BOOL_INDENT"
2020-05-01 07:12:01 +03:00
case opStructFieldOmitEmpty:
return "STRUCT_FIELD_OMIT_EMPTY"
case opStructFieldIntOmitEmpty:
return "STRUCT_FIELD_INT_OMIT_EMPTY"
case opStructFieldInt8OmitEmpty:
return "STRUCT_FIELD_INT8_OMIT_EMPTY"
case opStructFieldInt16OmitEmpty:
return "STRUCT_FIELD_INT16_OMIT_EMPTY"
case opStructFieldInt32OmitEmpty:
return "STRUCT_FIELD_INT32_OMIT_EMPTY"
case opStructFieldInt64OmitEmpty:
return "STRUCT_FIELD_INT64_OMIT_EMPTY"
case opStructFieldUintOmitEmpty:
return "STRUCT_FIELD_UINT_OMIT_EMPTY"
case opStructFieldUint8OmitEmpty:
return "STRUCT_FIELD_UINT8_OMIT_EMPTY"
case opStructFieldUint16OmitEmpty:
return "STRUCT_FIELD_UINT16_OMIT_EMPTY"
case opStructFieldUint32OmitEmpty:
return "STRUCT_FIELD_UINT32_OMIT_EMPTY"
case opStructFieldUint64OmitEmpty:
return "STRUCT_FIELD_UINT64_OMIT_EMPTY"
case opStructFieldFloat32OmitEmpty:
return "STRUCT_FIELD_FLOAT32_OMIT_EMPTY"
case opStructFieldFloat64OmitEmpty:
return "STRUCT_FIELD_FLOAT64_OMIT_EMPTY"
case opStructFieldStringOmitEmpty:
return "STRUCT_FIELD_STRING_OMIT_EMPTY"
case opStructFieldBoolOmitEmpty:
return "STRUCT_FIELD_BOOL_OMIT_EMPTY"
2020-05-02 17:35:41 +03:00
case opStructFieldOmitEmptyIndent:
return "STRUCT_FIELD_OMIT_EMPTY_INDENT"
case opStructFieldIntOmitEmptyIndent:
return "STRUCT_FIELD_INT_OMIT_EMPTY_INDENT"
case opStructFieldInt8OmitEmptyIndent:
return "STRUCT_FIELD_INT8_OMIT_EMPTY_INDENT"
case opStructFieldInt16OmitEmptyIndent:
return "STRUCT_FIELD_INT16_OMIT_EMPTY_INDENT"
case opStructFieldInt32OmitEmptyIndent:
return "STRUCT_FIELD_INT32_OMIT_EMPTY_INDENT"
case opStructFieldInt64OmitEmptyIndent:
return "STRUCT_FIELD_INT64_OMIT_EMPTY_INDENT"
case opStructFieldUintOmitEmptyIndent:
return "STRUCT_FIELD_UINT_OMIT_EMPTY_INDENT"
case opStructFieldUint8OmitEmptyIndent:
return "STRUCT_FIELD_UINT8_OMIT_EMPTY_INDENT"
case opStructFieldUint16OmitEmptyIndent:
return "STRUCT_FIELD_UINT16_OMIT_EMPTY_INDENT"
case opStructFieldUint32OmitEmptyIndent:
return "STRUCT_FIELD_UINT32_OMIT_EMPTY_INDENT"
case opStructFieldUint64OmitEmptyIndent:
return "STRUCT_FIELD_UINT64_OMIT_EMPTY_INDENT"
case opStructFieldFloat32OmitEmptyIndent:
return "STRUCT_FIELD_FLOAT32_OMIT_EMPTY_INDENT"
case opStructFieldFloat64OmitEmptyIndent:
return "STRUCT_FIELD_FLOAT64_OMIT_EMPTY_INDENT"
case opStructFieldStringOmitEmptyIndent:
return "STRUCT_FIELD_STRING_OMIT_EMPTY_INDENT"
case opStructFieldBoolOmitEmptyIndent:
return "STRUCT_FIELD_BOOL_OMIT_EMPTY_INDENT"
2020-04-29 18:31:50 +03:00
case opStructEnd:
return "STRUCT_END"
2020-05-02 17:35:41 +03:00
case opStructEndIndent:
return "STRUCT_END_INDENT"
2020-04-29 18:31:50 +03:00
}
return ""
}
type opcodeHeader struct {
2020-05-02 17:35:41 +03:00
op opType
typ *rtype
ptr uintptr
indent int
next *opcode
2020-04-29 18:31:50 +03:00
}
type opcode struct {
*opcodeHeader
}
2020-05-02 17:35:41 +03:00
func newOpCode(op opType, typ *rtype, indent int, next *opcode) *opcode {
2020-04-29 18:31:50 +03:00
return &opcode{
opcodeHeader: &opcodeHeader{
2020-05-02 17:35:41 +03:00
op: op,
typ: typ,
indent: indent,
next: next,
2020-04-29 18:31:50 +03:00
},
}
}
2020-05-02 17:35:41 +03:00
func newEndOp(indent int) *opcode {
return newOpCode(opEnd, nil, indent, nil)
2020-04-29 18:31:50 +03:00
}
func (c *opcode) beforeLastCode() *opcode {
code := c
for {
var nextCode *opcode
switch code.op {
2020-05-02 17:35:41 +03:00
case opArrayElem, opArrayElemIndent:
nextCode = code.toArrayElemCode().end
2020-05-02 17:35:41 +03:00
case opSliceElem, opSliceElemIndent:
2020-04-29 18:31:50 +03:00
nextCode = code.toSliceElemCode().end
2020-05-02 17:35:41 +03:00
case opMapKey, opMapKeyIndent:
nextCode = code.toMapKeyCode().end
default:
2020-04-29 18:31:50 +03:00
nextCode = code.next
}
if nextCode.op == opEnd {
return code
}
code = nextCode
}
return nil
}
func (c *opcode) dump() string {
codes := []string{}
for code := c; code.op != opEnd; {
2020-05-02 17:35:41 +03:00
indent := strings.Repeat(" ", code.indent)
codes = append(codes, fmt.Sprintf("%s%s", indent, code.op))
switch code.op {
2020-05-02 17:35:41 +03:00
case opArrayElem, opArrayElemIndent:
code = code.toArrayElemCode().end
2020-05-02 17:35:41 +03:00
case opSliceElem, opSliceElemIndent:
2020-04-29 18:31:50 +03:00
code = code.toSliceElemCode().end
2020-05-02 17:35:41 +03:00
case opMapKey, opMapKeyIndent:
code = code.toMapKeyCode().end
default:
2020-04-29 18:31:50 +03:00
code = code.next
}
}
return strings.Join(codes, "\n")
}
2020-04-29 19:44:48 +03:00
func (c *opcode) toSliceHeaderCode() *sliceHeaderCode {
return (*sliceHeaderCode)(unsafe.Pointer(c))
2020-04-29 18:31:50 +03:00
}
2020-04-29 19:44:48 +03:00
func (c *opcode) toSliceElemCode() *sliceElemCode {
return (*sliceElemCode)(unsafe.Pointer(c))
2020-04-29 18:31:50 +03:00
}
func (c *opcode) toArrayHeaderCode() *arrayHeaderCode {
return (*arrayHeaderCode)(unsafe.Pointer(c))
}
func (c *opcode) toArrayElemCode() *arrayElemCode {
return (*arrayElemCode)(unsafe.Pointer(c))
}
2020-04-29 18:31:50 +03:00
func (c *opcode) toStructFieldCode() *structFieldCode {
return (*structFieldCode)(unsafe.Pointer(c))
}
func (c *opcode) toMapHeadCode() *mapHeaderCode {
return (*mapHeaderCode)(unsafe.Pointer(c))
}
func (c *opcode) toMapKeyCode() *mapKeyCode {
return (*mapKeyCode)(unsafe.Pointer(c))
}
func (c *opcode) toMapValueCode() *mapValueCode {
return (*mapValueCode)(unsafe.Pointer(c))
}
2020-04-29 19:44:48 +03:00
type sliceHeaderCode struct {
*opcodeHeader
elem *sliceElemCode
end *opcode
}
2020-05-02 17:35:41 +03:00
func newSliceHeaderCode(indent int) *sliceHeaderCode {
2020-04-29 19:44:48 +03:00
return &sliceHeaderCode{
opcodeHeader: &opcodeHeader{
2020-05-02 17:35:41 +03:00
op: opSliceHead,
indent: indent,
2020-04-29 19:44:48 +03:00
},
}
}
2020-04-29 18:31:50 +03:00
type sliceElemCode struct {
*opcodeHeader
idx uintptr
len uintptr
size uintptr
data uintptr
end *opcode
}
func (c *sliceElemCode) set(header *reflect.SliceHeader) {
c.idx = uintptr(0)
c.len = uintptr(header.Len)
c.data = header.Data
}
type arrayHeaderCode struct {
*opcodeHeader
len uintptr
elem *arrayElemCode
end *opcode
}
2020-05-02 17:35:41 +03:00
func newArrayHeaderCode(indent, alen int) *arrayHeaderCode {
return &arrayHeaderCode{
opcodeHeader: &opcodeHeader{
2020-05-02 17:35:41 +03:00
op: opArrayHead,
indent: indent,
},
len: uintptr(alen),
}
}
type arrayElemCode struct {
*opcodeHeader
idx uintptr
len uintptr
size uintptr
end *opcode
}
2020-04-29 18:31:50 +03:00
type structFieldCode struct {
*opcodeHeader
2020-04-30 05:56:56 +03:00
key []byte
2020-04-29 18:31:50 +03:00
offset uintptr
nextField *opcode
2020-04-29 19:44:48 +03:00
end *opcode
2020-04-29 18:31:50 +03:00
}
type mapHeaderCode struct {
*opcodeHeader
key *mapKeyCode
value *mapValueCode
end *opcode
}
type mapKeyCode struct {
*opcodeHeader
idx int
len int
iter unsafe.Pointer
end *opcode
}
func (c *mapKeyCode) set(len int, iter unsafe.Pointer) {
c.idx = 0
c.len = len
c.iter = iter
}
type mapValueCode struct {
*opcodeHeader
iter unsafe.Pointer
}
func (c *mapValueCode) set(iter unsafe.Pointer) {
c.iter = iter
}
2020-05-02 17:35:41 +03:00
func newMapHeaderCode(typ *rtype, indent int) *mapHeaderCode {
return &mapHeaderCode{
opcodeHeader: &opcodeHeader{
2020-05-02 17:35:41 +03:00
op: opMapHead,
typ: typ,
indent: indent,
},
}
}
2020-05-02 17:35:41 +03:00
func newMapKeyCode(indent int) *mapKeyCode {
return &mapKeyCode{
opcodeHeader: &opcodeHeader{
2020-05-02 17:35:41 +03:00
op: opMapKey,
indent: indent,
},
}
}
2020-05-02 17:35:41 +03:00
func newMapValueCode(indent int) *mapValueCode {
return &mapValueCode{
opcodeHeader: &opcodeHeader{
2020-05-02 17:35:41 +03:00
op: opMapValue,
indent: indent,
},
}
}