forked from mirror/go-json
Support colored JSON
This commit is contained in:
parent
c294f01ac5
commit
4c19a845d9
11
color.go
11
color.go
|
@ -60,11 +60,12 @@ var (
|
|||
Bool: createColorFormat(fgHiYellowColor),
|
||||
String: createColorFormat(fgHiGreenColor),
|
||||
Binary: createColorFormat(fgHiRedColor),
|
||||
ObjectStart: createColorFormat(fgHiCyanColor),
|
||||
ObjectEnd: createColorFormat(fgHiCyanColor),
|
||||
ArrayStart: createColorFormat(fgHiCyanColor),
|
||||
ArrayEnd: createColorFormat(fgHiCyanColor),
|
||||
ObjectStart: createColorFormat(fgWhiteColor),
|
||||
ObjectKey: createColorFormat(fgHiCyanColor),
|
||||
ObjectEnd: createColorFormat(fgWhiteColor),
|
||||
ArrayStart: createColorFormat(fgWhiteColor),
|
||||
ArrayEnd: createColorFormat(fgWhiteColor),
|
||||
Colon: createColorFormat(fgWhiteColor),
|
||||
Comma: createColorFormat(fgWhiteColor),
|
||||
Null: createColorFormat(fgBlueColor),
|
||||
}
|
||||
)
|
||||
|
|
14
encode.go
14
encode.go
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
"github.com/goccy/go-json/internal/encoder"
|
||||
"github.com/goccy/go-json/internal/encoder/vm"
|
||||
"github.com/goccy/go-json/internal/encoder/vm_color"
|
||||
"github.com/goccy/go-json/internal/encoder/vm_color_indent"
|
||||
"github.com/goccy/go-json/internal/encoder/vm_indent"
|
||||
)
|
||||
|
||||
|
@ -254,8 +256,14 @@ func encodeIndent(ctx *encoder.RuntimeContext, v interface{}, prefix, indent str
|
|||
|
||||
func encodeRunCode(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
|
||||
if ctx.Option.Debug {
|
||||
if ctx.Option.Colorize {
|
||||
return vm_color.DebugRun(ctx, b, codeSet)
|
||||
}
|
||||
return vm.DebugRun(ctx, b, codeSet)
|
||||
}
|
||||
if ctx.Option.Colorize {
|
||||
return vm_color.Run(ctx, b, codeSet)
|
||||
}
|
||||
return vm.Run(ctx, b, codeSet)
|
||||
}
|
||||
|
||||
|
@ -263,8 +271,14 @@ func encodeRunIndentCode(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder
|
|||
ctx.Prefix = []byte(prefix)
|
||||
ctx.IndentStr = []byte(indent)
|
||||
if ctx.Option.Debug {
|
||||
if ctx.Option.Colorize {
|
||||
return vm_color_indent.DebugRun(ctx, b, codeSet)
|
||||
}
|
||||
return vm_indent.DebugRun(ctx, b, codeSet)
|
||||
}
|
||||
if ctx.Option.Colorize {
|
||||
return vm_color_indent.Run(ctx, b, codeSet)
|
||||
}
|
||||
return vm_indent.Run(ctx, b, codeSet)
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ func generateVM() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, pkg := range []string{"vm", "vm_indent"} {
|
||||
for _, pkg := range []string{"vm", "vm_indent", "vm_color", "vm_color_indent"} {
|
||||
f.Name.Name = pkg
|
||||
var buf bytes.Buffer
|
||||
printer.Fprint(&buf, fset, f)
|
||||
|
|
|
@ -39,7 +39,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, code.Idx, p)
|
||||
fallthrough
|
||||
case encoder.OpInt:
|
||||
b = appendInt(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpUintPtr:
|
||||
|
@ -53,18 +53,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, code.Idx, p)
|
||||
fallthrough
|
||||
case encoder.OpUint:
|
||||
b = appendUint(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpIntString:
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpUintString:
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -602,7 +602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendStructHead(ctx, b)
|
||||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadOmitEmptyInt:
|
||||
|
@ -638,7 +638,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
code = code.NextField
|
||||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -709,7 +709,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -746,7 +746,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -780,7 +780,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -817,7 +817,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -853,7 +853,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -886,7 +886,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendStructHead(ctx, b)
|
||||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadOmitEmptyUint:
|
||||
|
@ -922,7 +922,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
code = code.NextField
|
||||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
}
|
||||
|
@ -955,7 +955,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -993,7 +993,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -1030,7 +1030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -1064,7 +1064,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -1101,7 +1101,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -1137,7 +1137,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3413,7 +3413,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructFieldInt:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructFieldOmitEmptyInt:
|
||||
|
@ -3422,7 +3422,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3430,7 +3430,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3441,7 +3441,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3453,7 +3453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3462,7 +3462,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3474,7 +3474,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -3485,7 +3485,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3493,7 +3493,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructFieldUint:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructFieldOmitEmptyUint:
|
||||
|
@ -3502,7 +3502,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3510,7 +3510,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3521,7 +3521,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3533,7 +3533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3542,7 +3542,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3554,7 +3554,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -3565,7 +3565,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -4297,7 +4297,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructEndInt:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructEndOmitEmptyInt:
|
||||
|
@ -4306,7 +4306,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4316,7 +4316,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4327,7 +4327,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4341,7 +4341,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4350,7 +4350,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4364,7 +4364,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
|
@ -4375,7 +4375,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4385,7 +4385,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructEndUint:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructEndOmitEmptyUint:
|
||||
|
@ -4394,7 +4394,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4404,7 +4404,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4415,7 +4415,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4429,7 +4429,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4438,7 +4438,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4452,7 +4452,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
|
@ -4463,7 +4463,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
|
|
@ -53,7 +53,7 @@ func numMask(numBitSize uint8) uint64 {
|
|||
return 1<<numBitSize - 1
|
||||
}
|
||||
|
||||
func AppendInt(out []byte, u64 uint64, code *Opcode) []byte {
|
||||
func AppendInt(_ *RuntimeContext, out []byte, u64 uint64, code *Opcode) []byte {
|
||||
mask := numMask(code.NumBitSize)
|
||||
n := u64 & mask
|
||||
negative := (u64>>(code.NumBitSize-1))&1 == 1
|
||||
|
@ -96,7 +96,7 @@ func AppendInt(out []byte, u64 uint64, code *Opcode) []byte {
|
|||
return append(out, b[i:]...)
|
||||
}
|
||||
|
||||
func AppendUint(out []byte, u64 uint64, code *Opcode) []byte {
|
||||
func AppendUint(_ *RuntimeContext, out []byte, u64 uint64, code *Opcode) []byte {
|
||||
mask := numMask(code.NumBitSize)
|
||||
n := u64 & mask
|
||||
if n < 10 {
|
||||
|
|
|
@ -22,11 +22,13 @@ type EncodeFormatScheme struct {
|
|||
String EncodeFormat
|
||||
Binary EncodeFormat
|
||||
ObjectStart EncodeFormat
|
||||
ObjectKey EncodeFormat
|
||||
ObjectEnd EncodeFormat
|
||||
ArrayStart EncodeFormat
|
||||
ArrayEnd EncodeFormat
|
||||
Colon EncodeFormat
|
||||
Comma EncodeFormat
|
||||
Null EncodeFormat
|
||||
}
|
||||
|
||||
type (
|
||||
|
|
|
@ -2,8 +2,8 @@ package vm
|
|||
|
||||
import (
|
||||
// HACK: compile order
|
||||
// `vm`, `vm_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_indent
|
||||
// dependency order: vm => vm_indent => vm_color => vm_color_indent
|
||||
_ "github.com/goccy/go-json/internal/encoder/vm_indent"
|
||||
)
|
||||
|
|
|
@ -39,7 +39,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, code.Idx, p)
|
||||
fallthrough
|
||||
case encoder.OpInt:
|
||||
b = appendInt(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpUintPtr:
|
||||
|
@ -53,18 +53,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, code.Idx, p)
|
||||
fallthrough
|
||||
case encoder.OpUint:
|
||||
b = appendUint(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpIntString:
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpUintString:
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -602,7 +602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendStructHead(ctx, b)
|
||||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadOmitEmptyInt:
|
||||
|
@ -638,7 +638,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
code = code.NextField
|
||||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -709,7 +709,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -746,7 +746,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -780,7 +780,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -817,7 +817,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -853,7 +853,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -886,7 +886,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendStructHead(ctx, b)
|
||||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadOmitEmptyUint:
|
||||
|
@ -922,7 +922,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
code = code.NextField
|
||||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
}
|
||||
|
@ -955,7 +955,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -993,7 +993,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -1030,7 +1030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -1064,7 +1064,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -1101,7 +1101,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -1137,7 +1137,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3413,7 +3413,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructFieldInt:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructFieldOmitEmptyInt:
|
||||
|
@ -3422,7 +3422,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3430,7 +3430,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3441,7 +3441,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3453,7 +3453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3462,7 +3462,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3474,7 +3474,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -3485,7 +3485,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3493,7 +3493,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructFieldUint:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructFieldOmitEmptyUint:
|
||||
|
@ -3502,7 +3502,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3510,7 +3510,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3521,7 +3521,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3533,7 +3533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3542,7 +3542,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3554,7 +3554,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -3565,7 +3565,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -4297,7 +4297,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructEndInt:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructEndOmitEmptyInt:
|
||||
|
@ -4306,7 +4306,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4316,7 +4316,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4327,7 +4327,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4341,7 +4341,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4350,7 +4350,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4364,7 +4364,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
|
@ -4375,7 +4375,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4385,7 +4385,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructEndUint:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructEndOmitEmptyUint:
|
||||
|
@ -4394,7 +4394,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4404,7 +4404,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4415,7 +4415,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4429,7 +4429,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4438,7 +4438,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4452,7 +4452,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
|
@ -4463,7 +4463,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package vm_color
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goccy/go-json/internal/encoder"
|
||||
)
|
||||
|
||||
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
|
||||
var code *encoder.Opcode
|
||||
if ctx.Option.HTMLEscape {
|
||||
code = codeSet.EscapeKeyCode
|
||||
} else {
|
||||
code = codeSet.NoescapeKeyCode
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("=============[DEBUG]===============")
|
||||
fmt.Println("* [TYPE]")
|
||||
fmt.Println(codeSet.Type)
|
||||
fmt.Printf("\n")
|
||||
fmt.Println("* [ALL OPCODE]")
|
||||
fmt.Println(code.Dump())
|
||||
fmt.Printf("\n")
|
||||
fmt.Println("* [CONTEXT]")
|
||||
fmt.Printf("%+v\n", ctx)
|
||||
fmt.Println("===================================")
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return Run(ctx, b, codeSet)
|
||||
}
|
|
@ -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"
|
||||
)
|
|
@ -0,0 +1,360 @@
|
|||
package vm_color
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goccy/go-json/internal/encoder"
|
||||
"github.com/goccy/go-json/internal/runtime"
|
||||
)
|
||||
|
||||
const uintptrSize = 4 << (^uintptr(0) >> 63)
|
||||
|
||||
var (
|
||||
errUnsupportedValue = encoder.ErrUnsupportedValue
|
||||
errUnsupportedFloat = encoder.ErrUnsupportedFloat
|
||||
mapiterinit = encoder.MapIterInit
|
||||
mapiterkey = encoder.MapIterKey
|
||||
mapitervalue = encoder.MapIterValue
|
||||
mapiternext = encoder.MapIterNext
|
||||
maplen = encoder.MapLen
|
||||
)
|
||||
|
||||
type emptyInterface struct {
|
||||
typ *runtime.Type
|
||||
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 uint32) uintptr {
|
||||
addr := base + uintptr(idx)
|
||||
return **(**uintptr)(unsafe.Pointer(&addr))
|
||||
}
|
||||
|
||||
func store(base uintptr, idx uint32, p uintptr) {
|
||||
addr := base + uintptr(idx)
|
||||
**(**uintptr)(unsafe.Pointer(&addr)) = p
|
||||
}
|
||||
|
||||
func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr {
|
||||
addr := base + uintptr(idx)
|
||||
p := **(**uintptr)(unsafe.Pointer(&addr))
|
||||
for i := uint8(0); i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
|
||||
func ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) }
|
||||
func ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) }
|
||||
func ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) }
|
||||
func ptrToBytes(p uintptr) []byte { return **(**[]byte)(unsafe.Pointer(&p)) }
|
||||
func ptrToNumber(p uintptr) json.Number { return **(**json.Number)(unsafe.Pointer(&p)) }
|
||||
func ptrToString(p uintptr) string { return **(**string)(unsafe.Pointer(&p)) }
|
||||
func ptrToSlice(p uintptr) *runtime.SliceHeader { return *(**runtime.SliceHeader)(unsafe.Pointer(&p)) }
|
||||
func ptrToPtr(p uintptr) uintptr {
|
||||
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
|
||||
}
|
||||
func ptrToNPtr(p uintptr, ptrNum uint8) uintptr {
|
||||
for i := uint8(0); i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUnsafePtr(p uintptr) unsafe.Pointer {
|
||||
return *(*unsafe.Pointer)(unsafe.Pointer(&p))
|
||||
}
|
||||
func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} {
|
||||
return *(*interface{})(unsafe.Pointer(&emptyInterface{
|
||||
typ: code.Type,
|
||||
ptr: *(*unsafe.Pointer)(unsafe.Pointer(&p)),
|
||||
}))
|
||||
}
|
||||
|
||||
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(bb, format.Footer...), nil
|
||||
}
|
||||
|
||||
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 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(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.Comma
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, ',')
|
||||
return append(b, format.Footer...)
|
||||
}
|
||||
|
||||
func appendColon(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.Colon
|
||||
last := len(b) - 1
|
||||
if len(format.Header) > 0 {
|
||||
b[last] = format.Header[0]
|
||||
b = append(b, format.Header[1:]...)
|
||||
b = append(b, ':')
|
||||
return append(b, format.Footer...)
|
||||
}
|
||||
b[last] = ':'
|
||||
return b
|
||||
}
|
||||
|
||||
func appendMapKeyValue(ctx *encoder.RuntimeContext, _ *encoder.Opcode, b, key, value []byte) []byte {
|
||||
keyFormat := ctx.Option.ColorScheme.String
|
||||
b = append(b, keyFormat.Header...)
|
||||
b = append(b, key...)
|
||||
b = append(b, keyFormat.Footer...)
|
||||
|
||||
b = appendColon(ctx, b)
|
||||
|
||||
return append(b, value...)
|
||||
}
|
||||
|
||||
func appendMapEnd(ctx *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.ObjectEnd
|
||||
last := len(b) - 1
|
||||
if len(format.Header) > 0 {
|
||||
b[last] = format.Header[0]
|
||||
b = append(b, format.Header[1:]...)
|
||||
b = append(b, '}')
|
||||
b = append(b, format.Footer...)
|
||||
|
||||
return append(b, ',')
|
||||
}
|
||||
b[last] = '}'
|
||||
b = append(b, ',')
|
||||
return b
|
||||
}
|
||||
|
||||
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, _ *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)
|
||||
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)
|
||||
}
|
||||
|
||||
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(ctx *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.ArrayStart
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, '[')
|
||||
return append(b, format.Footer...)
|
||||
}
|
||||
|
||||
func appendArrayEnd(ctx *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
|
||||
last := len(b) - 1
|
||||
if b[last] == ',' {
|
||||
b[last] = ']'
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
format := ctx.Option.ColorScheme.ArrayEnd
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, ']')
|
||||
b = append(b, format.Footer...)
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
|
||||
func appendEmptyArray(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
b = appendArrayHead(ctx, nil, b)
|
||||
|
||||
format := ctx.Option.ColorScheme.ArrayEnd
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, ']')
|
||||
b = append(b, format.Footer...)
|
||||
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
|
||||
func appendEmptyObject(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
b = appendStructHead(ctx, b)
|
||||
|
||||
format := ctx.Option.ColorScheme.ObjectEnd
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, '}')
|
||||
b = append(b, format.Footer...)
|
||||
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
|
||||
func appendObjectEnd(ctx *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.ObjectEnd
|
||||
|
||||
last := len(b) - 1
|
||||
if len(format.Header) > 0 {
|
||||
b[last] = format.Header[0]
|
||||
b = append(b, format.Header[1:]...)
|
||||
b = append(b, '}')
|
||||
b = append(b, format.Footer...)
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
b[last] = '}'
|
||||
return append(b, ',')
|
||||
}
|
||||
|
||||
func appendStructHead(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.ObjectStart
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, '{')
|
||||
return append(b, format.Footer...)
|
||||
}
|
||||
|
||||
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...)
|
||||
|
||||
colonFormat := ctx.Option.ColorScheme.Colon
|
||||
b = append(b, colonFormat.Header...)
|
||||
b = append(b, ':')
|
||||
return append(b, colonFormat.Footer...)
|
||||
}
|
||||
|
||||
func appendStructEnd(ctx *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.ObjectEnd
|
||||
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, '}')
|
||||
b = append(b, format.Footer...)
|
||||
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
|
||||
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
footerLen := len(ctx.Option.ColorScheme.Comma.Footer)
|
||||
lastCharIdx := footerLen + 1
|
||||
|
||||
if len(b) < lastCharIdx {
|
||||
last := len(b) - 1
|
||||
if b[last] == ',' {
|
||||
b[last] = '}'
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
return appendStructEnd(ctx, code, b)
|
||||
}
|
||||
|
||||
last := len(b) - lastCharIdx
|
||||
if b[last] == ',' {
|
||||
b[last] = '}'
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
return appendStructEnd(ctx, code, b)
|
||||
}
|
||||
|
||||
func restoreIndent(_ *encoder.RuntimeContext, _ *encoder.Opcode, _ uintptr) {}
|
||||
func storeIndent(_ uintptr, _ *encoder.Opcode, _ uintptr) {}
|
||||
func appendMapKeyIndent(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte { return b }
|
||||
func appendArrayElemIndent(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte { return b }
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,34 @@
|
|||
package vm_color_indent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goccy/go-json/internal/encoder"
|
||||
)
|
||||
|
||||
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
|
||||
var code *encoder.Opcode
|
||||
if ctx.Option.HTMLEscape {
|
||||
code = codeSet.EscapeKeyCode
|
||||
} else {
|
||||
code = codeSet.NoescapeKeyCode
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("=============[DEBUG]===============")
|
||||
fmt.Println("* [TYPE]")
|
||||
fmt.Println(codeSet.Type)
|
||||
fmt.Printf("\n")
|
||||
fmt.Println("* [ALL OPCODE]")
|
||||
fmt.Println(code.Dump())
|
||||
fmt.Printf("\n")
|
||||
fmt.Println("* [CONTEXT]")
|
||||
fmt.Printf("%+v\n", ctx)
|
||||
fmt.Println("===================================")
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return Run(ctx, b, codeSet)
|
||||
}
|
|
@ -0,0 +1,299 @@
|
|||
package vm_color_indent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goccy/go-json/internal/encoder"
|
||||
"github.com/goccy/go-json/internal/runtime"
|
||||
)
|
||||
|
||||
const uintptrSize = 4 << (^uintptr(0) >> 63)
|
||||
|
||||
var (
|
||||
appendIndent = encoder.AppendIndent
|
||||
appendStructEnd = encoder.AppendStructEndIndent
|
||||
errUnsupportedValue = encoder.ErrUnsupportedValue
|
||||
errUnsupportedFloat = encoder.ErrUnsupportedFloat
|
||||
mapiterinit = encoder.MapIterInit
|
||||
mapiterkey = encoder.MapIterKey
|
||||
mapitervalue = encoder.MapIterValue
|
||||
mapiternext = encoder.MapIterNext
|
||||
maplen = encoder.MapLen
|
||||
)
|
||||
|
||||
type emptyInterface struct {
|
||||
typ *runtime.Type
|
||||
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 uint32) uintptr {
|
||||
addr := base + uintptr(idx)
|
||||
return **(**uintptr)(unsafe.Pointer(&addr))
|
||||
}
|
||||
|
||||
func store(base uintptr, idx uint32, p uintptr) {
|
||||
addr := base + uintptr(idx)
|
||||
**(**uintptr)(unsafe.Pointer(&addr)) = p
|
||||
}
|
||||
|
||||
func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr {
|
||||
addr := base + uintptr(idx)
|
||||
p := **(**uintptr)(unsafe.Pointer(&addr))
|
||||
for i := uint8(0); i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
|
||||
func ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) }
|
||||
func ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) }
|
||||
func ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) }
|
||||
func ptrToBytes(p uintptr) []byte { return **(**[]byte)(unsafe.Pointer(&p)) }
|
||||
func ptrToNumber(p uintptr) json.Number { return **(**json.Number)(unsafe.Pointer(&p)) }
|
||||
func ptrToString(p uintptr) string { return **(**string)(unsafe.Pointer(&p)) }
|
||||
func ptrToSlice(p uintptr) *runtime.SliceHeader { return *(**runtime.SliceHeader)(unsafe.Pointer(&p)) }
|
||||
func ptrToPtr(p uintptr) uintptr {
|
||||
return uintptr(**(**unsafe.Pointer)(unsafe.Pointer(&p)))
|
||||
}
|
||||
func ptrToNPtr(p uintptr, ptrNum uint8) uintptr {
|
||||
for i := uint8(0); i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUnsafePtr(p uintptr) unsafe.Pointer {
|
||||
return *(*unsafe.Pointer)(unsafe.Pointer(&p))
|
||||
}
|
||||
func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} {
|
||||
return *(*interface{})(unsafe.Pointer(&emptyInterface{
|
||||
typ: code.Type,
|
||||
ptr: *(*unsafe.Pointer)(unsafe.Pointer(&p)),
|
||||
}))
|
||||
}
|
||||
|
||||
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(bb, format.Footer...), nil
|
||||
}
|
||||
|
||||
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 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(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.Comma
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, ',', '\n')
|
||||
return append(b, format.Footer...)
|
||||
}
|
||||
|
||||
func appendColon(ctx *encoder.RuntimeContext, b []byte) []byte {
|
||||
format := ctx.Option.ColorScheme.Colon
|
||||
b = append(b, format.Header...)
|
||||
b = append(b, ':', ' ')
|
||||
return append(b, format.Footer...)
|
||||
}
|
||||
|
||||
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, 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)
|
||||
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...)
|
||||
b[len(b)-2] = ':'
|
||||
b[len(b)-1] = ' '
|
||||
return append(b, value...)
|
||||
}
|
||||
|
||||
func appendMapEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
b = b[:len(b)-2]
|
||||
b = append(b, '\n')
|
||||
b = appendIndent(ctx, b, code.Indent)
|
||||
return append(b, '}', ',', '\n')
|
||||
}
|
||||
|
||||
func appendArrayHead(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
b = append(b, '[', '\n')
|
||||
return appendIndent(ctx, b, code.Indent+1)
|
||||
}
|
||||
|
||||
func appendArrayEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
b = b[:len(b)-2]
|
||||
b = append(b, '\n')
|
||||
b = appendIndent(ctx, b, code.Indent)
|
||||
return append(b, ']', ',', '\n')
|
||||
}
|
||||
|
||||
func appendEmptyArray(_ *encoder.RuntimeContext, b []byte) []byte {
|
||||
return append(b, '[', ']', ',', '\n')
|
||||
}
|
||||
|
||||
func appendEmptyObject(_ *encoder.RuntimeContext, b []byte) []byte {
|
||||
return append(b, '{', '}', ',', '\n')
|
||||
}
|
||||
|
||||
func appendObjectEnd(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
last := len(b) - 1
|
||||
b[last] = '\n'
|
||||
b = appendIndent(ctx, b, code.Indent-1)
|
||||
return append(b, '}', ',', '\n')
|
||||
}
|
||||
|
||||
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
|
||||
return encoder.AppendMarshalJSONIndent(ctx, code, b, v)
|
||||
}
|
||||
|
||||
func appendMarshalText(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
|
||||
return encoder.AppendMarshalTextIndent(ctx, code, b, v)
|
||||
}
|
||||
|
||||
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.Key...)
|
||||
return append(b, ' ')
|
||||
}
|
||||
|
||||
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
last := len(b) - 1
|
||||
if b[last-1] == '{' {
|
||||
b[last] = '}'
|
||||
} else {
|
||||
if b[last] == '\n' {
|
||||
// to remove ',' and '\n' characters
|
||||
b = b[:len(b)-2]
|
||||
}
|
||||
b = append(b, '\n')
|
||||
b = appendIndent(ctx, b, code.Indent-1)
|
||||
b = append(b, '}')
|
||||
}
|
||||
return appendComma(ctx, b)
|
||||
}
|
||||
|
||||
func restoreIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, ctxptr uintptr) {
|
||||
ctx.BaseIndent = uint32(load(ctxptr, code.Length))
|
||||
}
|
||||
|
||||
func storeIndent(ctxptr uintptr, code *encoder.Opcode, indent uintptr) {
|
||||
store(ctxptr, code.End.Next.Length, indent)
|
||||
}
|
||||
|
||||
func appendArrayElemIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
return appendIndent(ctx, b, code.Indent+1)
|
||||
}
|
||||
|
||||
func appendMapKeyIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
return appendIndent(ctx, b, code.Indent)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,9 @@
|
|||
package vm_indent
|
||||
|
||||
import (
|
||||
// HACK: compile order
|
||||
// `vm`, `vm_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_indent
|
||||
// dependency order: vm => vm_indent => vm_color => vm_color_indent
|
||||
_ "github.com/goccy/go-json/internal/encoder/vm_color"
|
||||
)
|
||||
|
|
|
@ -39,7 +39,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, code.Idx, p)
|
||||
fallthrough
|
||||
case encoder.OpInt:
|
||||
b = appendInt(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpUintPtr:
|
||||
|
@ -53,18 +53,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, code.Idx, p)
|
||||
fallthrough
|
||||
case encoder.OpUint:
|
||||
b = appendUint(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpIntString:
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpUintString:
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -602,7 +602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendStructHead(ctx, b)
|
||||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadOmitEmptyInt:
|
||||
|
@ -638,7 +638,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
code = code.NextField
|
||||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -709,7 +709,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -746,7 +746,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -780,7 +780,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -817,7 +817,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -853,7 +853,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -886,7 +886,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendStructHead(ctx, b)
|
||||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadOmitEmptyUint:
|
||||
|
@ -922,7 +922,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
code = code.NextField
|
||||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
}
|
||||
|
@ -955,7 +955,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -993,7 +993,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
} else {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -1030,7 +1030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -1064,7 +1064,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
}
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -1101,7 +1101,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -1137,7 +1137,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3413,7 +3413,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructFieldInt:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructFieldOmitEmptyInt:
|
||||
|
@ -3422,7 +3422,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3430,7 +3430,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3441,7 +3441,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3453,7 +3453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3462,7 +3462,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3474,7 +3474,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -3485,7 +3485,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3493,7 +3493,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructFieldUint:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructFieldOmitEmptyUint:
|
||||
|
@ -3502,7 +3502,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3510,7 +3510,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3521,7 +3521,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -3533,7 +3533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
code = code.Next
|
||||
|
@ -3542,7 +3542,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
code = code.Next
|
||||
|
@ -3554,7 +3554,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(ctx, b)
|
||||
|
@ -3565,7 +3565,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendComma(ctx, b)
|
||||
}
|
||||
|
@ -4297,7 +4297,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructEndInt:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructEndOmitEmptyInt:
|
||||
|
@ -4306,7 +4306,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4316,7 +4316,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4327,7 +4327,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, u64, code)
|
||||
b = appendInt(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4341,7 +4341,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4350,7 +4350,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4364,7 +4364,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
|
@ -4375,7 +4375,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, ptrToUint64(p), code)
|
||||
b = appendInt(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4385,7 +4385,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
case encoder.OpStructEndUint:
|
||||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
case encoder.OpStructEndOmitEmptyUint:
|
||||
|
@ -4394,7 +4394,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
v := u64 & ((1 << code.NumBitSize) - 1)
|
||||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4404,7 +4404,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p := load(ctxptr, code.Idx)
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4415,7 +4415,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if v != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, u64, code)
|
||||
b = appendUint(ctx, b, u64, code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
@ -4429,7 +4429,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p == 0 {
|
||||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
code = code.Next
|
||||
|
@ -4438,7 +4438,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum)
|
||||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
b = appendStructEndSkipLast(ctx, code, b)
|
||||
|
@ -4452,7 +4452,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
b = appendNull(ctx, b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
|
@ -4463,7 +4463,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
if p != 0 {
|
||||
b = appendStructKey(ctx, code, b)
|
||||
b = append(b, '"')
|
||||
b = appendUint(b, ptrToUint64(p), code)
|
||||
b = appendUint(ctx, b, ptrToUint64(p), code)
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(ctx, code, b)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue