migrate go version to 1.17 (#203)

* migrate go version to 1.17

* update contributing
This commit is contained in:
tobi 2021-09-10 14:42:14 +02:00 committed by GitHub
commit f2e5bedea6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
282 changed files with 11863 additions and 12600 deletions

View file

@ -1,6 +1,7 @@
package encoder
import (
"context"
"encoding"
"encoding/json"
"fmt"
@ -13,13 +14,18 @@ import (
"github.com/goccy/go-json/internal/runtime"
)
type marshalerContext interface {
MarshalJSON(context.Context) ([]byte, error)
}
var (
marshalJSONType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
marshalTextType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
jsonNumberType = reflect.TypeOf(json.Number(""))
cachedOpcodeSets []*OpcodeSet
cachedOpcodeMap unsafe.Pointer // map[uintptr]*OpcodeSet
typeAddr *runtime.TypeAddr
marshalJSONType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
marshalJSONContextType = reflect.TypeOf((*marshalerContext)(nil)).Elem()
marshalTextType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
jsonNumberType = reflect.TypeOf(json.Number(""))
cachedOpcodeSets []*OpcodeSet
cachedOpcodeMap unsafe.Pointer // map[uintptr]*OpcodeSet
typeAddr *runtime.TypeAddr
)
func init() {
@ -55,19 +61,36 @@ func compileToGetCodeSetSlowPath(typeptr uintptr) (*OpcodeSet, error) {
// noescape trick for header.typ ( reflect.*rtype )
copiedType := *(**runtime.Type)(unsafe.Pointer(&typeptr))
code, err := compileHead(&compileContext{
noescapeKeyCode, err := compileHead(&compileContext{
typ: copiedType,
structTypeToCompiledCode: map[uintptr]*CompiledCode{},
})
if err != nil {
return nil, err
}
code = copyOpcode(code)
codeLength := code.TotalLength()
escapeKeyCode, err := compileHead(&compileContext{
typ: copiedType,
structTypeToCompiledCode: map[uintptr]*CompiledCode{},
escapeKey: true,
})
if err != nil {
return nil, err
}
noescapeKeyCode = copyOpcode(noescapeKeyCode)
escapeKeyCode = copyOpcode(escapeKeyCode)
setTotalLengthToInterfaceOp(noescapeKeyCode)
setTotalLengthToInterfaceOp(escapeKeyCode)
interfaceNoescapeKeyCode := copyToInterfaceOpcode(noescapeKeyCode)
interfaceEscapeKeyCode := copyToInterfaceOpcode(escapeKeyCode)
codeLength := noescapeKeyCode.TotalLength()
codeSet := &OpcodeSet{
Type: copiedType,
Code: code,
CodeLength: codeLength,
Type: copiedType,
NoescapeKeyCode: noescapeKeyCode,
EscapeKeyCode: escapeKeyCode,
InterfaceNoescapeKeyCode: interfaceNoescapeKeyCode,
InterfaceEscapeKeyCode: interfaceEscapeKeyCode,
CodeLength: codeLength,
EndCode: ToEndCode(interfaceNoescapeKeyCode),
}
storeOpcodeSet(typeptr, codeSet, opcodeMap)
return codeSet, nil
@ -100,7 +123,7 @@ func compileHead(ctx *compileContext) (*Opcode, error) {
elem := typ.Elem()
if elem.Kind() == reflect.Uint8 {
p := runtime.PtrTo(elem)
if !p.Implements(marshalJSONType) && !p.Implements(marshalTextType) {
if !implementsMarshalJSONType(p) && !p.Implements(marshalTextType) {
if isPtr {
return compileBytesPtr(ctx)
}
@ -246,6 +269,7 @@ func linkRecursiveCode(c *Opcode) {
continue
}
code.Jmp.Code = copyOpcode(code.Jmp.Code)
c := code.Jmp.Code
c.End.Next = newEndOp(&compileContext{})
c.Op = c.Op.PtrHeadToHead()
@ -258,8 +282,8 @@ func linkRecursiveCode(c *Opcode) {
lastCode.Length = lastCode.Idx + 2*uintptrSize
// extend length to alloc slot for elemIdx + length
totalLength := uintptr(code.TotalLength() + 2)
nextTotalLength := uintptr(c.TotalLength() + 2)
totalLength := uintptr(code.TotalLength() + 3)
nextTotalLength := uintptr(c.TotalLength() + 3)
c.End.Next.Op = OpRecursiveEnd
@ -268,6 +292,7 @@ func linkRecursiveCode(c *Opcode) {
code.Jmp.Linked = true
linkRecursiveCode(code.Jmp.Code)
code = code.Next
continue
}
@ -328,14 +353,14 @@ func optimizeStructEnd(c *Opcode) {
}
func implementsMarshalJSON(typ *runtime.Type) bool {
if !typ.Implements(marshalJSONType) {
if !implementsMarshalJSONType(typ) {
return false
}
if typ.Kind() != reflect.Ptr {
return true
}
// type kind is reflect.Ptr
if !typ.Elem().Implements(marshalJSONType) {
if !implementsMarshalJSONType(typ.Elem()) {
return true
}
// needs to dereference
@ -372,7 +397,7 @@ func compile(ctx *compileContext, isPtr bool) (*Opcode, error) {
elem := typ.Elem()
if elem.Kind() == reflect.Uint8 {
p := runtime.PtrTo(elem)
if !p.Implements(marshalJSONType) && !p.Implements(marshalTextType) {
if !implementsMarshalJSONType(p) && !p.Implements(marshalTextType) {
return compileBytes(ctx)
}
}
@ -474,8 +499,6 @@ func compileKey(ctx *compileContext) (*Opcode, error) {
switch typ.Kind() {
case reflect.Ptr:
return compilePtr(ctx)
case reflect.Interface:
return compileInterface(ctx)
case reflect.String:
return compileString(ctx)
case reflect.Int:
@ -517,10 +540,17 @@ func compilePtr(ctx *compileContext) (*Opcode, error) {
func compileMarshalJSON(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpMarshalJSON)
typ := ctx.typ
if !typ.Implements(marshalJSONType) && runtime.PtrTo(typ).Implements(marshalJSONType) {
code.AddrForMarshaler = true
if isPtrMarshalJSONType(typ) {
code.Flags |= AddrForMarshalerFlags
}
if typ.Implements(marshalJSONContextType) || runtime.PtrTo(typ).Implements(marshalJSONContextType) {
code.Flags |= MarshalerContextFlags
}
if isNilableType(typ) {
code.Flags |= IsNilableTypeFlags
} else {
code.Flags &= ^IsNilableTypeFlags
}
code.IsNilableType = isNilableType(typ)
ctx.incIndex()
return code, nil
}
@ -529,9 +559,13 @@ func compileMarshalText(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpMarshalText)
typ := ctx.typ
if !typ.Implements(marshalTextType) && runtime.PtrTo(typ).Implements(marshalTextType) {
code.AddrForMarshaler = true
code.Flags |= AddrForMarshalerFlags
}
if isNilableType(typ) {
code.Flags |= IsNilableTypeFlags
} else {
code.Flags &= ^IsNilableTypeFlags
}
code.IsNilableType = isNilableType(typ)
ctx.incIndex()
return code, nil
}
@ -540,7 +574,7 @@ const intSize = 32 << (^uint(0) >> 63)
func compileInt(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpInt)
code.setMaskAndRshiftNum(intSize)
code.NumBitSize = intSize
ctx.incIndex()
return code, nil
}
@ -556,7 +590,7 @@ func compileIntPtr(ctx *compileContext) (*Opcode, error) {
func compileInt8(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpInt)
code.setMaskAndRshiftNum(8)
code.NumBitSize = 8
ctx.incIndex()
return code, nil
}
@ -572,7 +606,7 @@ func compileInt8Ptr(ctx *compileContext) (*Opcode, error) {
func compileInt16(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpInt)
code.setMaskAndRshiftNum(16)
code.NumBitSize = 16
ctx.incIndex()
return code, nil
}
@ -588,7 +622,7 @@ func compileInt16Ptr(ctx *compileContext) (*Opcode, error) {
func compileInt32(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpInt)
code.setMaskAndRshiftNum(32)
code.NumBitSize = 32
ctx.incIndex()
return code, nil
}
@ -604,7 +638,7 @@ func compileInt32Ptr(ctx *compileContext) (*Opcode, error) {
func compileInt64(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpInt)
code.setMaskAndRshiftNum(64)
code.NumBitSize = 64
ctx.incIndex()
return code, nil
}
@ -620,7 +654,7 @@ func compileInt64Ptr(ctx *compileContext) (*Opcode, error) {
func compileUint(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUint)
code.setMaskAndRshiftNum(intSize)
code.NumBitSize = intSize
ctx.incIndex()
return code, nil
}
@ -636,7 +670,7 @@ func compileUintPtr(ctx *compileContext) (*Opcode, error) {
func compileUint8(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUint)
code.setMaskAndRshiftNum(8)
code.NumBitSize = 8
ctx.incIndex()
return code, nil
}
@ -652,7 +686,7 @@ func compileUint8Ptr(ctx *compileContext) (*Opcode, error) {
func compileUint16(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUint)
code.setMaskAndRshiftNum(16)
code.NumBitSize = 16
ctx.incIndex()
return code, nil
}
@ -668,7 +702,7 @@ func compileUint16Ptr(ctx *compileContext) (*Opcode, error) {
func compileUint32(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUint)
code.setMaskAndRshiftNum(32)
code.NumBitSize = 32
ctx.incIndex()
return code, nil
}
@ -684,7 +718,7 @@ func compileUint32Ptr(ctx *compileContext) (*Opcode, error) {
func compileUint64(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUint)
code.setMaskAndRshiftNum(64)
code.NumBitSize = 64
ctx.incIndex()
return code, nil
}
@ -700,70 +734,70 @@ func compileUint64Ptr(ctx *compileContext) (*Opcode, error) {
func compileIntString(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpIntString)
code.setMaskAndRshiftNum(intSize)
code.NumBitSize = intSize
ctx.incIndex()
return code, nil
}
func compileInt8String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpIntString)
code.setMaskAndRshiftNum(8)
code.NumBitSize = 8
ctx.incIndex()
return code, nil
}
func compileInt16String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpIntString)
code.setMaskAndRshiftNum(16)
code.NumBitSize = 16
ctx.incIndex()
return code, nil
}
func compileInt32String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpIntString)
code.setMaskAndRshiftNum(32)
code.NumBitSize = 32
ctx.incIndex()
return code, nil
}
func compileInt64String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpIntString)
code.setMaskAndRshiftNum(64)
code.NumBitSize = 64
ctx.incIndex()
return code, nil
}
func compileUintString(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUintString)
code.setMaskAndRshiftNum(intSize)
code.NumBitSize = intSize
ctx.incIndex()
return code, nil
}
func compileUint8String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUintString)
code.setMaskAndRshiftNum(8)
code.NumBitSize = 8
ctx.incIndex()
return code, nil
}
func compileUint16String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUintString)
code.setMaskAndRshiftNum(16)
code.NumBitSize = 16
ctx.incIndex()
return code, nil
}
func compileUint32String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUintString)
code.setMaskAndRshiftNum(32)
code.NumBitSize = 32
ctx.incIndex()
return code, nil
}
func compileUint64String(ctx *compileContext) (*Opcode, error) {
code := newOpCode(ctx, OpUintString)
code.setMaskAndRshiftNum(64)
code.NumBitSize = 64
ctx.incIndex()
return code, nil
}
@ -879,7 +913,7 @@ func compileSlice(ctx *compileContext) (*Opcode, error) {
if err != nil {
return nil, err
}
code.Indirect = true
code.Flags |= IndirectFlags
// header => opcode => elem => end
// ^ |
@ -891,7 +925,6 @@ func compileSlice(ctx *compileContext) (*Opcode, error) {
end := newOpCode(ctx, OpSliceEnd)
ctx.incIndex()
header.Elem = elemCode
header.End = end
header.Next = code
code.BeforeLastCode().Next = (*Opcode)(unsafe.Pointer(elemCode))
@ -903,7 +936,7 @@ func compileSlice(ctx *compileContext) (*Opcode, error) {
func compileListElem(ctx *compileContext) (*Opcode, error) {
typ := ctx.typ
switch {
case !typ.Implements(marshalJSONType) && runtime.PtrTo(typ).Implements(marshalJSONType):
case isPtrMarshalJSONType(typ):
return compileMarshalJSON(ctx)
case !typ.Implements(marshalTextType) && runtime.PtrTo(typ).Implements(marshalTextType):
return compileMarshalText(ctx)
@ -934,7 +967,7 @@ func compileArray(ctx *compileContext) (*Opcode, error) {
if err != nil {
return nil, err
}
code.Indirect = true
code.Flags |= IndirectFlags
// header => opcode => elem => end
// ^ |
// |________|
@ -945,7 +978,6 @@ func compileArray(ctx *compileContext) (*Opcode, error) {
end := newOpCode(ctx, OpArrayEnd)
ctx.incIndex()
header.Elem = elemCode
header.End = end
header.Next = code
code.BeforeLastCode().Next = (*Opcode)(unsafe.Pointer(elemCode))
@ -976,16 +1008,13 @@ func compileMap(ctx *compileContext) (*Opcode, error) {
if err != nil {
return nil, err
}
valueCode.Indirect = true
valueCode.Flags |= IndirectFlags
key := newMapKeyCode(ctx, header)
ctx.incIndex()
ctx = ctx.decIndent()
header.MapKey = key
header.MapValue = value
end := newMapEndCode(ctx, header)
ctx.incIndex()
@ -1052,8 +1081,7 @@ func compiledCode(ctx *compileContext) *Opcode {
func structHeader(ctx *compileContext, fieldCode *Opcode, valueCode *Opcode, tag *runtime.StructTag) *Opcode {
op := optimizeStructHeader(valueCode, tag)
fieldCode.Op = op
fieldCode.Mask = valueCode.Mask
fieldCode.RshiftNum = valueCode.RshiftNum
fieldCode.NumBitSize = valueCode.NumBitSize
fieldCode.PtrNum = valueCode.PtrNum
if op.IsMultipleOpHead() {
return valueCode.BeforeLastCode()
@ -1065,9 +1093,8 @@ func structHeader(ctx *compileContext, fieldCode *Opcode, valueCode *Opcode, tag
func structField(ctx *compileContext, fieldCode *Opcode, valueCode *Opcode, tag *runtime.StructTag) *Opcode {
op := optimizeStructField(valueCode, tag)
fieldCode.Op = op
fieldCode.NumBitSize = valueCode.NumBitSize
fieldCode.PtrNum = valueCode.PtrNum
fieldCode.Mask = valueCode.Mask
fieldCode.RshiftNum = valueCode.RshiftNum
if op.IsMultipleOpField() {
return valueCode.BeforeLastCode()
}
@ -1082,7 +1109,7 @@ func isNotExistsField(head *Opcode) bool {
if head.Op != OpStructHead {
return false
}
if !head.AnonymousHead {
if (head.Flags & AnonymousHeadFlags) == 0 {
return false
}
if head.Next == nil {
@ -1117,7 +1144,7 @@ func optimizeAnonymousFields(head *Opcode) {
if isNotExistsField(code.Next) {
code.Next = code.NextField
diff := code.Next.DisplayIdx - code.DisplayIdx
for i := 0; i < diff; i++ {
for i := uint32(0); i < diff; i++ {
code.Next.decOpcodeIndex()
}
linkPrevToNextField(code, removedFields)
@ -1147,20 +1174,20 @@ func anonymousStructFieldPairMap(tags runtime.StructTags, named string, valueCod
isHeadOp := strings.Contains(f.Op.String(), "Head")
if existsKey && f.Next != nil && strings.Contains(f.Next.Op.String(), "Recursive") {
// through
} else if isHeadOp && !f.AnonymousHead {
} else if isHeadOp && (f.Flags&AnonymousHeadFlags) == 0 {
if existsKey {
// TODO: need to remove this head
f.Op = OpStructHead
f.AnonymousKey = true
f.AnonymousHead = true
f.Flags |= AnonymousKeyFlags
f.Flags |= AnonymousHeadFlags
} else if named == "" {
f.AnonymousHead = true
f.Flags |= AnonymousHeadFlags
}
} else if named == "" && f.Op == OpStructEnd {
f.Op = OpStructAnonymousEnd
} else if existsKey {
diff := f.NextField.DisplayIdx - f.DisplayIdx
for i := 0; i < diff; i++ {
for i := uint32(0); i < diff; i++ {
f.NextField.decOpcodeIndex()
}
linkPrevToNextField(f, removedFields)
@ -1179,7 +1206,7 @@ func anonymousStructFieldPairMap(tags runtime.StructTags, named string, valueCod
anonymousFields[key] = append(anonymousFields[key], structFieldPair{
prevField: prevAnonymousField,
curField: f,
isTaggedKey: f.IsTaggedKey,
isTaggedKey: (f.Flags & IsTaggedKeyFlags) != 0,
})
if f.Next != nil && f.NextField != f.Next && f.Next.Op.CodeType() == CodeStructField {
for k, v := range anonymousFieldPairRecursively(named, f.Next) {
@ -1200,12 +1227,12 @@ func anonymousFieldPairRecursively(named string, valueCode *Opcode) map[string][
f := valueCode
var prevAnonymousField *Opcode
for {
if f.DisplayKey != "" && f.AnonymousHead {
if f.DisplayKey != "" && (f.Flags&AnonymousHeadFlags) != 0 {
key := fmt.Sprintf("%s.%s", named, f.DisplayKey)
anonymousFields[key] = append(anonymousFields[key], structFieldPair{
prevField: prevAnonymousField,
curField: f,
isTaggedKey: f.IsTaggedKey,
isTaggedKey: (f.Flags & IsTaggedKeyFlags) != 0,
})
if f.Next != nil && f.NextField != f.Next && f.Next.Op.CodeType() == CodeStructField {
for k, v := range anonymousFieldPairRecursively(named, f.Next) {
@ -1238,11 +1265,11 @@ func optimizeConflictAnonymousFields(anonymousFields map[string][]structFieldPai
if fieldPair.prevField == nil {
// head operation
fieldPair.curField.Op = OpStructHead
fieldPair.curField.AnonymousHead = true
fieldPair.curField.AnonymousKey = true
fieldPair.curField.Flags |= AnonymousHeadFlags
fieldPair.curField.Flags |= AnonymousKeyFlags
} else {
diff := fieldPair.curField.NextField.DisplayIdx - fieldPair.curField.DisplayIdx
for i := 0; i < diff; i++ {
for i := uint32(0); i < diff; i++ {
fieldPair.curField.NextField.decOpcodeIndex()
}
removedFields[fieldPair.curField] = struct{}{}
@ -1258,12 +1285,12 @@ func optimizeConflictAnonymousFields(anonymousFields map[string][]structFieldPai
if fieldPair.prevField == nil {
// head operation
fieldPair.curField.Op = OpStructHead
fieldPair.curField.AnonymousHead = true
fieldPair.curField.AnonymousKey = true
fieldPair.curField.Flags |= AnonymousHeadFlags
fieldPair.curField.Flags |= AnonymousKeyFlags
} else {
diff := fieldPair.curField.NextField.DisplayIdx - fieldPair.curField.DisplayIdx
removedFields[fieldPair.curField] = struct{}{}
for i := 0; i < diff; i++ {
for i := uint32(0); i < diff; i++ {
fieldPair.curField.NextField.decOpcodeIndex()
}
linkPrevToNextField(fieldPair.curField, removedFields)
@ -1273,7 +1300,7 @@ func optimizeConflictAnonymousFields(anonymousFields map[string][]structFieldPai
}
} else {
for _, fieldPair := range taggedPairs {
fieldPair.curField.IsTaggedKey = false
fieldPair.curField.Flags &= ^IsTaggedKeyFlags
}
}
}
@ -1390,7 +1417,7 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
valueCode = code
}
if field.Anonymous {
if field.Anonymous && !tag.IsTaggedKey {
tagKey := ""
if tag.IsTaggedKey {
tagKey = tag.Key
@ -1398,50 +1425,76 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
for k, v := range anonymousStructFieldPairMap(tags, tagKey, valueCode) {
anonymousFields[k] = append(anonymousFields[k], v...)
}
valueCode.decIndent()
// fix issue144
if !(isPtr && strings.Contains(valueCode.Op.String(), "Marshal")) {
valueCode.Indirect = indirect
if indirect {
valueCode.Flags |= IndirectFlags
} else {
valueCode.Flags &= ^IndirectFlags
}
}
} else {
if indirect {
// if parent is indirect type, set child indirect property to true
valueCode.Indirect = indirect
valueCode.Flags |= IndirectFlags
} else {
// if parent is not indirect type and child have only one field, set child indirect property to false
if i == 0 && valueCode.NextField != nil && valueCode.NextField.Op == OpStructEnd {
valueCode.Indirect = indirect
// if parent is not indirect type, set child indirect property to false.
// but if parent's indirect is false and isPtr is true, then indirect must be true.
// Do this only if indirectConversion is enabled at the end of compileStruct.
if i == 0 {
valueCode.Flags &= ^IndirectFlags
}
}
}
key := fmt.Sprintf(`"%s":`, tag.Key)
escapedKey := fmt.Sprintf(`%s:`, string(AppendEscapedString([]byte{}, tag.Key)))
var flags OpFlags
if indirect {
flags |= IndirectFlags
}
if field.Anonymous {
flags |= AnonymousKeyFlags
}
if tag.IsTaggedKey {
flags |= IsTaggedKeyFlags
}
if nilcheck {
flags |= NilCheckFlags
}
if addrForMarshaler {
flags |= AddrForMarshalerFlags
}
if strings.Contains(valueCode.Op.String(), "Ptr") || valueCode.Op == OpInterface {
flags |= IsNextOpPtrTypeFlags
}
if isNilableType {
flags |= IsNilableTypeFlags
}
var key string
if ctx.escapeKey {
rctx := &RuntimeContext{Option: &Option{Flag: HTMLEscapeOption}}
key = fmt.Sprintf(`%s:`, string(AppendString(rctx, []byte{}, tag.Key)))
} else {
key = fmt.Sprintf(`"%s":`, tag.Key)
}
fieldCode := &Opcode{
Type: valueCode.Type,
DisplayIdx: fieldOpcodeIndex,
Idx: opcodeOffset(fieldPtrIndex),
Next: valueCode,
Indent: ctx.indent,
AnonymousKey: field.Anonymous,
Key: []byte(key),
EscapedKey: []byte(escapedKey),
IsTaggedKey: tag.IsTaggedKey,
DisplayKey: tag.Key,
Offset: field.Offset,
Indirect: indirect,
Nilcheck: nilcheck,
AddrForMarshaler: addrForMarshaler,
IsNextOpPtrType: strings.Contains(valueCode.Op.String(), "Ptr") || valueCode.Op == OpInterface,
IsNilableType: isNilableType,
Idx: opcodeOffset(fieldPtrIndex),
Next: valueCode,
Flags: flags,
Key: key,
Offset: uint32(field.Offset),
Type: valueCode.Type,
DisplayIdx: fieldOpcodeIndex,
Indent: ctx.indent,
DisplayKey: tag.Key,
}
if fieldIdx == 0 {
fieldCode.HeadIdx = fieldCode.Idx
code = structHeader(ctx, fieldCode, valueCode, tag)
head = fieldCode
prevField = fieldCode
} else {
fieldCode.HeadIdx = head.HeadIdx
fieldCode.Idx = head.Idx
code.Next = fieldCode
code = structField(ctx, fieldCode, valueCode, tag)
prevField.NextField = fieldCode
@ -1455,7 +1508,6 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
Op: OpStructEnd,
Type: nil,
Indent: ctx.indent,
Next: newEndOp(ctx),
}
ctx = ctx.decIndent()
@ -1464,12 +1516,11 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
if head == nil {
head = &Opcode{
Op: OpStructHead,
Idx: opcodeOffset(ctx.ptrIndex),
NextField: structEndCode,
Type: typ,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
HeadIdx: opcodeOffset(ctx.ptrIndex),
Indent: ctx.indent,
NextField: structEndCode,
}
structEndCode.PrevField = head
ctx.incIndex()
@ -1479,6 +1530,7 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
structEndCode.DisplayIdx = ctx.opcodeIndex
structEndCode.Idx = opcodeOffset(ctx.ptrIndex)
ctx.incIndex()
structEndCode.Next = newEndOp(ctx)
if prevField != nil && prevField.NextField == nil {
prevField.NextField = structEndCode
@ -1494,15 +1546,23 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
delete(ctx.structTypeToCompiledCode, typeptr)
if !disableIndirectConversion && !head.Indirect && isPtr {
head.Indirect = true
if !disableIndirectConversion && (head.Flags&IndirectFlags == 0) && isPtr {
headCode := head
for strings.Contains(headCode.Op.String(), "Head") {
headCode.Flags |= IndirectFlags
headCode = headCode.Next
}
}
return ret, nil
}
func implementsMarshalJSONType(typ *runtime.Type) bool {
return typ.Implements(marshalJSONType) || typ.Implements(marshalJSONContextType)
}
func isPtrMarshalJSONType(typ *runtime.Type) bool {
return !typ.Implements(marshalJSONType) && runtime.PtrTo(typ).Implements(marshalJSONType)
return !implementsMarshalJSONType(typ) && implementsMarshalJSONType(runtime.PtrTo(typ))
}
func isPtrMarshalTextType(typ *runtime.Type) bool {

View file

@ -20,19 +20,36 @@ func CompileToGetCodeSet(typeptr uintptr) (*OpcodeSet, error) {
// noescape trick for header.typ ( reflect.*rtype )
copiedType := *(**runtime.Type)(unsafe.Pointer(&typeptr))
code, err := compileHead(&compileContext{
noescapeKeyCode, err := compileHead(&compileContext{
typ: copiedType,
structTypeToCompiledCode: map[uintptr]*CompiledCode{},
})
if err != nil {
return nil, err
}
code = copyOpcode(code)
codeLength := code.TotalLength()
escapeKeyCode, err := compileHead(&compileContext{
typ: copiedType,
structTypeToCompiledCode: map[uintptr]*CompiledCode{},
escapeKey: true,
})
if err != nil {
return nil, err
}
noescapeKeyCode = copyOpcode(noescapeKeyCode)
escapeKeyCode = copyOpcode(escapeKeyCode)
setTotalLengthToInterfaceOp(noescapeKeyCode)
setTotalLengthToInterfaceOp(escapeKeyCode)
interfaceNoescapeKeyCode := copyToInterfaceOpcode(noescapeKeyCode)
interfaceEscapeKeyCode := copyToInterfaceOpcode(escapeKeyCode)
codeLength := noescapeKeyCode.TotalLength()
codeSet := &OpcodeSet{
Type: copiedType,
Code: code,
CodeLength: codeLength,
Type: copiedType,
NoescapeKeyCode: noescapeKeyCode,
EscapeKeyCode: escapeKeyCode,
InterfaceNoescapeKeyCode: interfaceNoescapeKeyCode,
InterfaceEscapeKeyCode: interfaceEscapeKeyCode,
CodeLength: codeLength,
EndCode: ToEndCode(interfaceNoescapeKeyCode),
}
cachedOpcodeSets[index] = codeSet
return codeSet, nil

View file

@ -26,19 +26,37 @@ func CompileToGetCodeSet(typeptr uintptr) (*OpcodeSet, error) {
// noescape trick for header.typ ( reflect.*rtype )
copiedType := *(**runtime.Type)(unsafe.Pointer(&typeptr))
code, err := compileHead(&compileContext{
noescapeKeyCode, err := compileHead(&compileContext{
typ: copiedType,
structTypeToCompiledCode: map[uintptr]*CompiledCode{},
})
if err != nil {
return nil, err
}
code = copyOpcode(code)
codeLength := code.TotalLength()
escapeKeyCode, err := compileHead(&compileContext{
typ: copiedType,
structTypeToCompiledCode: map[uintptr]*CompiledCode{},
escapeKey: true,
})
if err != nil {
return nil, err
}
noescapeKeyCode = copyOpcode(noescapeKeyCode)
escapeKeyCode = copyOpcode(escapeKeyCode)
setTotalLengthToInterfaceOp(noescapeKeyCode)
setTotalLengthToInterfaceOp(escapeKeyCode)
interfaceNoescapeKeyCode := copyToInterfaceOpcode(noescapeKeyCode)
interfaceEscapeKeyCode := copyToInterfaceOpcode(escapeKeyCode)
codeLength := noescapeKeyCode.TotalLength()
codeSet := &OpcodeSet{
Type: copiedType,
Code: code,
CodeLength: codeLength,
Type: copiedType,
NoescapeKeyCode: noescapeKeyCode,
EscapeKeyCode: escapeKeyCode,
InterfaceNoescapeKeyCode: interfaceNoescapeKeyCode,
InterfaceEscapeKeyCode: interfaceEscapeKeyCode,
CodeLength: codeLength,
EndCode: ToEndCode(interfaceNoescapeKeyCode),
}
setsMu.Lock()
cachedOpcodeSets[index] = codeSet

View file

@ -1,6 +1,7 @@
package encoder
import (
"context"
"sync"
"unsafe"
@ -9,9 +10,10 @@ import (
type compileContext struct {
typ *runtime.Type
opcodeIndex int
opcodeIndex uint32
ptrIndex int
indent int
indent uint32
escapeKey bool
structTypeToCompiledCode map[uintptr]*CompiledCode
parent *compileContext
@ -23,6 +25,7 @@ func (c *compileContext) context() *compileContext {
opcodeIndex: c.opcodeIndex,
ptrIndex: c.ptrIndex,
indent: c.indent,
escapeKey: c.escapeKey,
structTypeToCompiledCode: c.structTypeToCompiledCode,
parent: c,
}
@ -95,20 +98,23 @@ var (
Buf: make([]byte, 0, bufSize),
Ptrs: make([]uintptr, 128),
KeepRefs: make([]unsafe.Pointer, 0, 8),
Option: &Option{},
}
},
}
)
type RuntimeContext struct {
Context context.Context
Buf []byte
MarshalBuf []byte
Ptrs []uintptr
KeepRefs []unsafe.Pointer
SeenPtr []uintptr
BaseIndent int
BaseIndent uint32
Prefix []byte
IndentStr []byte
Option *Option
}
func (c *RuntimeContext) Init(p uintptr, codelen int) {

View file

@ -17,14 +17,6 @@ import (
"github.com/goccy/go-json/internal/runtime"
)
type Option int
const (
HTMLEscapeOption Option = 1 << iota
IndentOption
UnorderedMapOption
)
func (t OpType) IsMultipleOpHead() bool {
switch t {
case OpStructHead:
@ -102,9 +94,13 @@ func (t OpType) IsMultipleOpField() bool {
}
type OpcodeSet struct {
Type *runtime.Type
Code *Opcode
CodeLength int
Type *runtime.Type
NoescapeKeyCode *Opcode
EscapeKeyCode *Opcode
InterfaceNoescapeKeyCode *Opcode
InterfaceEscapeKeyCode *Opcode
CodeLength int
EndCode *Opcode
}
type CompiledCode struct {
@ -276,7 +272,7 @@ func MapIterNext(it unsafe.Pointer)
//go:noescape
func MapLen(m unsafe.Pointer) int
func AppendByteSlice(b []byte, src []byte) []byte {
func AppendByteSlice(_ *RuntimeContext, b []byte, src []byte) []byte {
if src == nil {
return append(b, `null`...)
}
@ -294,7 +290,7 @@ func AppendByteSlice(b []byte, src []byte) []byte {
return append(append(b, buf...), '"')
}
func AppendFloat32(b []byte, v float32) []byte {
func AppendFloat32(_ *RuntimeContext, b []byte, v float32) []byte {
f64 := float64(v)
abs := math.Abs(f64)
fmt := byte('f')
@ -308,7 +304,7 @@ func AppendFloat32(b []byte, v float32) []byte {
return strconv.AppendFloat(b, f64, fmt, -1, 32)
}
func AppendFloat64(b []byte, v float64) []byte {
func AppendFloat64(_ *RuntimeContext, b []byte, v float64) []byte {
abs := math.Abs(v)
fmt := byte('f')
// Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
@ -320,7 +316,7 @@ func AppendFloat64(b []byte, v float64) []byte {
return strconv.AppendFloat(b, v, fmt, -1, 64)
}
func AppendBool(b []byte, v bool) []byte {
func AppendBool(_ *RuntimeContext, b []byte, v bool) []byte {
if v {
return append(b, "true"...)
}
@ -347,7 +343,7 @@ var (
}
)
func AppendNumber(b []byte, n json.Number) ([]byte, error) {
func AppendNumber(_ *RuntimeContext, b []byte, n json.Number) ([]byte, error) {
if len(n) == 0 {
return append(b, '0'), nil
}
@ -360,9 +356,9 @@ func AppendNumber(b []byte, n json.Number) ([]byte, error) {
return b, nil
}
func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{}) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.AddrForMarshaler {
if (code.Flags & AddrForMarshalerFlags) != 0 {
if rv.CanAddr() {
rv = rv.Addr()
} else {
@ -372,17 +368,31 @@ func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{
}
}
v = rv.Interface()
marshaler, ok := v.(json.Marshaler)
if !ok {
return AppendNull(b), nil
}
bb, err := marshaler.MarshalJSON()
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
var bb []byte
if (code.Flags & MarshalerContextFlags) != 0 {
marshaler, ok := v.(marshalerContext)
if !ok {
return AppendNull(ctx, b), nil
}
b, err := marshaler.MarshalJSON(ctx.Option.Context)
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
bb = b
} else {
marshaler, ok := v.(json.Marshaler)
if !ok {
return AppendNull(ctx, b), nil
}
b, err := marshaler.MarshalJSON()
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
bb = b
}
marshalBuf := ctx.MarshalBuf[:0]
marshalBuf = append(append(marshalBuf, bb...), nul)
compactedBuf, err := compact(b, marshalBuf, escape)
compactedBuf, err := compact(b, marshalBuf, (ctx.Option.Flag&HTMLEscapeOption) != 0)
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
@ -390,9 +400,9 @@ func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{
return compactedBuf, nil
}
func AppendMarshalJSONIndent(ctx *RuntimeContext, code *Opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
func AppendMarshalJSONIndent(ctx *RuntimeContext, code *Opcode, b []byte, v interface{}) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.AddrForMarshaler {
if (code.Flags & AddrForMarshalerFlags) != 0 {
if rv.CanAddr() {
rv = rv.Addr()
} else {
@ -402,22 +412,36 @@ func AppendMarshalJSONIndent(ctx *RuntimeContext, code *Opcode, b []byte, v inte
}
}
v = rv.Interface()
marshaler, ok := v.(json.Marshaler)
if !ok {
return AppendNull(b), nil
}
bb, err := marshaler.MarshalJSON()
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
var bb []byte
if (code.Flags & MarshalerContextFlags) != 0 {
marshaler, ok := v.(marshalerContext)
if !ok {
return AppendNull(ctx, b), nil
}
b, err := marshaler.MarshalJSON(ctx.Option.Context)
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
bb = b
} else {
marshaler, ok := v.(json.Marshaler)
if !ok {
return AppendNull(ctx, b), nil
}
b, err := marshaler.MarshalJSON()
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
bb = b
}
marshalBuf := ctx.MarshalBuf[:0]
marshalBuf = append(append(marshalBuf, bb...), nul)
indentedBuf, err := doIndent(
b,
marshalBuf,
string(ctx.Prefix)+strings.Repeat(string(ctx.IndentStr), ctx.BaseIndent+code.Indent),
string(ctx.Prefix)+strings.Repeat(string(ctx.IndentStr), int(ctx.BaseIndent+code.Indent)),
string(ctx.IndentStr),
escape,
(ctx.Option.Flag&HTMLEscapeOption) != 0,
)
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
@ -426,9 +450,9 @@ func AppendMarshalJSONIndent(ctx *RuntimeContext, code *Opcode, b []byte, v inte
return indentedBuf, nil
}
func AppendMarshalText(code *Opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
func AppendMarshalText(ctx *RuntimeContext, code *Opcode, b []byte, v interface{}) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.AddrForMarshaler {
if (code.Flags & AddrForMarshalerFlags) != 0 {
if rv.CanAddr() {
rv = rv.Addr()
} else {
@ -440,21 +464,18 @@ func AppendMarshalText(code *Opcode, b []byte, v interface{}, escape bool) ([]by
v = rv.Interface()
marshaler, ok := v.(encoding.TextMarshaler)
if !ok {
return AppendNull(b), nil
return AppendNull(ctx, b), nil
}
bytes, err := marshaler.MarshalText()
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
if escape {
return AppendEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
}
return AppendString(b, *(*string)(unsafe.Pointer(&bytes))), nil
return AppendString(ctx, b, *(*string)(unsafe.Pointer(&bytes))), nil
}
func AppendMarshalTextIndent(code *Opcode, b []byte, v interface{}, escape bool) ([]byte, error) {
func AppendMarshalTextIndent(ctx *RuntimeContext, code *Opcode, b []byte, v interface{}) ([]byte, error) {
rv := reflect.ValueOf(v) // convert by dynamic interface type
if code.AddrForMarshaler {
if (code.Flags & AddrForMarshalerFlags) != 0 {
if rv.CanAddr() {
rv = rv.Addr()
} else {
@ -466,31 +487,28 @@ func AppendMarshalTextIndent(code *Opcode, b []byte, v interface{}, escape bool)
v = rv.Interface()
marshaler, ok := v.(encoding.TextMarshaler)
if !ok {
return AppendNull(b), nil
return AppendNull(ctx, b), nil
}
bytes, err := marshaler.MarshalText()
if err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}
}
if escape {
return AppendEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
}
return AppendString(b, *(*string)(unsafe.Pointer(&bytes))), nil
return AppendString(ctx, b, *(*string)(unsafe.Pointer(&bytes))), nil
}
func AppendNull(b []byte) []byte {
func AppendNull(_ *RuntimeContext, b []byte) []byte {
return append(b, "null"...)
}
func AppendComma(b []byte) []byte {
func AppendComma(_ *RuntimeContext, b []byte) []byte {
return append(b, ',')
}
func AppendCommaIndent(b []byte) []byte {
func AppendCommaIndent(_ *RuntimeContext, b []byte) []byte {
return append(b, ',', '\n')
}
func AppendStructEnd(b []byte) []byte {
func AppendStructEnd(_ *RuntimeContext, b []byte) []byte {
return append(b, '}', ',')
}
@ -498,16 +516,16 @@ func AppendStructEndIndent(ctx *RuntimeContext, code *Opcode, b []byte) []byte {
b = append(b, '\n')
b = append(b, ctx.Prefix...)
indentNum := ctx.BaseIndent + code.Indent - 1
for i := 0; i < indentNum; i++ {
for i := uint32(0); i < indentNum; i++ {
b = append(b, ctx.IndentStr...)
}
return append(b, '}', ',', '\n')
}
func AppendIndent(ctx *RuntimeContext, b []byte, indent int) []byte {
func AppendIndent(ctx *RuntimeContext, b []byte, indent uint32) []byte {
b = append(b, ctx.Prefix...)
indentNum := ctx.BaseIndent + indent
for i := 0; i < indentNum; i++ {
for i := uint32(0); i < indentNum; i++ {
b = append(b, ctx.IndentStr...)
}
return b

View file

@ -49,9 +49,14 @@ var intBELookup = [100]uint16{
var intLookup = [2]*[100]uint16{&intLELookup, &intBELookup}
func AppendInt(out []byte, u64 uint64, code *Opcode) []byte {
n := u64 & code.Mask
negative := (u64>>code.RshiftNum)&1 == 1
func numMask(numBitSize uint8) uint64 {
return 1<<numBitSize - 1
}
func AppendInt(_ *RuntimeContext, out []byte, u64 uint64, code *Opcode) []byte {
mask := numMask(code.NumBitSize)
n := u64 & mask
negative := (u64>>(code.NumBitSize-1))&1 == 1
if !negative {
if n < 10 {
return append(out, byte(n+'0'))
@ -60,7 +65,7 @@ func AppendInt(out []byte, u64 uint64, code *Opcode) []byte {
return append(out, byte(u), byte(u>>8))
}
} else {
n = -n & code.Mask
n = -n & mask
}
lookup := intLookup[endianness]
@ -91,8 +96,9 @@ func AppendInt(out []byte, u64 uint64, code *Opcode) []byte {
return append(out, b[i:]...)
}
func AppendUint(out []byte, u64 uint64, code *Opcode) []byte {
n := u64 & code.Mask
func AppendUint(_ *RuntimeContext, out []byte, u64 uint64, code *Opcode) []byte {
mask := numMask(code.NumBitSize)
n := u64 & mask
if n < 10 {
return append(out, byte(n+'0'))
} else if n < 100 {

View file

@ -2,7 +2,6 @@ package encoder
import (
"fmt"
"math"
"strings"
"unsafe"
@ -11,61 +10,61 @@ import (
const uintptrSize = 4 << (^uintptr(0) >> 63)
type OpFlags uint16
const (
AnonymousHeadFlags OpFlags = 1 << 0
AnonymousKeyFlags OpFlags = 1 << 1
IndirectFlags OpFlags = 1 << 2
IsTaggedKeyFlags OpFlags = 1 << 3
NilCheckFlags OpFlags = 1 << 4
AddrForMarshalerFlags OpFlags = 1 << 5
IsNextOpPtrTypeFlags OpFlags = 1 << 6
IsNilableTypeFlags OpFlags = 1 << 7
MarshalerContextFlags OpFlags = 1 << 8
NonEmptyInterfaceFlags OpFlags = 1 << 9
)
type Opcode struct {
Op OpType // operation type
Type *runtime.Type // go type
DisplayIdx int // opcode index
Key []byte // struct field key
EscapedKey []byte // struct field key ( HTML escaped )
PtrNum int // pointer number: e.g. double pointer is 2.
DisplayKey string // key text to display
IsTaggedKey bool // whether tagged key
AnonymousKey bool // whether anonymous key
AnonymousHead bool // whether anonymous head or not
Indirect bool // whether indirect or not
Nilcheck bool // whether needs to nilcheck or not
AddrForMarshaler bool // whether needs to addr for marshaler or not
IsNextOpPtrType bool // whether next operation is ptr type or not
IsNilableType bool // whether type is nilable or not
RshiftNum uint8 // use to take bit for judging whether negative integer or not
Mask uint64 // mask for number
Indent int // indent number
Op OpType // operation type
Idx uint32 // offset to access ptr
Next *Opcode // next opcode
End *Opcode // array/slice/struct/map end
NextField *Opcode // next struct field
Key string // struct field key
Offset uint32 // offset size from struct header
PtrNum uint8 // pointer number: e.g. double pointer is 2.
NumBitSize uint8
Flags OpFlags
Idx uintptr // offset to access ptr
HeadIdx uintptr // offset to access slice/struct head
ElemIdx uintptr // offset to access array/slice/map elem
Length uintptr // offset to access slice/map length or array length
MapIter uintptr // offset to access map iterator
MapPos uintptr // offset to access position list for sorted map
Offset uintptr // offset size from struct header
Size uintptr // array/slice elem size
MapKey *Opcode // map key
MapValue *Opcode // map value
Elem *Opcode // array/slice elem
End *Opcode // array/slice/struct/map end
PrevField *Opcode // prev struct field
NextField *Opcode // next struct field
Next *Opcode // next opcode
Jmp *CompiledCode // for recursive call
Type *runtime.Type // go type
PrevField *Opcode // prev struct field
Jmp *CompiledCode // for recursive call
ElemIdx uint32 // offset to access array/slice/map elem
Length uint32 // offset to access slice/map length or array length
MapIter uint32 // offset to access map iterator
MapPos uint32 // offset to access position list for sorted map
Indent uint32 // indent number
Size uint32 // array/slice elem size
DisplayIdx uint32 // opcode index
DisplayKey string // key text to display
}
func rshitNum(bitSize uint8) uint8 {
return bitSize - 1
}
func (c *Opcode) setMaskAndRshiftNum(bitSize uint8) {
switch bitSize {
case 8:
c.Mask = math.MaxUint8
case 16:
c.Mask = math.MaxUint16
case 32:
c.Mask = math.MaxUint32
case 64:
c.Mask = math.MaxUint64
func (c *Opcode) MaxIdx() uint32 {
max := uint32(0)
for _, value := range []uint32{
c.Idx,
c.ElemIdx,
c.Length,
c.MapIter,
c.MapPos,
c.Size,
} {
if max < value {
max = value
}
}
c.RshiftNum = rshitNum(bitSize)
return max
}
func (c *Opcode) ToHeaderType(isString bool) OpType {
@ -278,8 +277,8 @@ func newOpCode(ctx *compileContext, op OpType) *Opcode {
return newOpCodeWithNext(ctx, op, newEndOp(ctx))
}
func opcodeOffset(idx int) uintptr {
return uintptr(idx) * uintptrSize
func opcodeOffset(idx int) uint32 {
return uint32(idx) * uintptrSize
}
func copyOpcode(code *Opcode) *Opcode {
@ -287,14 +286,53 @@ func copyOpcode(code *Opcode) *Opcode {
return code.copy(codeMap)
}
func setTotalLengthToInterfaceOp(code *Opcode) {
c := code
for c.Op != OpEnd && c.Op != OpInterfaceEnd {
if c.Op == OpInterface {
c.Length = uint32(code.TotalLength())
}
switch c.Op.CodeType() {
case CodeArrayElem, CodeSliceElem, CodeMapKey:
c = c.End
default:
c = c.Next
}
}
}
func ToEndCode(code *Opcode) *Opcode {
c := code
for c.Op != OpEnd && c.Op != OpInterfaceEnd {
switch c.Op.CodeType() {
case CodeArrayElem, CodeSliceElem, CodeMapKey:
c = c.End
default:
c = c.Next
}
}
return c
}
func copyToInterfaceOpcode(code *Opcode) *Opcode {
copied := copyOpcode(code)
c := copied
c = ToEndCode(c)
c.Idx += uintptrSize
c.ElemIdx = c.Idx + uintptrSize
c.Length = c.Idx + 2*uintptrSize
c.Op = OpInterfaceEnd
return copied
}
func newOpCodeWithNext(ctx *compileContext, op OpType, next *Opcode) *Opcode {
return &Opcode{
Op: op,
Idx: opcodeOffset(ctx.ptrIndex),
Next: next,
Type: ctx.typ,
DisplayIdx: ctx.opcodeIndex,
Indent: ctx.indent,
Idx: opcodeOffset(ctx.ptrIndex),
Next: next,
}
}
@ -311,37 +349,24 @@ func (c *Opcode) copy(codeMap map[uintptr]*Opcode) *Opcode {
return code
}
copied := &Opcode{
Op: c.Op,
Type: c.Type,
DisplayIdx: c.DisplayIdx,
Key: c.Key,
EscapedKey: c.EscapedKey,
DisplayKey: c.DisplayKey,
PtrNum: c.PtrNum,
Mask: c.Mask,
RshiftNum: c.RshiftNum,
IsTaggedKey: c.IsTaggedKey,
AnonymousKey: c.AnonymousKey,
AnonymousHead: c.AnonymousHead,
Indirect: c.Indirect,
Nilcheck: c.Nilcheck,
AddrForMarshaler: c.AddrForMarshaler,
IsNextOpPtrType: c.IsNextOpPtrType,
IsNilableType: c.IsNilableType,
Indent: c.Indent,
Idx: c.Idx,
HeadIdx: c.HeadIdx,
ElemIdx: c.ElemIdx,
Length: c.Length,
MapIter: c.MapIter,
MapPos: c.MapPos,
Offset: c.Offset,
Size: c.Size,
Op: c.Op,
Key: c.Key,
PtrNum: c.PtrNum,
NumBitSize: c.NumBitSize,
Flags: c.Flags,
Idx: c.Idx,
Offset: c.Offset,
Type: c.Type,
DisplayIdx: c.DisplayIdx,
DisplayKey: c.DisplayKey,
ElemIdx: c.ElemIdx,
Length: c.Length,
MapIter: c.MapIter,
MapPos: c.MapPos,
Size: c.Size,
Indent: c.Indent,
}
codeMap[addr] = copied
copied.MapKey = c.MapKey.copy(codeMap)
copied.MapValue = c.MapValue.copy(codeMap)
copied.Elem = c.Elem.copy(codeMap)
copied.End = c.End.copy(codeMap)
copied.PrevField = c.PrevField.copy(codeMap)
copied.NextField = c.NextField.copy(codeMap)
@ -369,8 +394,12 @@ func (c *Opcode) BeforeLastCode() *Opcode {
func (c *Opcode) TotalLength() int {
var idx int
for code := c; code.Op != OpEnd; {
idx = int(code.Idx / uintptrSize)
code := c
for code.Op != OpEnd && code.Op != OpInterfaceEnd {
maxIdx := int(code.MaxIdx() / uintptrSize)
if idx < maxIdx {
idx = maxIdx
}
if code.Op == OpRecursiveEnd {
break
}
@ -381,15 +410,18 @@ func (c *Opcode) TotalLength() int {
code = code.Next
}
}
return idx + 2 // opEnd + 1
maxIdx := int(code.MaxIdx() / uintptrSize)
if idx < maxIdx {
idx = maxIdx
}
return idx + 1
}
func (c *Opcode) decOpcodeIndex() {
for code := c; code.Op != OpEnd; {
code.DisplayIdx--
code.Idx -= uintptrSize
if code.HeadIdx > 0 {
code.HeadIdx -= uintptrSize
if code.Idx > 0 {
code.Idx -= uintptrSize
}
if code.ElemIdx > 0 {
code.ElemIdx -= uintptrSize
@ -422,19 +454,18 @@ func (c *Opcode) decIndent() {
}
func (c *Opcode) dumpHead(code *Opcode) string {
var length uintptr
var length uint32
if code.Op.CodeType() == CodeArrayHead {
length = code.Length
} else {
length = code.Length / uintptrSize
}
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][headIdx:%d][elemIdx:%d][length:%d])`,
`[%d]%s%s ([idx:%d][elemIdx:%d][length:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.HeadIdx/uintptrSize,
code.ElemIdx/uintptrSize,
length,
)
@ -442,12 +473,11 @@ func (c *Opcode) dumpHead(code *Opcode) string {
func (c *Opcode) dumpMapHead(code *Opcode) string {
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][headIdx:%d][elemIdx:%d][length:%d][mapIter:%d])`,
`[%d]%s%s ([idx:%d][elemIdx:%d][length:%d][mapIter:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.HeadIdx/uintptrSize,
code.ElemIdx/uintptrSize,
code.Length/uintptrSize,
code.MapIter/uintptrSize,
@ -458,7 +488,7 @@ func (c *Opcode) dumpMapEnd(code *Opcode) string {
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][mapPos:%d][length:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.MapPos/uintptrSize,
@ -467,19 +497,18 @@ func (c *Opcode) dumpMapEnd(code *Opcode) string {
}
func (c *Opcode) dumpElem(code *Opcode) string {
var length uintptr
var length uint32
if code.Op.CodeType() == CodeArrayElem {
length = code.Length
} else {
length = code.Length / uintptrSize
}
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][headIdx:%d][elemIdx:%d][length:%d][size:%d])`,
`[%d]%s%s ([idx:%d][elemIdx:%d][length:%d][size:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.HeadIdx/uintptrSize,
code.ElemIdx/uintptrSize,
length,
code.Size,
@ -488,14 +517,13 @@ func (c *Opcode) dumpElem(code *Opcode) string {
func (c *Opcode) dumpField(code *Opcode) string {
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][key:%s][offset:%d][headIdx:%d])`,
`[%d]%s%s ([idx:%d][key:%s][offset:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.DisplayKey,
code.Offset,
code.HeadIdx/uintptrSize,
)
}
@ -503,7 +531,7 @@ func (c *Opcode) dumpKey(code *Opcode) string {
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][elemIdx:%d][length:%d][mapIter:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.ElemIdx/uintptrSize,
@ -516,7 +544,7 @@ func (c *Opcode) dumpValue(code *Opcode) string {
return fmt.Sprintf(
`[%d]%s%s ([idx:%d][mapIter:%d])`,
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
code.MapIter/uintptrSize,
@ -525,7 +553,7 @@ func (c *Opcode) dumpValue(code *Opcode) string {
func (c *Opcode) Dump() string {
codes := []string{}
for code := c; code.Op != OpEnd; {
for code := c; code.Op != OpEnd && code.Op != OpInterfaceEnd; {
switch code.Op.CodeType() {
case CodeSliceHead:
codes = append(codes, c.dumpHead(code))
@ -555,7 +583,7 @@ func (c *Opcode) Dump() string {
codes = append(codes, fmt.Sprintf(
"[%d]%s%s ([idx:%d])",
code.DisplayIdx,
strings.Repeat("-", code.Indent),
strings.Repeat("-", int(code.Indent)),
code.Op,
code.Idx/uintptrSize,
))
@ -610,9 +638,8 @@ func newSliceHeaderCode(ctx *compileContext) *Opcode {
length := opcodeOffset(ctx.ptrIndex)
return &Opcode{
Op: OpSlice,
DisplayIdx: ctx.opcodeIndex,
Idx: idx,
HeadIdx: idx,
DisplayIdx: ctx.opcodeIndex,
ElemIdx: elemIdx,
Length: length,
Indent: ctx.indent,
@ -622,13 +649,12 @@ func newSliceHeaderCode(ctx *compileContext) *Opcode {
func newSliceElemCode(ctx *compileContext, head *Opcode, size uintptr) *Opcode {
return &Opcode{
Op: OpSliceElem,
Idx: head.Idx,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
HeadIdx: head.Idx,
ElemIdx: head.ElemIdx,
Length: head.Length,
Indent: ctx.indent,
Size: size,
Size: uint32(size),
}
}
@ -638,25 +664,23 @@ func newArrayHeaderCode(ctx *compileContext, alen int) *Opcode {
elemIdx := opcodeOffset(ctx.ptrIndex)
return &Opcode{
Op: OpArray,
DisplayIdx: ctx.opcodeIndex,
Idx: idx,
HeadIdx: idx,
DisplayIdx: ctx.opcodeIndex,
ElemIdx: elemIdx,
Indent: ctx.indent,
Length: uintptr(alen),
Length: uint32(alen),
}
}
func newArrayElemCode(ctx *compileContext, head *Opcode, length int, size uintptr) *Opcode {
return &Opcode{
Op: OpArrayElem,
Idx: head.Idx,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
ElemIdx: head.ElemIdx,
HeadIdx: head.HeadIdx,
Length: uintptr(length),
Length: uint32(length),
Indent: ctx.indent,
Size: size,
Size: uint32(size),
}
}
@ -670,9 +694,9 @@ func newMapHeaderCode(ctx *compileContext) *Opcode {
mapIter := opcodeOffset(ctx.ptrIndex)
return &Opcode{
Op: OpMap,
Idx: idx,
Type: ctx.typ,
DisplayIdx: ctx.opcodeIndex,
Idx: idx,
ElemIdx: elemIdx,
Length: length,
MapIter: mapIter,
@ -683,8 +707,8 @@ func newMapHeaderCode(ctx *compileContext) *Opcode {
func newMapKeyCode(ctx *compileContext, head *Opcode) *Opcode {
return &Opcode{
Op: OpMapKey,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
DisplayIdx: ctx.opcodeIndex,
ElemIdx: head.ElemIdx,
Length: head.Length,
MapIter: head.MapIter,
@ -695,8 +719,8 @@ func newMapKeyCode(ctx *compileContext, head *Opcode) *Opcode {
func newMapValueCode(ctx *compileContext, head *Opcode) *Opcode {
return &Opcode{
Op: OpMapValue,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
DisplayIdx: ctx.opcodeIndex,
ElemIdx: head.ElemIdx,
Length: head.Length,
MapIter: head.MapIter,
@ -710,34 +734,39 @@ func newMapEndCode(ctx *compileContext, head *Opcode) *Opcode {
idx := opcodeOffset(ctx.ptrIndex)
return &Opcode{
Op: OpMapEnd,
DisplayIdx: ctx.opcodeIndex,
Idx: idx,
Next: newEndOp(ctx),
DisplayIdx: ctx.opcodeIndex,
Length: head.Length,
MapPos: mapPos,
Indent: ctx.indent,
Next: newEndOp(ctx),
}
}
func newInterfaceCode(ctx *compileContext) *Opcode {
var flag OpFlags
if ctx.typ.NumMethod() > 0 {
flag |= NonEmptyInterfaceFlags
}
return &Opcode{
Op: OpInterface,
Idx: opcodeOffset(ctx.ptrIndex),
Next: newEndOp(ctx),
Type: ctx.typ,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
Indent: ctx.indent,
Next: newEndOp(ctx),
Flags: flag,
}
}
func newRecursiveCode(ctx *compileContext, jmp *CompiledCode) *Opcode {
return &Opcode{
Op: OpRecursive,
Idx: opcodeOffset(ctx.ptrIndex),
Next: newEndOp(ctx),
Type: ctx.typ,
DisplayIdx: ctx.opcodeIndex,
Idx: opcodeOffset(ctx.ptrIndex),
Indent: ctx.indent,
Next: newEndOp(ctx),
Jmp: jmp,
}
}

View file

@ -0,0 +1,41 @@
package encoder
import "context"
type OptionFlag uint8
const (
HTMLEscapeOption OptionFlag = 1 << iota
IndentOption
UnorderedMapOption
DebugOption
ColorizeOption
ContextOption
)
type Option struct {
Flag OptionFlag
ColorScheme *ColorScheme
Context context.Context
}
type EncodeFormat struct {
Header string
Footer string
}
type EncodeFormatScheme struct {
Int EncodeFormat
Uint EncodeFormat
Float EncodeFormat
Bool EncodeFormat
String EncodeFormat
Binary EncodeFormat
ObjectKey EncodeFormat
Null EncodeFormat
}
type (
ColorScheme = EncodeFormatScheme
ColorFormat = EncodeFormat
)

View file

@ -22,7 +22,7 @@ const (
CodeStructEnd CodeType = 11
)
var opTypeStrings = [400]string{
var opTypeStrings = [401]string{
"End",
"Interface",
"Ptr",
@ -36,6 +36,7 @@ var opTypeStrings = [400]string{
"Recursive",
"RecursivePtr",
"RecursiveEnd",
"InterfaceEnd",
"StructAnonymousEnd",
"Int",
"Uint",
@ -425,7 +426,7 @@ var opTypeStrings = [400]string{
"StructEndOmitEmpty",
}
type OpType int
type OpType uint16
const (
OpEnd OpType = 0
@ -441,397 +442,398 @@ const (
OpRecursive OpType = 10
OpRecursivePtr OpType = 11
OpRecursiveEnd OpType = 12
OpStructAnonymousEnd OpType = 13
OpInt OpType = 14
OpUint OpType = 15
OpFloat32 OpType = 16
OpFloat64 OpType = 17
OpBool OpType = 18
OpString OpType = 19
OpBytes OpType = 20
OpNumber OpType = 21
OpArray OpType = 22
OpMap OpType = 23
OpSlice OpType = 24
OpStruct OpType = 25
OpMarshalJSON OpType = 26
OpMarshalText OpType = 27
OpIntString OpType = 28
OpUintString OpType = 29
OpFloat32String OpType = 30
OpFloat64String OpType = 31
OpBoolString OpType = 32
OpStringString OpType = 33
OpNumberString OpType = 34
OpIntPtr OpType = 35
OpUintPtr OpType = 36
OpFloat32Ptr OpType = 37
OpFloat64Ptr OpType = 38
OpBoolPtr OpType = 39
OpStringPtr OpType = 40
OpBytesPtr OpType = 41
OpNumberPtr OpType = 42
OpArrayPtr OpType = 43
OpMapPtr OpType = 44
OpSlicePtr OpType = 45
OpMarshalJSONPtr OpType = 46
OpMarshalTextPtr OpType = 47
OpInterfacePtr OpType = 48
OpIntPtrString OpType = 49
OpUintPtrString OpType = 50
OpFloat32PtrString OpType = 51
OpFloat64PtrString OpType = 52
OpBoolPtrString OpType = 53
OpStringPtrString OpType = 54
OpNumberPtrString OpType = 55
OpStructHeadInt OpType = 56
OpStructHeadOmitEmptyInt OpType = 57
OpStructPtrHeadInt OpType = 58
OpStructPtrHeadOmitEmptyInt OpType = 59
OpStructHeadUint OpType = 60
OpStructHeadOmitEmptyUint OpType = 61
OpStructPtrHeadUint OpType = 62
OpStructPtrHeadOmitEmptyUint OpType = 63
OpStructHeadFloat32 OpType = 64
OpStructHeadOmitEmptyFloat32 OpType = 65
OpStructPtrHeadFloat32 OpType = 66
OpStructPtrHeadOmitEmptyFloat32 OpType = 67
OpStructHeadFloat64 OpType = 68
OpStructHeadOmitEmptyFloat64 OpType = 69
OpStructPtrHeadFloat64 OpType = 70
OpStructPtrHeadOmitEmptyFloat64 OpType = 71
OpStructHeadBool OpType = 72
OpStructHeadOmitEmptyBool OpType = 73
OpStructPtrHeadBool OpType = 74
OpStructPtrHeadOmitEmptyBool OpType = 75
OpStructHeadString OpType = 76
OpStructHeadOmitEmptyString OpType = 77
OpStructPtrHeadString OpType = 78
OpStructPtrHeadOmitEmptyString OpType = 79
OpStructHeadBytes OpType = 80
OpStructHeadOmitEmptyBytes OpType = 81
OpStructPtrHeadBytes OpType = 82
OpStructPtrHeadOmitEmptyBytes OpType = 83
OpStructHeadNumber OpType = 84
OpStructHeadOmitEmptyNumber OpType = 85
OpStructPtrHeadNumber OpType = 86
OpStructPtrHeadOmitEmptyNumber OpType = 87
OpStructHeadArray OpType = 88
OpStructHeadOmitEmptyArray OpType = 89
OpStructPtrHeadArray OpType = 90
OpStructPtrHeadOmitEmptyArray OpType = 91
OpStructHeadMap OpType = 92
OpStructHeadOmitEmptyMap OpType = 93
OpStructPtrHeadMap OpType = 94
OpStructPtrHeadOmitEmptyMap OpType = 95
OpStructHeadSlice OpType = 96
OpStructHeadOmitEmptySlice OpType = 97
OpStructPtrHeadSlice OpType = 98
OpStructPtrHeadOmitEmptySlice OpType = 99
OpStructHeadStruct OpType = 100
OpStructHeadOmitEmptyStruct OpType = 101
OpStructPtrHeadStruct OpType = 102
OpStructPtrHeadOmitEmptyStruct OpType = 103
OpStructHeadMarshalJSON OpType = 104
OpStructHeadOmitEmptyMarshalJSON OpType = 105
OpStructPtrHeadMarshalJSON OpType = 106
OpStructPtrHeadOmitEmptyMarshalJSON OpType = 107
OpStructHeadMarshalText OpType = 108
OpStructHeadOmitEmptyMarshalText OpType = 109
OpStructPtrHeadMarshalText OpType = 110
OpStructPtrHeadOmitEmptyMarshalText OpType = 111
OpStructHeadIntString OpType = 112
OpStructHeadOmitEmptyIntString OpType = 113
OpStructPtrHeadIntString OpType = 114
OpStructPtrHeadOmitEmptyIntString OpType = 115
OpStructHeadUintString OpType = 116
OpStructHeadOmitEmptyUintString OpType = 117
OpStructPtrHeadUintString OpType = 118
OpStructPtrHeadOmitEmptyUintString OpType = 119
OpStructHeadFloat32String OpType = 120
OpStructHeadOmitEmptyFloat32String OpType = 121
OpStructPtrHeadFloat32String OpType = 122
OpStructPtrHeadOmitEmptyFloat32String OpType = 123
OpStructHeadFloat64String OpType = 124
OpStructHeadOmitEmptyFloat64String OpType = 125
OpStructPtrHeadFloat64String OpType = 126
OpStructPtrHeadOmitEmptyFloat64String OpType = 127
OpStructHeadBoolString OpType = 128
OpStructHeadOmitEmptyBoolString OpType = 129
OpStructPtrHeadBoolString OpType = 130
OpStructPtrHeadOmitEmptyBoolString OpType = 131
OpStructHeadStringString OpType = 132
OpStructHeadOmitEmptyStringString OpType = 133
OpStructPtrHeadStringString OpType = 134
OpStructPtrHeadOmitEmptyStringString OpType = 135
OpStructHeadNumberString OpType = 136
OpStructHeadOmitEmptyNumberString OpType = 137
OpStructPtrHeadNumberString OpType = 138
OpStructPtrHeadOmitEmptyNumberString OpType = 139
OpStructHeadIntPtr OpType = 140
OpStructHeadOmitEmptyIntPtr OpType = 141
OpStructPtrHeadIntPtr OpType = 142
OpStructPtrHeadOmitEmptyIntPtr OpType = 143
OpStructHeadUintPtr OpType = 144
OpStructHeadOmitEmptyUintPtr OpType = 145
OpStructPtrHeadUintPtr OpType = 146
OpStructPtrHeadOmitEmptyUintPtr OpType = 147
OpStructHeadFloat32Ptr OpType = 148
OpStructHeadOmitEmptyFloat32Ptr OpType = 149
OpStructPtrHeadFloat32Ptr OpType = 150
OpStructPtrHeadOmitEmptyFloat32Ptr OpType = 151
OpStructHeadFloat64Ptr OpType = 152
OpStructHeadOmitEmptyFloat64Ptr OpType = 153
OpStructPtrHeadFloat64Ptr OpType = 154
OpStructPtrHeadOmitEmptyFloat64Ptr OpType = 155
OpStructHeadBoolPtr OpType = 156
OpStructHeadOmitEmptyBoolPtr OpType = 157
OpStructPtrHeadBoolPtr OpType = 158
OpStructPtrHeadOmitEmptyBoolPtr OpType = 159
OpStructHeadStringPtr OpType = 160
OpStructHeadOmitEmptyStringPtr OpType = 161
OpStructPtrHeadStringPtr OpType = 162
OpStructPtrHeadOmitEmptyStringPtr OpType = 163
OpStructHeadBytesPtr OpType = 164
OpStructHeadOmitEmptyBytesPtr OpType = 165
OpStructPtrHeadBytesPtr OpType = 166
OpStructPtrHeadOmitEmptyBytesPtr OpType = 167
OpStructHeadNumberPtr OpType = 168
OpStructHeadOmitEmptyNumberPtr OpType = 169
OpStructPtrHeadNumberPtr OpType = 170
OpStructPtrHeadOmitEmptyNumberPtr OpType = 171
OpStructHeadArrayPtr OpType = 172
OpStructHeadOmitEmptyArrayPtr OpType = 173
OpStructPtrHeadArrayPtr OpType = 174
OpStructPtrHeadOmitEmptyArrayPtr OpType = 175
OpStructHeadMapPtr OpType = 176
OpStructHeadOmitEmptyMapPtr OpType = 177
OpStructPtrHeadMapPtr OpType = 178
OpStructPtrHeadOmitEmptyMapPtr OpType = 179
OpStructHeadSlicePtr OpType = 180
OpStructHeadOmitEmptySlicePtr OpType = 181
OpStructPtrHeadSlicePtr OpType = 182
OpStructPtrHeadOmitEmptySlicePtr OpType = 183
OpStructHeadMarshalJSONPtr OpType = 184
OpStructHeadOmitEmptyMarshalJSONPtr OpType = 185
OpStructPtrHeadMarshalJSONPtr OpType = 186
OpStructPtrHeadOmitEmptyMarshalJSONPtr OpType = 187
OpStructHeadMarshalTextPtr OpType = 188
OpStructHeadOmitEmptyMarshalTextPtr OpType = 189
OpStructPtrHeadMarshalTextPtr OpType = 190
OpStructPtrHeadOmitEmptyMarshalTextPtr OpType = 191
OpStructHeadInterfacePtr OpType = 192
OpStructHeadOmitEmptyInterfacePtr OpType = 193
OpStructPtrHeadInterfacePtr OpType = 194
OpStructPtrHeadOmitEmptyInterfacePtr OpType = 195
OpStructHeadIntPtrString OpType = 196
OpStructHeadOmitEmptyIntPtrString OpType = 197
OpStructPtrHeadIntPtrString OpType = 198
OpStructPtrHeadOmitEmptyIntPtrString OpType = 199
OpStructHeadUintPtrString OpType = 200
OpStructHeadOmitEmptyUintPtrString OpType = 201
OpStructPtrHeadUintPtrString OpType = 202
OpStructPtrHeadOmitEmptyUintPtrString OpType = 203
OpStructHeadFloat32PtrString OpType = 204
OpStructHeadOmitEmptyFloat32PtrString OpType = 205
OpStructPtrHeadFloat32PtrString OpType = 206
OpStructPtrHeadOmitEmptyFloat32PtrString OpType = 207
OpStructHeadFloat64PtrString OpType = 208
OpStructHeadOmitEmptyFloat64PtrString OpType = 209
OpStructPtrHeadFloat64PtrString OpType = 210
OpStructPtrHeadOmitEmptyFloat64PtrString OpType = 211
OpStructHeadBoolPtrString OpType = 212
OpStructHeadOmitEmptyBoolPtrString OpType = 213
OpStructPtrHeadBoolPtrString OpType = 214
OpStructPtrHeadOmitEmptyBoolPtrString OpType = 215
OpStructHeadStringPtrString OpType = 216
OpStructHeadOmitEmptyStringPtrString OpType = 217
OpStructPtrHeadStringPtrString OpType = 218
OpStructPtrHeadOmitEmptyStringPtrString OpType = 219
OpStructHeadNumberPtrString OpType = 220
OpStructHeadOmitEmptyNumberPtrString OpType = 221
OpStructPtrHeadNumberPtrString OpType = 222
OpStructPtrHeadOmitEmptyNumberPtrString OpType = 223
OpStructHead OpType = 224
OpStructHeadOmitEmpty OpType = 225
OpStructPtrHead OpType = 226
OpStructPtrHeadOmitEmpty OpType = 227
OpStructFieldInt OpType = 228
OpStructFieldOmitEmptyInt OpType = 229
OpStructEndInt OpType = 230
OpStructEndOmitEmptyInt OpType = 231
OpStructFieldUint OpType = 232
OpStructFieldOmitEmptyUint OpType = 233
OpStructEndUint OpType = 234
OpStructEndOmitEmptyUint OpType = 235
OpStructFieldFloat32 OpType = 236
OpStructFieldOmitEmptyFloat32 OpType = 237
OpStructEndFloat32 OpType = 238
OpStructEndOmitEmptyFloat32 OpType = 239
OpStructFieldFloat64 OpType = 240
OpStructFieldOmitEmptyFloat64 OpType = 241
OpStructEndFloat64 OpType = 242
OpStructEndOmitEmptyFloat64 OpType = 243
OpStructFieldBool OpType = 244
OpStructFieldOmitEmptyBool OpType = 245
OpStructEndBool OpType = 246
OpStructEndOmitEmptyBool OpType = 247
OpStructFieldString OpType = 248
OpStructFieldOmitEmptyString OpType = 249
OpStructEndString OpType = 250
OpStructEndOmitEmptyString OpType = 251
OpStructFieldBytes OpType = 252
OpStructFieldOmitEmptyBytes OpType = 253
OpStructEndBytes OpType = 254
OpStructEndOmitEmptyBytes OpType = 255
OpStructFieldNumber OpType = 256
OpStructFieldOmitEmptyNumber OpType = 257
OpStructEndNumber OpType = 258
OpStructEndOmitEmptyNumber OpType = 259
OpStructFieldArray OpType = 260
OpStructFieldOmitEmptyArray OpType = 261
OpStructEndArray OpType = 262
OpStructEndOmitEmptyArray OpType = 263
OpStructFieldMap OpType = 264
OpStructFieldOmitEmptyMap OpType = 265
OpStructEndMap OpType = 266
OpStructEndOmitEmptyMap OpType = 267
OpStructFieldSlice OpType = 268
OpStructFieldOmitEmptySlice OpType = 269
OpStructEndSlice OpType = 270
OpStructEndOmitEmptySlice OpType = 271
OpStructFieldStruct OpType = 272
OpStructFieldOmitEmptyStruct OpType = 273
OpStructEndStruct OpType = 274
OpStructEndOmitEmptyStruct OpType = 275
OpStructFieldMarshalJSON OpType = 276
OpStructFieldOmitEmptyMarshalJSON OpType = 277
OpStructEndMarshalJSON OpType = 278
OpStructEndOmitEmptyMarshalJSON OpType = 279
OpStructFieldMarshalText OpType = 280
OpStructFieldOmitEmptyMarshalText OpType = 281
OpStructEndMarshalText OpType = 282
OpStructEndOmitEmptyMarshalText OpType = 283
OpStructFieldIntString OpType = 284
OpStructFieldOmitEmptyIntString OpType = 285
OpStructEndIntString OpType = 286
OpStructEndOmitEmptyIntString OpType = 287
OpStructFieldUintString OpType = 288
OpStructFieldOmitEmptyUintString OpType = 289
OpStructEndUintString OpType = 290
OpStructEndOmitEmptyUintString OpType = 291
OpStructFieldFloat32String OpType = 292
OpStructFieldOmitEmptyFloat32String OpType = 293
OpStructEndFloat32String OpType = 294
OpStructEndOmitEmptyFloat32String OpType = 295
OpStructFieldFloat64String OpType = 296
OpStructFieldOmitEmptyFloat64String OpType = 297
OpStructEndFloat64String OpType = 298
OpStructEndOmitEmptyFloat64String OpType = 299
OpStructFieldBoolString OpType = 300
OpStructFieldOmitEmptyBoolString OpType = 301
OpStructEndBoolString OpType = 302
OpStructEndOmitEmptyBoolString OpType = 303
OpStructFieldStringString OpType = 304
OpStructFieldOmitEmptyStringString OpType = 305
OpStructEndStringString OpType = 306
OpStructEndOmitEmptyStringString OpType = 307
OpStructFieldNumberString OpType = 308
OpStructFieldOmitEmptyNumberString OpType = 309
OpStructEndNumberString OpType = 310
OpStructEndOmitEmptyNumberString OpType = 311
OpStructFieldIntPtr OpType = 312
OpStructFieldOmitEmptyIntPtr OpType = 313
OpStructEndIntPtr OpType = 314
OpStructEndOmitEmptyIntPtr OpType = 315
OpStructFieldUintPtr OpType = 316
OpStructFieldOmitEmptyUintPtr OpType = 317
OpStructEndUintPtr OpType = 318
OpStructEndOmitEmptyUintPtr OpType = 319
OpStructFieldFloat32Ptr OpType = 320
OpStructFieldOmitEmptyFloat32Ptr OpType = 321
OpStructEndFloat32Ptr OpType = 322
OpStructEndOmitEmptyFloat32Ptr OpType = 323
OpStructFieldFloat64Ptr OpType = 324
OpStructFieldOmitEmptyFloat64Ptr OpType = 325
OpStructEndFloat64Ptr OpType = 326
OpStructEndOmitEmptyFloat64Ptr OpType = 327
OpStructFieldBoolPtr OpType = 328
OpStructFieldOmitEmptyBoolPtr OpType = 329
OpStructEndBoolPtr OpType = 330
OpStructEndOmitEmptyBoolPtr OpType = 331
OpStructFieldStringPtr OpType = 332
OpStructFieldOmitEmptyStringPtr OpType = 333
OpStructEndStringPtr OpType = 334
OpStructEndOmitEmptyStringPtr OpType = 335
OpStructFieldBytesPtr OpType = 336
OpStructFieldOmitEmptyBytesPtr OpType = 337
OpStructEndBytesPtr OpType = 338
OpStructEndOmitEmptyBytesPtr OpType = 339
OpStructFieldNumberPtr OpType = 340
OpStructFieldOmitEmptyNumberPtr OpType = 341
OpStructEndNumberPtr OpType = 342
OpStructEndOmitEmptyNumberPtr OpType = 343
OpStructFieldArrayPtr OpType = 344
OpStructFieldOmitEmptyArrayPtr OpType = 345
OpStructEndArrayPtr OpType = 346
OpStructEndOmitEmptyArrayPtr OpType = 347
OpStructFieldMapPtr OpType = 348
OpStructFieldOmitEmptyMapPtr OpType = 349
OpStructEndMapPtr OpType = 350
OpStructEndOmitEmptyMapPtr OpType = 351
OpStructFieldSlicePtr OpType = 352
OpStructFieldOmitEmptySlicePtr OpType = 353
OpStructEndSlicePtr OpType = 354
OpStructEndOmitEmptySlicePtr OpType = 355
OpStructFieldMarshalJSONPtr OpType = 356
OpStructFieldOmitEmptyMarshalJSONPtr OpType = 357
OpStructEndMarshalJSONPtr OpType = 358
OpStructEndOmitEmptyMarshalJSONPtr OpType = 359
OpStructFieldMarshalTextPtr OpType = 360
OpStructFieldOmitEmptyMarshalTextPtr OpType = 361
OpStructEndMarshalTextPtr OpType = 362
OpStructEndOmitEmptyMarshalTextPtr OpType = 363
OpStructFieldInterfacePtr OpType = 364
OpStructFieldOmitEmptyInterfacePtr OpType = 365
OpStructEndInterfacePtr OpType = 366
OpStructEndOmitEmptyInterfacePtr OpType = 367
OpStructFieldIntPtrString OpType = 368
OpStructFieldOmitEmptyIntPtrString OpType = 369
OpStructEndIntPtrString OpType = 370
OpStructEndOmitEmptyIntPtrString OpType = 371
OpStructFieldUintPtrString OpType = 372
OpStructFieldOmitEmptyUintPtrString OpType = 373
OpStructEndUintPtrString OpType = 374
OpStructEndOmitEmptyUintPtrString OpType = 375
OpStructFieldFloat32PtrString OpType = 376
OpStructFieldOmitEmptyFloat32PtrString OpType = 377
OpStructEndFloat32PtrString OpType = 378
OpStructEndOmitEmptyFloat32PtrString OpType = 379
OpStructFieldFloat64PtrString OpType = 380
OpStructFieldOmitEmptyFloat64PtrString OpType = 381
OpStructEndFloat64PtrString OpType = 382
OpStructEndOmitEmptyFloat64PtrString OpType = 383
OpStructFieldBoolPtrString OpType = 384
OpStructFieldOmitEmptyBoolPtrString OpType = 385
OpStructEndBoolPtrString OpType = 386
OpStructEndOmitEmptyBoolPtrString OpType = 387
OpStructFieldStringPtrString OpType = 388
OpStructFieldOmitEmptyStringPtrString OpType = 389
OpStructEndStringPtrString OpType = 390
OpStructEndOmitEmptyStringPtrString OpType = 391
OpStructFieldNumberPtrString OpType = 392
OpStructFieldOmitEmptyNumberPtrString OpType = 393
OpStructEndNumberPtrString OpType = 394
OpStructEndOmitEmptyNumberPtrString OpType = 395
OpStructField OpType = 396
OpStructFieldOmitEmpty OpType = 397
OpStructEnd OpType = 398
OpStructEndOmitEmpty OpType = 399
OpInterfaceEnd OpType = 13
OpStructAnonymousEnd OpType = 14
OpInt OpType = 15
OpUint OpType = 16
OpFloat32 OpType = 17
OpFloat64 OpType = 18
OpBool OpType = 19
OpString OpType = 20
OpBytes OpType = 21
OpNumber OpType = 22
OpArray OpType = 23
OpMap OpType = 24
OpSlice OpType = 25
OpStruct OpType = 26
OpMarshalJSON OpType = 27
OpMarshalText OpType = 28
OpIntString OpType = 29
OpUintString OpType = 30
OpFloat32String OpType = 31
OpFloat64String OpType = 32
OpBoolString OpType = 33
OpStringString OpType = 34
OpNumberString OpType = 35
OpIntPtr OpType = 36
OpUintPtr OpType = 37
OpFloat32Ptr OpType = 38
OpFloat64Ptr OpType = 39
OpBoolPtr OpType = 40
OpStringPtr OpType = 41
OpBytesPtr OpType = 42
OpNumberPtr OpType = 43
OpArrayPtr OpType = 44
OpMapPtr OpType = 45
OpSlicePtr OpType = 46
OpMarshalJSONPtr OpType = 47
OpMarshalTextPtr OpType = 48
OpInterfacePtr OpType = 49
OpIntPtrString OpType = 50
OpUintPtrString OpType = 51
OpFloat32PtrString OpType = 52
OpFloat64PtrString OpType = 53
OpBoolPtrString OpType = 54
OpStringPtrString OpType = 55
OpNumberPtrString OpType = 56
OpStructHeadInt OpType = 57
OpStructHeadOmitEmptyInt OpType = 58
OpStructPtrHeadInt OpType = 59
OpStructPtrHeadOmitEmptyInt OpType = 60
OpStructHeadUint OpType = 61
OpStructHeadOmitEmptyUint OpType = 62
OpStructPtrHeadUint OpType = 63
OpStructPtrHeadOmitEmptyUint OpType = 64
OpStructHeadFloat32 OpType = 65
OpStructHeadOmitEmptyFloat32 OpType = 66
OpStructPtrHeadFloat32 OpType = 67
OpStructPtrHeadOmitEmptyFloat32 OpType = 68
OpStructHeadFloat64 OpType = 69
OpStructHeadOmitEmptyFloat64 OpType = 70
OpStructPtrHeadFloat64 OpType = 71
OpStructPtrHeadOmitEmptyFloat64 OpType = 72
OpStructHeadBool OpType = 73
OpStructHeadOmitEmptyBool OpType = 74
OpStructPtrHeadBool OpType = 75
OpStructPtrHeadOmitEmptyBool OpType = 76
OpStructHeadString OpType = 77
OpStructHeadOmitEmptyString OpType = 78
OpStructPtrHeadString OpType = 79
OpStructPtrHeadOmitEmptyString OpType = 80
OpStructHeadBytes OpType = 81
OpStructHeadOmitEmptyBytes OpType = 82
OpStructPtrHeadBytes OpType = 83
OpStructPtrHeadOmitEmptyBytes OpType = 84
OpStructHeadNumber OpType = 85
OpStructHeadOmitEmptyNumber OpType = 86
OpStructPtrHeadNumber OpType = 87
OpStructPtrHeadOmitEmptyNumber OpType = 88
OpStructHeadArray OpType = 89
OpStructHeadOmitEmptyArray OpType = 90
OpStructPtrHeadArray OpType = 91
OpStructPtrHeadOmitEmptyArray OpType = 92
OpStructHeadMap OpType = 93
OpStructHeadOmitEmptyMap OpType = 94
OpStructPtrHeadMap OpType = 95
OpStructPtrHeadOmitEmptyMap OpType = 96
OpStructHeadSlice OpType = 97
OpStructHeadOmitEmptySlice OpType = 98
OpStructPtrHeadSlice OpType = 99
OpStructPtrHeadOmitEmptySlice OpType = 100
OpStructHeadStruct OpType = 101
OpStructHeadOmitEmptyStruct OpType = 102
OpStructPtrHeadStruct OpType = 103
OpStructPtrHeadOmitEmptyStruct OpType = 104
OpStructHeadMarshalJSON OpType = 105
OpStructHeadOmitEmptyMarshalJSON OpType = 106
OpStructPtrHeadMarshalJSON OpType = 107
OpStructPtrHeadOmitEmptyMarshalJSON OpType = 108
OpStructHeadMarshalText OpType = 109
OpStructHeadOmitEmptyMarshalText OpType = 110
OpStructPtrHeadMarshalText OpType = 111
OpStructPtrHeadOmitEmptyMarshalText OpType = 112
OpStructHeadIntString OpType = 113
OpStructHeadOmitEmptyIntString OpType = 114
OpStructPtrHeadIntString OpType = 115
OpStructPtrHeadOmitEmptyIntString OpType = 116
OpStructHeadUintString OpType = 117
OpStructHeadOmitEmptyUintString OpType = 118
OpStructPtrHeadUintString OpType = 119
OpStructPtrHeadOmitEmptyUintString OpType = 120
OpStructHeadFloat32String OpType = 121
OpStructHeadOmitEmptyFloat32String OpType = 122
OpStructPtrHeadFloat32String OpType = 123
OpStructPtrHeadOmitEmptyFloat32String OpType = 124
OpStructHeadFloat64String OpType = 125
OpStructHeadOmitEmptyFloat64String OpType = 126
OpStructPtrHeadFloat64String OpType = 127
OpStructPtrHeadOmitEmptyFloat64String OpType = 128
OpStructHeadBoolString OpType = 129
OpStructHeadOmitEmptyBoolString OpType = 130
OpStructPtrHeadBoolString OpType = 131
OpStructPtrHeadOmitEmptyBoolString OpType = 132
OpStructHeadStringString OpType = 133
OpStructHeadOmitEmptyStringString OpType = 134
OpStructPtrHeadStringString OpType = 135
OpStructPtrHeadOmitEmptyStringString OpType = 136
OpStructHeadNumberString OpType = 137
OpStructHeadOmitEmptyNumberString OpType = 138
OpStructPtrHeadNumberString OpType = 139
OpStructPtrHeadOmitEmptyNumberString OpType = 140
OpStructHeadIntPtr OpType = 141
OpStructHeadOmitEmptyIntPtr OpType = 142
OpStructPtrHeadIntPtr OpType = 143
OpStructPtrHeadOmitEmptyIntPtr OpType = 144
OpStructHeadUintPtr OpType = 145
OpStructHeadOmitEmptyUintPtr OpType = 146
OpStructPtrHeadUintPtr OpType = 147
OpStructPtrHeadOmitEmptyUintPtr OpType = 148
OpStructHeadFloat32Ptr OpType = 149
OpStructHeadOmitEmptyFloat32Ptr OpType = 150
OpStructPtrHeadFloat32Ptr OpType = 151
OpStructPtrHeadOmitEmptyFloat32Ptr OpType = 152
OpStructHeadFloat64Ptr OpType = 153
OpStructHeadOmitEmptyFloat64Ptr OpType = 154
OpStructPtrHeadFloat64Ptr OpType = 155
OpStructPtrHeadOmitEmptyFloat64Ptr OpType = 156
OpStructHeadBoolPtr OpType = 157
OpStructHeadOmitEmptyBoolPtr OpType = 158
OpStructPtrHeadBoolPtr OpType = 159
OpStructPtrHeadOmitEmptyBoolPtr OpType = 160
OpStructHeadStringPtr OpType = 161
OpStructHeadOmitEmptyStringPtr OpType = 162
OpStructPtrHeadStringPtr OpType = 163
OpStructPtrHeadOmitEmptyStringPtr OpType = 164
OpStructHeadBytesPtr OpType = 165
OpStructHeadOmitEmptyBytesPtr OpType = 166
OpStructPtrHeadBytesPtr OpType = 167
OpStructPtrHeadOmitEmptyBytesPtr OpType = 168
OpStructHeadNumberPtr OpType = 169
OpStructHeadOmitEmptyNumberPtr OpType = 170
OpStructPtrHeadNumberPtr OpType = 171
OpStructPtrHeadOmitEmptyNumberPtr OpType = 172
OpStructHeadArrayPtr OpType = 173
OpStructHeadOmitEmptyArrayPtr OpType = 174
OpStructPtrHeadArrayPtr OpType = 175
OpStructPtrHeadOmitEmptyArrayPtr OpType = 176
OpStructHeadMapPtr OpType = 177
OpStructHeadOmitEmptyMapPtr OpType = 178
OpStructPtrHeadMapPtr OpType = 179
OpStructPtrHeadOmitEmptyMapPtr OpType = 180
OpStructHeadSlicePtr OpType = 181
OpStructHeadOmitEmptySlicePtr OpType = 182
OpStructPtrHeadSlicePtr OpType = 183
OpStructPtrHeadOmitEmptySlicePtr OpType = 184
OpStructHeadMarshalJSONPtr OpType = 185
OpStructHeadOmitEmptyMarshalJSONPtr OpType = 186
OpStructPtrHeadMarshalJSONPtr OpType = 187
OpStructPtrHeadOmitEmptyMarshalJSONPtr OpType = 188
OpStructHeadMarshalTextPtr OpType = 189
OpStructHeadOmitEmptyMarshalTextPtr OpType = 190
OpStructPtrHeadMarshalTextPtr OpType = 191
OpStructPtrHeadOmitEmptyMarshalTextPtr OpType = 192
OpStructHeadInterfacePtr OpType = 193
OpStructHeadOmitEmptyInterfacePtr OpType = 194
OpStructPtrHeadInterfacePtr OpType = 195
OpStructPtrHeadOmitEmptyInterfacePtr OpType = 196
OpStructHeadIntPtrString OpType = 197
OpStructHeadOmitEmptyIntPtrString OpType = 198
OpStructPtrHeadIntPtrString OpType = 199
OpStructPtrHeadOmitEmptyIntPtrString OpType = 200
OpStructHeadUintPtrString OpType = 201
OpStructHeadOmitEmptyUintPtrString OpType = 202
OpStructPtrHeadUintPtrString OpType = 203
OpStructPtrHeadOmitEmptyUintPtrString OpType = 204
OpStructHeadFloat32PtrString OpType = 205
OpStructHeadOmitEmptyFloat32PtrString OpType = 206
OpStructPtrHeadFloat32PtrString OpType = 207
OpStructPtrHeadOmitEmptyFloat32PtrString OpType = 208
OpStructHeadFloat64PtrString OpType = 209
OpStructHeadOmitEmptyFloat64PtrString OpType = 210
OpStructPtrHeadFloat64PtrString OpType = 211
OpStructPtrHeadOmitEmptyFloat64PtrString OpType = 212
OpStructHeadBoolPtrString OpType = 213
OpStructHeadOmitEmptyBoolPtrString OpType = 214
OpStructPtrHeadBoolPtrString OpType = 215
OpStructPtrHeadOmitEmptyBoolPtrString OpType = 216
OpStructHeadStringPtrString OpType = 217
OpStructHeadOmitEmptyStringPtrString OpType = 218
OpStructPtrHeadStringPtrString OpType = 219
OpStructPtrHeadOmitEmptyStringPtrString OpType = 220
OpStructHeadNumberPtrString OpType = 221
OpStructHeadOmitEmptyNumberPtrString OpType = 222
OpStructPtrHeadNumberPtrString OpType = 223
OpStructPtrHeadOmitEmptyNumberPtrString OpType = 224
OpStructHead OpType = 225
OpStructHeadOmitEmpty OpType = 226
OpStructPtrHead OpType = 227
OpStructPtrHeadOmitEmpty OpType = 228
OpStructFieldInt OpType = 229
OpStructFieldOmitEmptyInt OpType = 230
OpStructEndInt OpType = 231
OpStructEndOmitEmptyInt OpType = 232
OpStructFieldUint OpType = 233
OpStructFieldOmitEmptyUint OpType = 234
OpStructEndUint OpType = 235
OpStructEndOmitEmptyUint OpType = 236
OpStructFieldFloat32 OpType = 237
OpStructFieldOmitEmptyFloat32 OpType = 238
OpStructEndFloat32 OpType = 239
OpStructEndOmitEmptyFloat32 OpType = 240
OpStructFieldFloat64 OpType = 241
OpStructFieldOmitEmptyFloat64 OpType = 242
OpStructEndFloat64 OpType = 243
OpStructEndOmitEmptyFloat64 OpType = 244
OpStructFieldBool OpType = 245
OpStructFieldOmitEmptyBool OpType = 246
OpStructEndBool OpType = 247
OpStructEndOmitEmptyBool OpType = 248
OpStructFieldString OpType = 249
OpStructFieldOmitEmptyString OpType = 250
OpStructEndString OpType = 251
OpStructEndOmitEmptyString OpType = 252
OpStructFieldBytes OpType = 253
OpStructFieldOmitEmptyBytes OpType = 254
OpStructEndBytes OpType = 255
OpStructEndOmitEmptyBytes OpType = 256
OpStructFieldNumber OpType = 257
OpStructFieldOmitEmptyNumber OpType = 258
OpStructEndNumber OpType = 259
OpStructEndOmitEmptyNumber OpType = 260
OpStructFieldArray OpType = 261
OpStructFieldOmitEmptyArray OpType = 262
OpStructEndArray OpType = 263
OpStructEndOmitEmptyArray OpType = 264
OpStructFieldMap OpType = 265
OpStructFieldOmitEmptyMap OpType = 266
OpStructEndMap OpType = 267
OpStructEndOmitEmptyMap OpType = 268
OpStructFieldSlice OpType = 269
OpStructFieldOmitEmptySlice OpType = 270
OpStructEndSlice OpType = 271
OpStructEndOmitEmptySlice OpType = 272
OpStructFieldStruct OpType = 273
OpStructFieldOmitEmptyStruct OpType = 274
OpStructEndStruct OpType = 275
OpStructEndOmitEmptyStruct OpType = 276
OpStructFieldMarshalJSON OpType = 277
OpStructFieldOmitEmptyMarshalJSON OpType = 278
OpStructEndMarshalJSON OpType = 279
OpStructEndOmitEmptyMarshalJSON OpType = 280
OpStructFieldMarshalText OpType = 281
OpStructFieldOmitEmptyMarshalText OpType = 282
OpStructEndMarshalText OpType = 283
OpStructEndOmitEmptyMarshalText OpType = 284
OpStructFieldIntString OpType = 285
OpStructFieldOmitEmptyIntString OpType = 286
OpStructEndIntString OpType = 287
OpStructEndOmitEmptyIntString OpType = 288
OpStructFieldUintString OpType = 289
OpStructFieldOmitEmptyUintString OpType = 290
OpStructEndUintString OpType = 291
OpStructEndOmitEmptyUintString OpType = 292
OpStructFieldFloat32String OpType = 293
OpStructFieldOmitEmptyFloat32String OpType = 294
OpStructEndFloat32String OpType = 295
OpStructEndOmitEmptyFloat32String OpType = 296
OpStructFieldFloat64String OpType = 297
OpStructFieldOmitEmptyFloat64String OpType = 298
OpStructEndFloat64String OpType = 299
OpStructEndOmitEmptyFloat64String OpType = 300
OpStructFieldBoolString OpType = 301
OpStructFieldOmitEmptyBoolString OpType = 302
OpStructEndBoolString OpType = 303
OpStructEndOmitEmptyBoolString OpType = 304
OpStructFieldStringString OpType = 305
OpStructFieldOmitEmptyStringString OpType = 306
OpStructEndStringString OpType = 307
OpStructEndOmitEmptyStringString OpType = 308
OpStructFieldNumberString OpType = 309
OpStructFieldOmitEmptyNumberString OpType = 310
OpStructEndNumberString OpType = 311
OpStructEndOmitEmptyNumberString OpType = 312
OpStructFieldIntPtr OpType = 313
OpStructFieldOmitEmptyIntPtr OpType = 314
OpStructEndIntPtr OpType = 315
OpStructEndOmitEmptyIntPtr OpType = 316
OpStructFieldUintPtr OpType = 317
OpStructFieldOmitEmptyUintPtr OpType = 318
OpStructEndUintPtr OpType = 319
OpStructEndOmitEmptyUintPtr OpType = 320
OpStructFieldFloat32Ptr OpType = 321
OpStructFieldOmitEmptyFloat32Ptr OpType = 322
OpStructEndFloat32Ptr OpType = 323
OpStructEndOmitEmptyFloat32Ptr OpType = 324
OpStructFieldFloat64Ptr OpType = 325
OpStructFieldOmitEmptyFloat64Ptr OpType = 326
OpStructEndFloat64Ptr OpType = 327
OpStructEndOmitEmptyFloat64Ptr OpType = 328
OpStructFieldBoolPtr OpType = 329
OpStructFieldOmitEmptyBoolPtr OpType = 330
OpStructEndBoolPtr OpType = 331
OpStructEndOmitEmptyBoolPtr OpType = 332
OpStructFieldStringPtr OpType = 333
OpStructFieldOmitEmptyStringPtr OpType = 334
OpStructEndStringPtr OpType = 335
OpStructEndOmitEmptyStringPtr OpType = 336
OpStructFieldBytesPtr OpType = 337
OpStructFieldOmitEmptyBytesPtr OpType = 338
OpStructEndBytesPtr OpType = 339
OpStructEndOmitEmptyBytesPtr OpType = 340
OpStructFieldNumberPtr OpType = 341
OpStructFieldOmitEmptyNumberPtr OpType = 342
OpStructEndNumberPtr OpType = 343
OpStructEndOmitEmptyNumberPtr OpType = 344
OpStructFieldArrayPtr OpType = 345
OpStructFieldOmitEmptyArrayPtr OpType = 346
OpStructEndArrayPtr OpType = 347
OpStructEndOmitEmptyArrayPtr OpType = 348
OpStructFieldMapPtr OpType = 349
OpStructFieldOmitEmptyMapPtr OpType = 350
OpStructEndMapPtr OpType = 351
OpStructEndOmitEmptyMapPtr OpType = 352
OpStructFieldSlicePtr OpType = 353
OpStructFieldOmitEmptySlicePtr OpType = 354
OpStructEndSlicePtr OpType = 355
OpStructEndOmitEmptySlicePtr OpType = 356
OpStructFieldMarshalJSONPtr OpType = 357
OpStructFieldOmitEmptyMarshalJSONPtr OpType = 358
OpStructEndMarshalJSONPtr OpType = 359
OpStructEndOmitEmptyMarshalJSONPtr OpType = 360
OpStructFieldMarshalTextPtr OpType = 361
OpStructFieldOmitEmptyMarshalTextPtr OpType = 362
OpStructEndMarshalTextPtr OpType = 363
OpStructEndOmitEmptyMarshalTextPtr OpType = 364
OpStructFieldInterfacePtr OpType = 365
OpStructFieldOmitEmptyInterfacePtr OpType = 366
OpStructEndInterfacePtr OpType = 367
OpStructEndOmitEmptyInterfacePtr OpType = 368
OpStructFieldIntPtrString OpType = 369
OpStructFieldOmitEmptyIntPtrString OpType = 370
OpStructEndIntPtrString OpType = 371
OpStructEndOmitEmptyIntPtrString OpType = 372
OpStructFieldUintPtrString OpType = 373
OpStructFieldOmitEmptyUintPtrString OpType = 374
OpStructEndUintPtrString OpType = 375
OpStructEndOmitEmptyUintPtrString OpType = 376
OpStructFieldFloat32PtrString OpType = 377
OpStructFieldOmitEmptyFloat32PtrString OpType = 378
OpStructEndFloat32PtrString OpType = 379
OpStructEndOmitEmptyFloat32PtrString OpType = 380
OpStructFieldFloat64PtrString OpType = 381
OpStructFieldOmitEmptyFloat64PtrString OpType = 382
OpStructEndFloat64PtrString OpType = 383
OpStructEndOmitEmptyFloat64PtrString OpType = 384
OpStructFieldBoolPtrString OpType = 385
OpStructFieldOmitEmptyBoolPtrString OpType = 386
OpStructEndBoolPtrString OpType = 387
OpStructEndOmitEmptyBoolPtrString OpType = 388
OpStructFieldStringPtrString OpType = 389
OpStructFieldOmitEmptyStringPtrString OpType = 390
OpStructEndStringPtrString OpType = 391
OpStructEndOmitEmptyStringPtrString OpType = 392
OpStructFieldNumberPtrString OpType = 393
OpStructFieldOmitEmptyNumberPtrString OpType = 394
OpStructEndNumberPtrString OpType = 395
OpStructEndOmitEmptyNumberPtrString OpType = 396
OpStructField OpType = 397
OpStructFieldOmitEmpty OpType = 398
OpStructEnd OpType = 399
OpStructEndOmitEmpty OpType = 400
)
func (t OpType) String() string {
if int(t) >= 400 {
if int(t) >= 401 {
return ""
}
return opTypeStrings[int(t)]

View file

@ -405,7 +405,10 @@ func stringToUint64Slice(s string) []uint64 {
}))
}
func AppendEscapedString(buf []byte, s string) []byte {
func AppendString(ctx *RuntimeContext, buf []byte, s string) []byte {
if ctx.Option.Flag&HTMLEscapeOption == 0 {
return appendString(buf, s)
}
valLen := len(s)
if valLen == 0 {
return append(buf, `""`...)
@ -531,7 +534,7 @@ ESCAPE_END:
return append(append(buf, s[i:]...), '"')
}
func AppendString(buf []byte, s string) []byte {
func appendString(buf []byte, s string) []byte {
valLen := len(s)
if valLen == 0 {
return append(buf, `""`...)

View file

@ -6,15 +6,22 @@ import (
"github.com/goccy/go-json/internal/encoder"
)
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt encoder.Option) ([]byte, error) {
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
defer func() {
var code *encoder.Opcode
if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
code = codeSet.EscapeKeyCode
} else {
code = codeSet.NoescapeKeyCode
}
if err := recover(); err != nil {
fmt.Println("=============[DEBUG]===============")
fmt.Println("* [TYPE]")
fmt.Println(codeSet.Type)
fmt.Printf("\n")
fmt.Println("* [ALL OPCODE]")
fmt.Println(codeSet.Code.Dump())
fmt.Println(code.Dump())
fmt.Printf("\n")
fmt.Println("* [CONTEXT]")
fmt.Printf("%+v\n", ctx)
@ -23,5 +30,5 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
}
}()
return Run(ctx, b, codeSet, opt)
return Run(ctx, b, codeSet)
}

View file

@ -2,8 +2,8 @@ package vm
import (
// HACK: compile order
// `vm`, `vm_escaped`, `vm_indent`, `vm_escaped_indent` packages uses a lot of memory to compile,
// `vm`, `vm_indent`, `vm_color`, `vm_color_indent` packages uses a lot of memory to compile,
// so forcibly make dependencies and avoid compiling in concurrent.
// dependency order: vm => vm_escaped => vm_indent => vm_escaped_indent
_ "github.com/goccy/go-json/internal/encoder/vm_escaped"
// dependency order: vm => vm_indent => vm_color => vm_color_indent
_ "github.com/goccy/go-json/internal/encoder/vm_indent"
)

View file

@ -33,24 +33,33 @@ type emptyInterface struct {
ptr unsafe.Pointer
}
type nonEmptyInterface struct {
itab *struct {
ityp *runtime.Type // static interface type
typ *runtime.Type // dynamic concrete type
// unused fields...
}
ptr unsafe.Pointer
}
func errUnimplementedOp(op encoder.OpType) error {
return fmt.Errorf("encoder: opcode %s has not been implemented", op)
}
func load(base uintptr, idx uintptr) uintptr {
addr := base + idx
func load(base uintptr, idx uint32) uintptr {
addr := base + uintptr(idx)
return **(**uintptr)(unsafe.Pointer(&addr))
}
func store(base uintptr, idx uintptr, p uintptr) {
addr := base + idx
func store(base uintptr, idx uint32, p uintptr) {
addr := base + uintptr(idx)
**(**uintptr)(unsafe.Pointer(&addr)) = p
}
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
addr := base + idx
func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr {
addr := base + uintptr(idx)
p := **(**uintptr)(unsafe.Pointer(&addr))
for i := 0; i < ptrNum; i++ {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -70,8 +79,8 @@ func ptrToSlice(p uintptr) *runtime.SliceHeader { return *(**runtime.SliceHeader
func ptrToPtr(p uintptr) uintptr {
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
}
func ptrToNPtr(p uintptr, ptrNum int) uintptr {
for i := 0; i < ptrNum; i++ {
func ptrToNPtr(p uintptr, ptrNum uint8) uintptr {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -90,22 +99,22 @@ func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} {
}))
}
func appendBool(b []byte, v bool) []byte {
func appendBool(_ *encoder.RuntimeContext, b []byte, v bool) []byte {
if v {
return append(b, "true"...)
}
return append(b, "false"...)
}
func appendNull(b []byte) []byte {
func appendNull(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, "null"...)
}
func appendComma(b []byte) []byte {
func appendComma(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, ',')
}
func appendColon(b []byte) []byte {
func appendColon(_ *encoder.RuntimeContext, b []byte) []byte {
last := len(b) - 1
b[last] = ':'
return b
@ -123,45 +132,12 @@ func appendMapEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte
return b
}
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, opt encoder.Option, _ *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
if err != nil {
return nil, err
}
totalLength := uintptr(codeSet.CodeLength)
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
curlen := uintptr(len(ctx.Ptrs))
offsetNum := ptrOffset / uintptrSize
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
}
oldPtrs := ctx.Ptrs
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
newPtrs[0] = uintptr(iface.ptr)
ctx.Ptrs = newPtrs
bb, err := Run(ctx, b, ifaceCodeSet, opt)
if err != nil {
return nil, err
}
ctx.Ptrs = oldPtrs
return bb, nil
}
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalJSON(ctx, code, b, v, false)
return encoder.AppendMarshalJSON(ctx, code, b, v)
}
func appendMarshalText(code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalText(code, b, v, false)
func appendMarshalText(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalText(ctx, code, b, v)
}
func appendArrayHead(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
@ -174,11 +150,11 @@ func appendArrayEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []by
return append(b, ',')
}
func appendEmptyArray(b []byte) []byte {
func appendEmptyArray(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '[', ']', ',')
}
func appendEmptyObject(b []byte) []byte {
func appendEmptyObject(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{', '}', ',')
}
@ -188,7 +164,7 @@ func appendObjectEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []b
return append(b, ',')
}
func appendStructHead(b []byte) []byte {
func appendStructHead(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{')
}
@ -204,7 +180,7 @@ func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode,
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
return appendComma(b)
return appendComma(ctx, b)
}
return appendStructEnd(ctx, code, b)
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
package vm_escaped
package vm_color
import (
"fmt"
@ -6,7 +6,14 @@ import (
"github.com/goccy/go-json/internal/encoder"
)
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt encoder.Option) ([]byte, error) {
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
var code *encoder.Opcode
if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
code = codeSet.EscapeKeyCode
} else {
code = codeSet.NoescapeKeyCode
}
defer func() {
if err := recover(); err != nil {
fmt.Println("=============[DEBUG]===============")
@ -14,7 +21,7 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
fmt.Println(codeSet.Type)
fmt.Printf("\n")
fmt.Println("* [ALL OPCODE]")
fmt.Println(codeSet.Code.Dump())
fmt.Println(code.Dump())
fmt.Printf("\n")
fmt.Println("* [CONTEXT]")
fmt.Printf("%+v\n", ctx)
@ -23,5 +30,5 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
}
}()
return Run(ctx, b, codeSet, opt)
return Run(ctx, b, codeSet)
}

View file

@ -0,0 +1,9 @@
package vm_color
import (
// HACK: compile order
// `vm`, `vm_indent`, `vm_color`, `vm_color_indent` packages uses a lot of memory to compile,
// so forcibly make dependencies and avoid compiling in concurrent.
// dependency order: vm => vm_indent => vm_color => vm_color_indent
_ "github.com/goccy/go-json/internal/encoder/vm_color_indent"
)

View file

@ -1,4 +1,4 @@
package vm_escaped
package vm_color
import (
"encoding/json"
@ -12,13 +12,6 @@ import (
const uintptrSize = 4 << (^uintptr(0) >> 63)
var (
appendInt = encoder.AppendInt
appendUint = encoder.AppendUint
appendFloat32 = encoder.AppendFloat32
appendFloat64 = encoder.AppendFloat64
appendString = encoder.AppendEscapedString
appendByteSlice = encoder.AppendByteSlice
appendNumber = encoder.AppendNumber
errUnsupportedValue = encoder.ErrUnsupportedValue
errUnsupportedFloat = encoder.ErrUnsupportedFloat
mapiterinit = encoder.MapIterInit
@ -33,24 +26,33 @@ type emptyInterface struct {
ptr unsafe.Pointer
}
func errUnimplementedOp(op encoder.OpType) error {
return fmt.Errorf("encoder (escaped): opcode %s has not been implemented", op)
type nonEmptyInterface struct {
itab *struct {
ityp *runtime.Type // static interface type
typ *runtime.Type // dynamic concrete type
// unused fields...
}
ptr unsafe.Pointer
}
func load(base uintptr, idx uintptr) uintptr {
addr := base + idx
func errUnimplementedOp(op encoder.OpType) error {
return fmt.Errorf("encoder: opcode %s has not been implemented", op)
}
func load(base uintptr, idx uint32) uintptr {
addr := base + uintptr(idx)
return **(**uintptr)(unsafe.Pointer(&addr))
}
func store(base uintptr, idx uintptr, p uintptr) {
addr := base + idx
func store(base uintptr, idx uint32, p uintptr) {
addr := base + uintptr(idx)
**(**uintptr)(unsafe.Pointer(&addr)) = p
}
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
addr := base + idx
func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr {
addr := base + uintptr(idx)
p := **(**uintptr)(unsafe.Pointer(&addr))
for i := 0; i < ptrNum; i++ {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -70,8 +72,8 @@ func ptrToSlice(p uintptr) *runtime.SliceHeader { return *(**runtime.SliceHeader
func ptrToPtr(p uintptr) uintptr {
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
}
func ptrToNPtr(p uintptr, ptrNum int) uintptr {
for i := 0; i < ptrNum; i++ {
func ptrToNPtr(p uintptr, ptrNum uint8) uintptr {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -90,78 +92,111 @@ func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} {
}))
}
func appendBool(b []byte, v bool) []byte {
if v {
return append(b, "true"...)
func appendInt(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte {
format := ctx.Option.ColorScheme.Int
b = append(b, format.Header...)
b = encoder.AppendInt(ctx, b, v, code)
return append(b, format.Footer...)
}
func appendUint(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte {
format := ctx.Option.ColorScheme.Uint
b = append(b, format.Header...)
b = encoder.AppendUint(ctx, b, v, code)
return append(b, format.Footer...)
}
func appendFloat32(ctx *encoder.RuntimeContext, b []byte, v float32) []byte {
format := ctx.Option.ColorScheme.Float
b = append(b, format.Header...)
b = encoder.AppendFloat32(ctx, b, v)
return append(b, format.Footer...)
}
func appendFloat64(ctx *encoder.RuntimeContext, b []byte, v float64) []byte {
format := ctx.Option.ColorScheme.Float
b = append(b, format.Header...)
b = encoder.AppendFloat64(ctx, b, v)
return append(b, format.Footer...)
}
func appendString(ctx *encoder.RuntimeContext, b []byte, v string) []byte {
format := ctx.Option.ColorScheme.String
b = append(b, format.Header...)
b = encoder.AppendString(ctx, b, v)
return append(b, format.Footer...)
}
func appendByteSlice(ctx *encoder.RuntimeContext, b []byte, src []byte) []byte {
format := ctx.Option.ColorScheme.Binary
b = append(b, format.Header...)
b = encoder.AppendByteSlice(ctx, b, src)
return append(b, format.Footer...)
}
func appendNumber(ctx *encoder.RuntimeContext, b []byte, n json.Number) ([]byte, error) {
format := ctx.Option.ColorScheme.Int
b = append(b, format.Header...)
bb, err := encoder.AppendNumber(ctx, b, n)
if err != nil {
return nil, err
}
return append(b, "false"...)
return append(bb, format.Footer...), nil
}
func appendNull(b []byte) []byte {
return append(b, "null"...)
func appendBool(ctx *encoder.RuntimeContext, b []byte, v bool) []byte {
format := ctx.Option.ColorScheme.Bool
b = append(b, format.Header...)
if v {
b = append(b, "true"...)
} else {
b = append(b, "false"...)
}
return append(b, format.Footer...)
}
func appendComma(b []byte) []byte {
func appendNull(ctx *encoder.RuntimeContext, b []byte) []byte {
format := ctx.Option.ColorScheme.Null
b = append(b, format.Header...)
b = append(b, "null"...)
return append(b, format.Footer...)
}
func appendComma(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, ',')
}
func appendColon(b []byte) []byte {
func appendColon(_ *encoder.RuntimeContext, b []byte) []byte {
last := len(b) - 1
b[last] = ':'
return b
}
func appendMapKeyValue(_ *encoder.RuntimeContext, _ *encoder.Opcode, b, key, value []byte) []byte {
b = append(b, key...)
b[len(b)-1] = ':'
b = append(b, key[:len(key)-1]...)
b = append(b, ':')
return append(b, value...)
}
func appendMapEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
b[len(b)-1] = '}'
last := len(b) - 1
b[last] = '}'
b = append(b, ',')
return b
}
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, opt encoder.Option, _ *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
if err != nil {
return nil, err
}
totalLength := uintptr(codeSet.CodeLength)
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
curlen := uintptr(len(ctx.Ptrs))
offsetNum := ptrOffset / uintptrSize
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
}
oldPtrs := ctx.Ptrs
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
newPtrs[0] = uintptr(iface.ptr)
ctx.Ptrs = newPtrs
bb, err := Run(ctx, b, ifaceCodeSet, opt)
if err != nil {
return nil, err
}
ctx.Ptrs = oldPtrs
return bb, nil
}
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalJSON(ctx, code, b, v, true)
return encoder.AppendMarshalJSON(ctx, code, b, v)
}
func appendMarshalText(code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalText(code, b, v, true)
func appendMarshalText(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
format := ctx.Option.ColorScheme.String
b = append(b, format.Header...)
bb, err := encoder.AppendMarshalText(ctx, code, b, v)
if err != nil {
return nil, err
}
return append(bb, format.Footer...), nil
}
func appendArrayHead(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
@ -174,11 +209,11 @@ func appendArrayEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []by
return append(b, ',')
}
func appendEmptyArray(b []byte) []byte {
func appendEmptyArray(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '[', ']', ',')
}
func appendEmptyObject(b []byte) []byte {
func appendEmptyObject(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{', '}', ',')
}
@ -188,12 +223,17 @@ func appendObjectEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []b
return append(b, ',')
}
func appendStructHead(b []byte) []byte {
func appendStructHead(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{')
}
func appendStructKey(_ *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
return append(b, code.EscapedKey...)
func appendStructKey(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
format := ctx.Option.ColorScheme.ObjectKey
b = append(b, format.Header...)
b = append(b, code.Key[:len(code.Key)-1]...)
b = append(b, format.Footer...)
return append(b, ':')
}
func appendStructEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
@ -204,7 +244,7 @@ func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode,
last := len(b) - 1
if b[last] == ',' {
b[last] = '}'
return appendComma(b)
return appendComma(ctx, b)
}
return appendStructEnd(ctx, code, b)
}

View file

@ -1,4 +1,4 @@
package vm_escaped_indent
package vm_color_indent
import (
"fmt"
@ -6,7 +6,14 @@ import (
"github.com/goccy/go-json/internal/encoder"
)
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt encoder.Option) ([]byte, error) {
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
var code *encoder.Opcode
if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
code = codeSet.EscapeKeyCode
} else {
code = codeSet.NoescapeKeyCode
}
defer func() {
if err := recover(); err != nil {
fmt.Println("=============[DEBUG]===============")
@ -14,7 +21,7 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
fmt.Println(codeSet.Type)
fmt.Printf("\n")
fmt.Println("* [ALL OPCODE]")
fmt.Println(codeSet.Code.Dump())
fmt.Println(code.Dump())
fmt.Printf("\n")
fmt.Println("* [CONTEXT]")
fmt.Printf("%+v\n", ctx)
@ -23,5 +30,5 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
}
}()
return Run(ctx, b, codeSet, opt)
return Run(ctx, b, codeSet)
}

View file

@ -1,4 +1,4 @@
package vm_escaped_indent
package vm_color_indent
import (
"encoding/json"
@ -12,15 +12,8 @@ import (
const uintptrSize = 4 << (^uintptr(0) >> 63)
var (
appendInt = encoder.AppendInt
appendUint = encoder.AppendUint
appendFloat32 = encoder.AppendFloat32
appendFloat64 = encoder.AppendFloat64
appendString = encoder.AppendString
appendByteSlice = encoder.AppendByteSlice
appendNumber = encoder.AppendNumber
appendStructEnd = encoder.AppendStructEndIndent
appendIndent = encoder.AppendIndent
appendStructEnd = encoder.AppendStructEndIndent
errUnsupportedValue = encoder.ErrUnsupportedValue
errUnsupportedFloat = encoder.ErrUnsupportedFloat
mapiterinit = encoder.MapIterInit
@ -35,24 +28,33 @@ type emptyInterface struct {
ptr unsafe.Pointer
}
func errUnimplementedOp(op encoder.OpType) error {
return fmt.Errorf("encoder (indent+escaped): opcode %s has not been implemented", op)
type nonEmptyInterface struct {
itab *struct {
ityp *runtime.Type // static interface type
typ *runtime.Type // dynamic concrete type
// unused fields...
}
ptr unsafe.Pointer
}
func load(base uintptr, idx uintptr) uintptr {
addr := base + idx
func errUnimplementedOp(op encoder.OpType) error {
return fmt.Errorf("encoder (indent): opcode %s has not been implemented", op)
}
func load(base uintptr, idx uint32) uintptr {
addr := base + uintptr(idx)
return **(**uintptr)(unsafe.Pointer(&addr))
}
func store(base uintptr, idx uintptr, p uintptr) {
addr := base + idx
func store(base uintptr, idx uint32, p uintptr) {
addr := base + uintptr(idx)
**(**uintptr)(unsafe.Pointer(&addr)) = p
}
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
addr := base + idx
func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr {
addr := base + uintptr(idx)
p := **(**uintptr)(unsafe.Pointer(&addr))
for i := 0; i < ptrNum; i++ {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -72,8 +74,8 @@ func ptrToSlice(p uintptr) *runtime.SliceHeader { return *(**runtime.SliceHeader
func ptrToPtr(p uintptr) uintptr {
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
}
func ptrToNPtr(p uintptr, ptrNum int) uintptr {
for i := 0; i < ptrNum; i++ {
func ptrToNPtr(p uintptr, ptrNum uint8) uintptr {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -92,62 +94,84 @@ func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} {
}))
}
func appendBool(b []byte, v bool) []byte {
if v {
return append(b, "true"...)
func appendInt(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte {
format := ctx.Option.ColorScheme.Int
b = append(b, format.Header...)
b = encoder.AppendInt(ctx, b, v, code)
return append(b, format.Footer...)
}
func appendUint(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte {
format := ctx.Option.ColorScheme.Uint
b = append(b, format.Header...)
b = encoder.AppendUint(ctx, b, v, code)
return append(b, format.Footer...)
}
func appendFloat32(ctx *encoder.RuntimeContext, b []byte, v float32) []byte {
format := ctx.Option.ColorScheme.Float
b = append(b, format.Header...)
b = encoder.AppendFloat32(ctx, b, v)
return append(b, format.Footer...)
}
func appendFloat64(ctx *encoder.RuntimeContext, b []byte, v float64) []byte {
format := ctx.Option.ColorScheme.Float
b = append(b, format.Header...)
b = encoder.AppendFloat64(ctx, b, v)
return append(b, format.Footer...)
}
func appendString(ctx *encoder.RuntimeContext, b []byte, v string) []byte {
format := ctx.Option.ColorScheme.String
b = append(b, format.Header...)
b = encoder.AppendString(ctx, b, v)
return append(b, format.Footer...)
}
func appendByteSlice(ctx *encoder.RuntimeContext, b []byte, src []byte) []byte {
format := ctx.Option.ColorScheme.Binary
b = append(b, format.Header...)
b = encoder.AppendByteSlice(ctx, b, src)
return append(b, format.Footer...)
}
func appendNumber(ctx *encoder.RuntimeContext, b []byte, n json.Number) ([]byte, error) {
format := ctx.Option.ColorScheme.Int
b = append(b, format.Header...)
bb, err := encoder.AppendNumber(ctx, b, n)
if err != nil {
return nil, err
}
return append(b, "false"...)
return append(bb, format.Footer...), nil
}
func appendNull(b []byte) []byte {
return append(b, "null"...)
func appendBool(ctx *encoder.RuntimeContext, b []byte, v bool) []byte {
format := ctx.Option.ColorScheme.Bool
b = append(b, format.Header...)
if v {
b = append(b, "true"...)
} else {
b = append(b, "false"...)
}
return append(b, format.Footer...)
}
func appendComma(b []byte) []byte {
func appendNull(ctx *encoder.RuntimeContext, b []byte) []byte {
format := ctx.Option.ColorScheme.Null
b = append(b, format.Header...)
b = append(b, "null"...)
return append(b, format.Footer...)
}
func appendComma(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, ',', '\n')
}
func appendColon(b []byte) []byte {
func appendColon(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, ':', ' ')
}
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, opt encoder.Option, code *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
if err != nil {
return nil, err
}
totalLength := uintptr(codeSet.CodeLength)
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
curlen := uintptr(len(ctx.Ptrs))
offsetNum := ptrOffset / uintptrSize
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
}
oldPtrs := ctx.Ptrs
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
newPtrs[0] = uintptr(iface.ptr)
ctx.Ptrs = newPtrs
oldBaseIndent := ctx.BaseIndent
ctx.BaseIndent = code.Indent
bb, err := Run(ctx, b, ifaceCodeSet, opt)
if err != nil {
return nil, err
}
ctx.BaseIndent = oldBaseIndent
ctx.Ptrs = oldPtrs
return bb, nil
}
func appendMapKeyValue(ctx *encoder.RuntimeContext, code *encoder.Opcode, b, key, value []byte) []byte {
b = appendIndent(ctx, b, code.Indent+1)
b = append(b, key...)
@ -175,11 +199,11 @@ func appendArrayEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte)
return append(b, ']', ',', '\n')
}
func appendEmptyArray(b []byte) []byte {
func appendEmptyArray(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '[', ']', ',', '\n')
}
func appendEmptyObject(b []byte) []byte {
func appendEmptyObject(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{', '}', ',', '\n')
}
@ -191,21 +215,32 @@ func appendObjectEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte
}
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalJSONIndent(ctx, code, b, v, true)
return encoder.AppendMarshalJSONIndent(ctx, code, b, v)
}
func appendMarshalText(code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalTextIndent(code, b, v, true)
func appendMarshalText(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
format := ctx.Option.ColorScheme.String
b = append(b, format.Header...)
bb, err := encoder.AppendMarshalTextIndent(ctx, code, b, v)
if err != nil {
return nil, err
}
return append(bb, format.Footer...), nil
}
func appendStructHead(b []byte) []byte {
func appendStructHead(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{', '\n')
}
func appendStructKey(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
b = appendIndent(ctx, b, code.Indent)
b = append(b, code.EscapedKey...)
return append(b, ' ')
format := ctx.Option.ColorScheme.ObjectKey
b = append(b, format.Header...)
b = append(b, code.Key[:len(code.Key)-1]...)
b = append(b, format.Footer...)
return append(b, ':', ' ')
}
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
@ -221,15 +256,15 @@ func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode,
b = appendIndent(ctx, b, code.Indent-1)
b = append(b, '}')
}
return appendComma(b)
return appendComma(ctx, b)
}
func restoreIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, ctxptr uintptr) {
ctx.BaseIndent = int(load(ctxptr, code.Length))
ctx.BaseIndent = uint32(load(ctxptr, code.Length))
}
func storeIndent(ctxptr uintptr, code *encoder.Opcode, indent uintptr) {
store(ctxptr, code.End.Next.Length, indent)
store(ctxptr, code.Length, indent)
}
func appendArrayElemIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {

View file

@ -1,9 +0,0 @@
package vm_escaped
import (
// HACK: compile order
// `vm`, `vm_escaped`, `vm_indent`, `vm_escaped_indent` packages uses a lot of memory to compile,
// so forcibly make dependencies and avoid compiling in concurrent.
// dependency order: vm => vm_escaped => vm_indent => vm_escaped_indent
_ "github.com/goccy/go-json/internal/encoder/vm_indent"
)

View file

@ -1,6 +0,0 @@
package vm_escaped_indent
// HACK: compile order
// `vm`, `vm_escaped`, `vm_indent`, `vm_escaped_indent` packages uses a lot of memory to compile,
// so forcibly make dependencies and avoid compiling in concurrent.
// dependency order: vm => vm_escaped => vm_indent => vm_escaped_indent

View file

@ -6,7 +6,14 @@ import (
"github.com/goccy/go-json/internal/encoder"
)
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt encoder.Option) ([]byte, error) {
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
var code *encoder.Opcode
if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
code = codeSet.EscapeKeyCode
} else {
code = codeSet.NoescapeKeyCode
}
defer func() {
if err := recover(); err != nil {
fmt.Println("=============[DEBUG]===============")
@ -14,7 +21,7 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
fmt.Println(codeSet.Type)
fmt.Printf("\n")
fmt.Println("* [ALL OPCODE]")
fmt.Println(codeSet.Code.Dump())
fmt.Println(code.Dump())
fmt.Printf("\n")
fmt.Println("* [CONTEXT]")
fmt.Printf("%+v\n", ctx)
@ -23,5 +30,5 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet,
}
}()
return Run(ctx, b, codeSet, opt)
return Run(ctx, b, codeSet)
}

View file

@ -2,8 +2,8 @@ package vm_indent
import (
// HACK: compile order
// `vm`, `vm_escaped`, `vm_indent`, `vm_escaped_indent` packages uses a lot of memory to compile,
// `vm`, `vm_indent`, `vm_color`, `vm_color_indent` packages uses a lot of memory to compile,
// so forcibly make dependencies and avoid compiling in concurrent.
// dependency order: vm => vm_escaped => vm_indent => vm_escaped_indent
_ "github.com/goccy/go-json/internal/encoder/vm_escaped_indent"
// dependency order: vm => vm_indent => vm_color => vm_color_indent
_ "github.com/goccy/go-json/internal/encoder/vm_color"
)

View file

@ -35,24 +35,33 @@ type emptyInterface struct {
ptr unsafe.Pointer
}
type nonEmptyInterface struct {
itab *struct {
ityp *runtime.Type // static interface type
typ *runtime.Type // dynamic concrete type
// unused fields...
}
ptr unsafe.Pointer
}
func errUnimplementedOp(op encoder.OpType) error {
return fmt.Errorf("encoder (indent): opcode %s has not been implemented", op)
}
func load(base uintptr, idx uintptr) uintptr {
addr := base + idx
func load(base uintptr, idx uint32) uintptr {
addr := base + uintptr(idx)
return **(**uintptr)(unsafe.Pointer(&addr))
}
func store(base uintptr, idx uintptr, p uintptr) {
addr := base + idx
func store(base uintptr, idx uint32, p uintptr) {
addr := base + uintptr(idx)
**(**uintptr)(unsafe.Pointer(&addr)) = p
}
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
addr := base + idx
func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr {
addr := base + uintptr(idx)
p := **(**uintptr)(unsafe.Pointer(&addr))
for i := 0; i < ptrNum; i++ {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -72,8 +81,8 @@ func ptrToSlice(p uintptr) *runtime.SliceHeader { return *(**runtime.SliceHeader
func ptrToPtr(p uintptr) uintptr {
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
}
func ptrToNPtr(p uintptr, ptrNum int) uintptr {
for i := 0; i < ptrNum; i++ {
func ptrToNPtr(p uintptr, ptrNum uint8) uintptr {
for i := uint8(0); i < ptrNum; i++ {
if p == 0 {
return 0
}
@ -92,62 +101,25 @@ func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} {
}))
}
func appendBool(b []byte, v bool) []byte {
func appendBool(_ *encoder.RuntimeContext, b []byte, v bool) []byte {
if v {
return append(b, "true"...)
}
return append(b, "false"...)
}
func appendNull(b []byte) []byte {
func appendNull(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, "null"...)
}
func appendComma(b []byte) []byte {
func appendComma(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, ',', '\n')
}
func appendColon(b []byte) []byte {
func appendColon(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, ':', ' ')
}
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, opt encoder.Option, code *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
if err != nil {
return nil, err
}
totalLength := uintptr(codeSet.CodeLength)
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
curlen := uintptr(len(ctx.Ptrs))
offsetNum := ptrOffset / uintptrSize
newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen {
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
}
oldPtrs := ctx.Ptrs
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
newPtrs[0] = uintptr(iface.ptr)
ctx.Ptrs = newPtrs
oldBaseIndent := ctx.BaseIndent
ctx.BaseIndent = code.Indent
bb, err := Run(ctx, b, ifaceCodeSet, opt)
if err != nil {
return nil, err
}
ctx.BaseIndent = oldBaseIndent
ctx.Ptrs = oldPtrs
return bb, nil
}
func appendMapKeyValue(ctx *encoder.RuntimeContext, code *encoder.Opcode, b, key, value []byte) []byte {
b = appendIndent(ctx, b, code.Indent+1)
b = append(b, key...)
@ -175,11 +147,11 @@ func appendArrayEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte)
return append(b, ']', ',', '\n')
}
func appendEmptyArray(b []byte) []byte {
func appendEmptyArray(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '[', ']', ',', '\n')
}
func appendEmptyObject(b []byte) []byte {
func appendEmptyObject(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{', '}', ',', '\n')
}
@ -191,14 +163,14 @@ func appendObjectEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte
}
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalJSONIndent(ctx, code, b, v, false)
return encoder.AppendMarshalJSONIndent(ctx, code, b, v)
}
func appendMarshalText(code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalTextIndent(code, b, v, false)
func appendMarshalText(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
return encoder.AppendMarshalTextIndent(ctx, code, b, v)
}
func appendStructHead(b []byte) []byte {
func appendStructHead(_ *encoder.RuntimeContext, b []byte) []byte {
return append(b, '{', '\n')
}
@ -221,15 +193,15 @@ func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode,
b = appendIndent(ctx, b, code.Indent-1)
b = append(b, '}')
}
return appendComma(b)
return appendComma(ctx, b)
}
func restoreIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, ctxptr uintptr) {
ctx.BaseIndent = int(load(ctxptr, code.Length))
ctx.BaseIndent = uint32(load(ctxptr, code.Length))
}
func storeIndent(ctxptr uintptr, code *encoder.Opcode, indent uintptr) {
store(ctxptr, code.End.Next.Length, indent)
store(ctxptr, code.Length, indent)
}
func appendArrayElemIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {

File diff suppressed because it is too large Load diff