From 87882a9111a1fcd2a5f826c1a0d4a7c2821cff47 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 17 Jan 2021 15:49:34 +0900 Subject: [PATCH] Sort operation --- encode_vm.go | 1747 ++++++++++++++++++++--------------- encode_vm_escaped.go | 1312 +++++++++++++------------- encode_vm_escaped_indent.go | 1428 ++++++++++++++-------------- encode_vm_indent.go | 1429 ++++++++++++++-------------- 4 files changed, 3091 insertions(+), 2825 deletions(-) diff --git a/encode_vm.go b/encode_vm.go index e5b7deb..f709239 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -1561,6 +1561,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt16Only, opStructFieldHeadInt16Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -1568,6 +1613,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendInt(b, int64(e.ptrToInt16(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Only, opStructFieldHeadOmitEmptyInt16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := int64(e.ptrToInt16(p)) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt16Only, opStructFieldHeadStringTagInt16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1590,6 +1654,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt16Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + p = e.ptrToPtr(p) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt16Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } else { + b = append(b, '{') + b = append(b, code.key...) + p = e.ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1611,6 +1718,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldHeadOmitEmptyInt16PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt16NPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{') + b = append(b, code.key...) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = e.ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1624,6 +1794,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Only, opStructFieldAnonymousHeadInt16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1634,6 +1843,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Only, opStructFieldAnonymousHeadOmitEmptyInt16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt16Only, opStructFieldAnonymousHeadStringTagInt16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1652,6 +1888,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = e.ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.key...) + p = e.ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1670,6 +1944,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3293,51 +3605,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt16(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt16(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4076,45 +4343,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4734,6 +4962,22 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte ptr := load(ctxptr, code.headIdx) + code.offset code = code.next store(ctxptr, code.idx, ptr) + case opStructFieldOmitEmpty: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + code = code.next + store(ctxptr, code.idx, p) + } + case opStructFieldStringTag: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + b = append(b, code.key...) + code = code.next + store(ctxptr, code.idx, p) case opStructFieldInt: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -4819,6 +5063,29 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldInt16Ptr: b = append(b, code.key...) ptr := load(ctxptr, code.headIdx) @@ -4830,10 +5097,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldInt16: + case opStructFieldInt32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldInt32Ptr: @@ -4847,10 +5131,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldInt32: + case opStructFieldInt64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldInt64Ptr: @@ -4864,10 +5165,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldInt64: + case opStructFieldUint: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUintPtr: @@ -4881,10 +5199,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldUint: + case opStructFieldUint8: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint8Ptr: @@ -4898,10 +5233,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldUint8: + case opStructFieldUint16: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint16Ptr: @@ -4915,10 +5267,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldUint16: + case opStructFieldUint32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint32Ptr: @@ -4932,10 +5301,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldUint32: + case opStructFieldUint64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint64Ptr: @@ -4949,10 +5335,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldUint64: + case opStructFieldFloat32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = encodeFloat32(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldFloat32Ptr: @@ -4966,10 +5369,38 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldFloat32: + case opStructFieldFloat64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat64(b, v) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldFloat64Ptr: @@ -4989,14 +5420,26 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeFloat64(b, v) b = encodeComma(b) code = code.next - case opStructFieldFloat64: + case opStructFieldString: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) + b = encodeNoEscapedString(b, e.ptrToString(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = append(b, code.key...) + b = encodeNoEscapedString(b, v) + b = encodeComma(b) } - b = encodeFloat64(b, v) + code = code.next + case opStructFieldStringTagString: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + s := e.ptrToString(ptr + code.offset) + b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) b = encodeComma(b) code = code.next case opStructFieldStringPtr: @@ -5010,10 +5453,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldString: + case opStructFieldBool: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = encodeNoEscapedString(b, e.ptrToString(ptr+code.offset)) + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = append(b, code.key...) + b = encodeBool(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldBoolPtr: @@ -5027,18 +5487,28 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = encodeComma(b) - code = code.next case opStructFieldBytes: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = encodeComma(b) code = code.next + case opStructFieldOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = append(b, code.key...) + b = encodeByteSlice(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + b = append(b, code.key...) + b = encodeByteSlice(b, v) + b = encodeComma(b) + code = code.next case opStructFieldMarshalJSON: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -5055,178 +5525,22 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = append(b, buf.Bytes()...) b = encodeComma(b) code = code.next - case opStructFieldMarshalText: + case opStructFieldStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) p := ptr + code.offset v := e.ptrToInterface(code, p) - bytes, err := v.(encoding.TextMarshaler).MarshalText() + bb, err := v.(Marshaler).MarshalJSON() if err != nil { return nil, errMarshaler(code, err) } - b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + var buf bytes.Buffer + if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil { + return nil, err + } + b = append(b, code.key...) + b = encodeNoEscapedString(b, buf.String()) b = encodeComma(b) code = code.next - case opStructFieldArray: - b = append(b, code.key...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldSlice: - b = append(b, code.key...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldMap: - b = append(b, code.key...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldMapLoad: - b = append(b, code.key...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldStruct: - b = append(b, code.key...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldOmitEmpty: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - code = code.next - store(ctxptr, code.idx, p) - } - case opStructFieldOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = encodeFloat32(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = encodeFloat64(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = append(b, code.key...) - b = encodeNoEscapedString(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = append(b, code.key...) - b = encodeBool(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = append(b, code.key...) - b = encodeByteSlice(b, v) - b = encodeComma(b) - } - code = code.next case opStructFieldOmitEmptyMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -5245,190 +5559,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) } code = code.next - case opStructFieldOmitEmptyMarshalText: + case opStructFieldMarshalText: ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) p := ptr + code.offset v := e.ptrToInterface(code, p) - if v != nil { - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = append(b, code.key...) - b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyArray: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - array := e.ptrToSlice(p) - if p == 0 || uintptr(array.data) == 0 { - code = code.nextField - } else { - code = code.next - } - case opStructFieldOmitEmptySlice: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - slice := e.ptrToSlice(p) - if p == 0 || uintptr(slice.data) == 0 { - code = code.nextField - } else { - code = code.next - } - case opStructFieldOmitEmptyMap: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - code = code.next - } - } - case opStructFieldOmitEmptyMapLoad: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - code = code.next - } - } - case opStructFieldStringTag: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - b = append(b, code.key...) - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagString: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - s := e.ptrToString(ptr + code.offset) - b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) - b = encodeComma(b) - code = code.next - case opStructFieldStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - b = append(b, code.key...) - b = encodeByteSlice(b, v) - b = encodeComma(b) - code = code.next - case opStructFieldStringTagMarshalJSON: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - bb, err := v.(Marshaler).MarshalJSON() + bytes, err := v.(encoding.TextMarshaler).MarshalText() if err != nil { return nil, errMarshaler(code, err) } - var buf bytes.Buffer - if err := compact(&buf, bb, e.enabledHTMLEscape); err != nil { - return nil, err - } - b = append(b, code.key...) - b = encodeNoEscapedString(b, buf.String()) + b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) b = encodeComma(b) code = code.next case opStructFieldStringTagMarshalText: @@ -5443,6 +5583,94 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) b = encodeComma(b) code = code.next + case opStructFieldOmitEmptyMarshalText: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + if v != nil { + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = append(b, code.key...) + b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = encodeComma(b) + } + code = code.next + case opStructFieldArray: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptyArray: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + array := e.ptrToSlice(p) + if p == 0 || uintptr(array.data) == 0 { + code = code.nextField + } else { + code = code.next + } + case opStructFieldSlice: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptySlice: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + slice := e.ptrToSlice(p) + if p == 0 || uintptr(slice.data) == 0 { + code = code.nextField + } else { + code = code.next + } + case opStructFieldMap: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptyMap: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + code = code.next + } + } + case opStructFieldMapLoad: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptyMapLoad: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + code = code.next + } + } + case opStructFieldStruct: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) case opStructEnd: last := len(b) - 1 if b[last] == ',' { @@ -5600,6 +5828,29 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = appendStructEnd(b) + code = code.next case opStructEndInt16Ptr: b = append(b, code.key...) ptr := load(ctxptr, code.headIdx) @@ -5611,10 +5862,66 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndInt16: + case opStructEndOmitEmptyInt16Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt16(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt16Ptr: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt16NPtr: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + for i := 0; i < code.ptrNum-1; i++ { + if p == 0 { + break + } + p = e.ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, int64(e.ptrToInt16(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndInt32Ptr: @@ -5628,10 +5935,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndInt32: + case opStructEndInt64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndInt64Ptr: @@ -5645,10 +5969,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndInt64: + case opStructEndUint: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } + code = code.next + case opStructEndStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUintPtr: @@ -5662,10 +6003,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndUint: + case opStructEndUint8: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint8Ptr: @@ -5679,10 +6037,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndUint8: + case opStructEndUint16: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint16Ptr: @@ -5696,10 +6071,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndUint16: + case opStructEndUint32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint32Ptr: @@ -5713,10 +6105,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndUint32: + case opStructEndUint64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint64Ptr: @@ -5730,10 +6139,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndUint64: + case opStructEndFloat32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = encodeFloat32(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndFloat32Ptr: @@ -5747,10 +6173,38 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndFloat32: + case opStructEndFloat64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = encodeFloat64(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat64(b, v) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndFloat64Ptr: @@ -5770,14 +6224,26 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeFloat64(b, v) b = appendStructEnd(b) code = code.next - case opStructEndFloat64: + case opStructEndString: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) + b = encodeNoEscapedString(b, e.ptrToString(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = append(b, code.key...) + b = encodeNoEscapedString(b, v) } - b = encodeFloat64(b, v) + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagString: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + s := e.ptrToString(ptr + code.offset) + b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) b = appendStructEnd(b) code = code.next case opStructEndStringPtr: @@ -5791,10 +6257,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndString: + case opStructEndBool: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = encodeNoEscapedString(b, e.ptrToString(ptr+code.offset)) + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = append(b, code.key...) + b = encodeBool(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndBoolPtr: @@ -5808,18 +6291,28 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = appendStructEnd(b) - code = code.next case opStructEndBytes: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = append(b, code.key...) + b = encodeByteSlice(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + b = append(b, code.key...) + b = encodeByteSlice(b, v) + b = appendStructEnd(b) + code = code.next case opStructEndMarshalJSON: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -5836,138 +6329,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = append(b, buf.Bytes()...) b = appendStructEnd(b) code = code.next - case opStructEndMarshalText: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = appendStructEnd(b) - } - code = code.next - case opStructEndOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendUint(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = encodeFloat32(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = encodeFloat64(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = append(b, code.key...) - b = encodeNoEscapedString(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = append(b, code.key...) - b = encodeBool(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = append(b, code.key...) - b = encodeByteSlice(b, v) - } - b = appendStructEnd(b) - code = code.next case opStructEndOmitEmptyMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -5986,126 +6347,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndOmitEmptyMarshalText: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - if v != nil { - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = append(b, code.key...) - b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - } - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagString: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - s := e.ptrToString(ptr + code.offset) - b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - b = append(b, code.key...) - b = encodeByteSlice(b, v) - b = appendStructEnd(b) - code = code.next case opStructEndStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -6122,6 +6363,32 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeNoEscapedString(b, buf.String()) b = appendStructEnd(b) code = code.next + case opStructEndMarshalText: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyMarshalText: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + if v != nil { + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = append(b, code.key...) + b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + } + b = appendStructEnd(b) + code = code.next case opStructEndStringTagMarshalText: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 97d43b6..98e5978 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -4760,6 +4760,22 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) ptr := load(ctxptr, code.headIdx) + code.offset code = code.next store(ctxptr, code.idx, ptr) + case opStructFieldOmitEmpty: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + code = code.next + store(ctxptr, code.idx, p) + } + case opStructFieldStringTag: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + b = append(b, code.escapedKey...) + code = code.next + store(ctxptr, code.idx, p) case opStructFieldInt: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -4845,6 +4861,29 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldInt16Ptr: b = append(b, code.escapedKey...) ptr := load(ctxptr, code.headIdx) @@ -4856,10 +4895,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldInt16: + case opStructFieldInt32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldInt32Ptr: @@ -4873,10 +4929,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldInt32: + case opStructFieldInt64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldInt64Ptr: @@ -4890,10 +4963,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldInt64: + case opStructFieldUint: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUintPtr: @@ -4907,10 +4997,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldUint: + case opStructFieldUint8: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint8Ptr: @@ -4924,10 +5031,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldUint8: + case opStructFieldUint16: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint16Ptr: @@ -4941,10 +5065,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldUint16: + case opStructFieldUint32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint32Ptr: @@ -4958,10 +5099,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldUint32: + case opStructFieldUint64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldUint64Ptr: @@ -4975,10 +5133,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldUint64: + case opStructFieldFloat32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldFloat32Ptr: @@ -4992,10 +5167,38 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldFloat32: + case opStructFieldFloat64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat64(b, v) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldFloat64Ptr: @@ -5015,14 +5218,26 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeFloat64(b, v) b = encodeComma(b) code = code.next - case opStructFieldFloat64: + case opStructFieldString: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) + b = encodeEscapedString(b, e.ptrToString(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = append(b, code.escapedKey...) + b = encodeEscapedString(b, v) + b = encodeComma(b) } - b = encodeFloat64(b, v) + code = code.next + case opStructFieldStringTagString: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + s := e.ptrToString(ptr + code.offset) + b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) b = encodeComma(b) code = code.next case opStructFieldStringPtr: @@ -5036,10 +5251,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldString: + case opStructFieldBool: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = encodeEscapedString(b, e.ptrToString(ptr+code.offset)) + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = append(b, code.escapedKey...) + b = encodeBool(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldBoolPtr: @@ -5053,18 +5285,28 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = encodeComma(b) - code = code.next case opStructFieldBytes: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = encodeComma(b) code = code.next + case opStructFieldOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = append(b, code.escapedKey...) + b = encodeByteSlice(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + b = append(b, code.escapedKey...) + b = encodeByteSlice(b, v) + b = encodeComma(b) + code = code.next case opStructFieldMarshalJSON: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -5081,178 +5323,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = append(b, buf.Bytes()...) b = encodeComma(b) code = code.next - case opStructFieldMarshalText: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - b = encodeComma(b) - code = code.next - case opStructFieldArray: - b = append(b, code.escapedKey...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldSlice: - b = append(b, code.escapedKey...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldMap: - b = append(b, code.escapedKey...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldMapLoad: - b = append(b, code.escapedKey...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldStruct: - b = append(b, code.escapedKey...) - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldOmitEmpty: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - code = code.next - store(ctxptr, code.idx, p) - } - case opStructFieldOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = encodeFloat32(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = encodeFloat64(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = append(b, code.escapedKey...) - b = encodeEscapedString(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = append(b, code.escapedKey...) - b = encodeBool(b, v) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = append(b, code.escapedKey...) - b = encodeByteSlice(b, v) - b = encodeComma(b) - } - code = code.next case opStructFieldOmitEmptyMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -5271,176 +5341,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) } code = code.next - case opStructFieldOmitEmptyMarshalText: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - if v != nil { - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = append(b, code.escapedKey...) - b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - b = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyArray: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - array := e.ptrToSlice(p) - if p == 0 || uintptr(array.data) == 0 { - code = code.nextField - } else { - code = code.next - } - case opStructFieldOmitEmptySlice: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - slice := e.ptrToSlice(p) - if p == 0 || uintptr(slice.data) == 0 { - code = code.nextField - } else { - code = code.next - } - case opStructFieldOmitEmptyMap: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - code = code.next - } - } - case opStructFieldOmitEmptyMapLoad: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - code = code.next - } - } - case opStructFieldStringTag: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - b = append(b, code.escapedKey...) - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagString: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - s := e.ptrToString(ptr + code.offset) - b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) - b = encodeComma(b) - code = code.next - case opStructFieldStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldStringTagBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - b = append(b, code.escapedKey...) - b = encodeByteSlice(b, v) - b = encodeComma(b) - code = code.next case opStructFieldStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -5457,6 +5357,32 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeEscapedString(b, buf.String()) b = encodeComma(b) code = code.next + case opStructFieldMarshalText: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyMarshalText: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + if v != nil { + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = append(b, code.escapedKey...) + b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = encodeComma(b) + } + code = code.next case opStructFieldStringTagMarshalText: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -5469,6 +5395,80 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) b = encodeComma(b) code = code.next + case opStructFieldArray: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptyArray: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + array := e.ptrToSlice(p) + if p == 0 || uintptr(array.data) == 0 { + code = code.nextField + } else { + code = code.next + } + case opStructFieldSlice: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptySlice: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + slice := e.ptrToSlice(p) + if p == 0 || uintptr(slice.data) == 0 { + code = code.nextField + } else { + code = code.next + } + case opStructFieldMap: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptyMap: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + code = code.next + } + } + case opStructFieldMapLoad: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) + case opStructFieldOmitEmptyMapLoad: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + code = code.next + } + } + case opStructFieldStruct: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + code = code.next + store(ctxptr, code.idx, p) case opStructEnd: last := len(b) - 1 if b[last] == ',' { @@ -5626,6 +5626,29 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = appendStructEnd(b) + code = code.next case opStructEndInt16Ptr: b = append(b, code.escapedKey...) ptr := load(ctxptr, code.headIdx) @@ -5637,10 +5660,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndInt16: + case opStructEndInt32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndInt32Ptr: @@ -5654,10 +5694,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndInt32: + case opStructEndInt64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndInt64Ptr: @@ -5671,10 +5728,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndInt64: + case opStructEndUint: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUintPtr: @@ -5688,10 +5762,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndUint: + case opStructEndUint8: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint8Ptr: @@ -5705,10 +5796,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndUint8: + case opStructEndUint16: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint16Ptr: @@ -5722,10 +5830,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndUint16: + case opStructEndUint32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint32Ptr: @@ -5739,10 +5864,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndUint32: + case opStructEndUint64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndUint64Ptr: @@ -5756,10 +5898,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndUint64: + case opStructEndFloat32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndFloat32Ptr: @@ -5773,10 +5932,38 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndFloat32: + case opStructEndFloat64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = encodeFloat64(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat64(b, v) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndFloat64Ptr: @@ -5796,14 +5983,26 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeFloat64(b, v) b = appendStructEnd(b) code = code.next - case opStructEndFloat64: + case opStructEndString: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) + b = encodeEscapedString(b, e.ptrToString(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = append(b, code.escapedKey...) + b = encodeEscapedString(b, v) } - b = encodeFloat64(b, v) + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagString: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + s := e.ptrToString(ptr + code.offset) + b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) b = appendStructEnd(b) code = code.next case opStructEndStringPtr: @@ -5817,10 +6016,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndString: + case opStructEndBool: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = encodeEscapedString(b, e.ptrToString(ptr+code.offset)) + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = append(b, code.escapedKey...) + b = encodeBool(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') b = appendStructEnd(b) code = code.next case opStructEndBoolPtr: @@ -5834,18 +6050,28 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = appendStructEnd(b) - code = code.next case opStructEndBytes: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = append(b, code.escapedKey...) + b = encodeByteSlice(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + b = append(b, code.escapedKey...) + b = encodeByteSlice(b, v) + b = appendStructEnd(b) + code = code.next case opStructEndMarshalJSON: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -5862,138 +6088,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = append(b, buf.Bytes()...) b = appendStructEnd(b) code = code.next - case opStructEndMarshalText: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, int64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, int64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendUint(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = encodeFloat32(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = encodeFloat64(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = append(b, code.escapedKey...) - b = encodeEscapedString(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = append(b, code.escapedKey...) - b = encodeBool(b, v) - } - b = appendStructEnd(b) - code = code.next - case opStructEndOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = append(b, code.escapedKey...) - b = encodeByteSlice(b, v) - } - b = appendStructEnd(b) - code = code.next case opStructEndOmitEmptyMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -6012,126 +6106,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndOmitEmptyMarshalText: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - v := e.ptrToInterface(code, p) - if v != nil { - bytes, err := v.(encoding.TextMarshaler).MarshalText() - if err != nil { - return nil, errMarshaler(code, err) - } - b = append(b, code.escapedKey...) - b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) - } - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagString: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - s := e.ptrToString(ptr + code.offset) - b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next - case opStructEndStringTagBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - b = append(b, code.escapedKey...) - b = encodeByteSlice(b, v) - b = appendStructEnd(b) - code = code.next case opStructEndStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset @@ -6148,6 +6122,32 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeEscapedString(b, buf.String()) b = appendStructEnd(b) code = code.next + case opStructEndMarshalText: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyMarshalText: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + v := e.ptrToInterface(code, p) + if v != nil { + bytes, err := v.(encoding.TextMarshaler).MarshalText() + if err != nil { + return nil, errMarshaler(code, err) + } + b = append(b, code.escapedKey...) + b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + } + b = appendStructEnd(b) + code = code.next case opStructEndStringTagMarshalText: ptr := load(ctxptr, code.headIdx) p := ptr + code.offset diff --git a/encode_vm_escaped_indent.go b/encode_vm_escaped_indent.go index 89f3e40..39ed3cb 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -4060,6 +4060,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op p := ptr + code.offset code = code.next store(ctxptr, code.idx, p) + case opStructFieldOmitEmpty: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + code = code.next + store(ctxptr, code.idx, p) + } + case opStructFieldStringTag: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + code = code.next + store(ctxptr, code.idx, p) case opStructFieldInt: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4124,6 +4144,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldInt32: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4132,6 +4172,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldInt64: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4140,6 +4200,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, e.ptrToInt64(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4148,6 +4228,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint8: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4156,6 +4256,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint16: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4164,6 +4284,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint32: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4172,6 +4312,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint64: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4180,6 +4340,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldFloat32: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4188,6 +4368,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat32(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldFloat64: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4200,6 +4400,33 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeFloat64(b, v) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldString: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4208,6 +4435,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeEscapedString(b, e.ptrToString(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeEscapedString(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagString: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + s := e.ptrToString(ptr + code.offset) + b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) + b = encodeIndentComma(b) + code = code.next case opStructFieldBool: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4216,6 +4463,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeBool(b, e.ptrToBool(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldBytes: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4224,6 +4491,25 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeByteSlice(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagBytes: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) + b = encodeIndentComma(b) + code = code.next case opStructFieldMarshalJSON: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4242,454 +4528,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, buf.Bytes()...) b = encodeIndentComma(b) code = code.next - case opStructFieldArray: - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - array := e.ptrToSlice(p) - if p == 0 || uintptr(array.data) == 0 { - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.nextField - } else { - code = code.next - } - case opStructFieldSlice: - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - slice := e.ptrToSlice(p) - if p == 0 || uintptr(slice.data) == 0 { - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.nextField - } else { - code = code.next - } - case opStructFieldMap: - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - b = encodeNull(b) - code = code.nextField - } else { - p = e.ptrToPtr(p) - mlen := maplen(e.ptrToUnsafePtr(p)) - if mlen == 0 { - b = append(b, '{', '}', ',', '\n') - mapCode := code.next - code = mapCode.end.next - } else { - code = code.next - } - } - case opStructFieldMapLoad: - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - b = encodeNull(b) - code = code.nextField - } else { - p = e.ptrToPtr(p) - mlen := maplen(e.ptrToUnsafePtr(p)) - if mlen == 0 { - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - code = code.next - } - } - case opStructFieldStruct: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - if p == 0 { - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - headCode := code.next - if headCode.next == headCode.end { - // not exists fields - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - code = code.next - store(ctxptr, code.idx, p) - } - } - case opStructFieldOmitEmpty: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - code = code.next - store(ctxptr, code.idx, p) - } - case opStructFieldOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendInt(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeFloat32(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeFloat64(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeEscapedString(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeBool(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeByteSlice(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyArray: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - array := e.ptrToSlice(p) - if p == 0 || uintptr(array.data) == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - code = code.next - } - case opStructFieldOmitEmptySlice: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - slice := e.ptrToSlice(p) - if p == 0 || uintptr(slice.data) == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - code = code.next - } - case opStructFieldOmitEmptyMap: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - code = code.next - } - } - case opStructFieldOmitEmptyMapLoad: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - code = code.next - } - } - case opStructFieldOmitEmptyStruct: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - headCode := code.next - if headCode.next == headCode.end { - // not exists fields - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - code = code.next - store(ctxptr, code.idx, p) - } - } - case opStructFieldStringTag: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagString: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - s := e.ptrToString(ptr + code.offset) - b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagBytes: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) - b = encodeIndentComma(b) - code = code.next case opStructFieldStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent) @@ -4722,6 +4560,168 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) b = encodeIndentComma(b) code = code.next + case opStructFieldArray: + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + array := e.ptrToSlice(p) + if p == 0 || uintptr(array.data) == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.nextField + } else { + code = code.next + } + case opStructFieldOmitEmptyArray: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + array := e.ptrToSlice(p) + if p == 0 || uintptr(array.data) == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + code = code.next + } + case opStructFieldSlice: + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + slice := e.ptrToSlice(p) + if p == 0 || uintptr(slice.data) == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.nextField + } else { + code = code.next + } + case opStructFieldOmitEmptySlice: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + slice := e.ptrToSlice(p) + if p == 0 || uintptr(slice.data) == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + code = code.next + } + case opStructFieldMap: + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + b = encodeNull(b) + code = code.nextField + } else { + p = e.ptrToPtr(p) + mlen := maplen(e.ptrToUnsafePtr(p)) + if mlen == 0 { + b = append(b, '{', '}', ',', '\n') + mapCode := code.next + code = mapCode.end.next + } else { + code = code.next + } + } + case opStructFieldOmitEmptyMap: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + code = code.next + } + } + case opStructFieldMapLoad: + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + b = encodeNull(b) + code = code.nextField + } else { + p = e.ptrToPtr(p) + mlen := maplen(e.ptrToUnsafePtr(p)) + if mlen == 0 { + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + code = code.next + } + } + case opStructFieldOmitEmptyMapLoad: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + code = code.next + } + } + case opStructFieldStruct: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + if p == 0 { + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + headCode := code.next + if headCode.next == headCode.end { + // not exists fields + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + code = code.next + store(ctxptr, code.idx, p) + } + } + case opStructFieldOmitEmptyStruct: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + headCode := code.next + if headCode.next == headCode.end { + // not exists fields + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + code = code.next + store(ctxptr, code.idx, p) + } + } case opStructAnonymousEnd: code = code.next case opStructEnd: @@ -4919,6 +4919,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt16Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4940,6 +4960,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt32Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4961,6 +5001,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, e.ptrToInt64(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt64Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4982,6 +5042,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUintPtr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5003,6 +5083,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint8Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5024,6 +5124,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint16Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5045,6 +5165,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint32Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5066,6 +5206,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint64Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5087,6 +5247,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat32(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat32Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5112,6 +5292,33 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeFloat64(b, v) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat64(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeFloat64(b, v) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat64Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5137,6 +5344,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeEscapedString(b, e.ptrToString(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeEscapedString(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagString: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + s := e.ptrToString(ptr + code.offset) + b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndBool: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5145,6 +5372,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeBool(b, e.ptrToBool(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndBytes: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5153,6 +5400,25 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeByteSlice(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagBytes: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndMarshalJSON: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -5171,272 +5437,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, buf.Bytes()...) b = e.appendStructEndIndent(b, code.indent-1) code = code.next - case opStructEndOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendInt(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = appendUint(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeFloat32(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeFloat64(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeEscapedString(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeBool(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeByteSlice(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagString: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - s := e.ptrToString(ptr + code.offset) - b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagBytes: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next case opStructEndStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index eee093c..416b186 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -4060,6 +4060,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( p := ptr + code.offset code = code.next store(ctxptr, code.idx, p) + case opStructFieldOmitEmpty: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + code = code.next + store(ctxptr, code.idx, p) + } + case opStructFieldStringTag: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + code = code.next + store(ctxptr, code.idx, p) case opStructFieldInt: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4116,7 +4136,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, '"') b = encodeIndentComma(b) code = code.next - case opStructFieldInt16: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4125,6 +4144,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldInt32: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4133,6 +4172,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldInt64: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4141,6 +4200,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, e.ptrToInt64(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4149,6 +4228,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint8: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4157,6 +4256,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint16: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4165,6 +4284,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint32: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4173,6 +4312,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldUint64: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4181,6 +4340,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldFloat32: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4189,6 +4368,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat32(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldFloat64: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4201,6 +4400,33 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeFloat64(b, v) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldString: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4209,6 +4435,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeNoEscapedString(b, e.ptrToString(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeNoEscapedString(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagString: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + s := e.ptrToString(ptr + code.offset) + b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) + b = encodeIndentComma(b) + code = code.next case opStructFieldBool: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4217,6 +4463,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeBool(b, e.ptrToBool(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldBytes: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4225,6 +4491,25 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeByteSlice(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagBytes: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) + b = encodeIndentComma(b) + code = code.next case opStructFieldMarshalJSON: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4243,454 +4528,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, buf.Bytes()...) b = encodeIndentComma(b) code = code.next - case opStructFieldArray: - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - array := e.ptrToSlice(p) - if p == 0 || uintptr(array.data) == 0 { - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.nextField - } else { - code = code.next - } - case opStructFieldSlice: - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - slice := e.ptrToSlice(p) - if p == 0 || uintptr(slice.data) == 0 { - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.nextField - } else { - code = code.next - } - case opStructFieldMap: - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - b = encodeNull(b) - code = code.nextField - } else { - p = e.ptrToPtr(p) - mlen := maplen(e.ptrToUnsafePtr(p)) - if mlen == 0 { - b = append(b, '{', '}', ',', '\n') - mapCode := code.next - code = mapCode.end.next - } else { - code = code.next - } - } - case opStructFieldMapLoad: - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - b = encodeNull(b) - code = code.nextField - } else { - p = e.ptrToPtr(p) - mlen := maplen(e.ptrToUnsafePtr(p)) - if mlen == 0 { - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - code = code.next - } - } - case opStructFieldStruct: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - if p == 0 { - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - headCode := code.next - if headCode.next == headCode.end { - // not exists fields - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - code = code.next - store(ctxptr, code.idx, p) - } - } - case opStructFieldOmitEmpty: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 || **(**uintptr)(unsafe.Pointer(&p)) == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - code = code.next - store(ctxptr, code.idx, p) - } - case opStructFieldOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendInt(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeFloat32(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeFloat64(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeNoEscapedString(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeBool(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeByteSlice(b, v) - b = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyArray: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - array := e.ptrToSlice(p) - if p == 0 || uintptr(array.data) == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - code = code.next - } - case opStructFieldOmitEmptySlice: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - slice := e.ptrToSlice(p) - if p == 0 || uintptr(slice.data) == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - code = code.next - } - case opStructFieldOmitEmptyMap: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - code = code.next - } - } - case opStructFieldOmitEmptyMapLoad: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) - if mlen == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - code = code.next - } - } - case opStructFieldOmitEmptyStruct: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - if p == 0 { - code = code.nextField - } else { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - headCode := code.next - if headCode.next == headCode.end { - // not exists fields - b = append(b, '{', '}', ',', '\n') - code = code.nextField - } else { - code = code.next - store(ctxptr, code.idx, p) - } - } - case opStructFieldStringTag: - ptr := load(ctxptr, code.headIdx) - p := ptr + code.offset - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - code = code.next - store(ctxptr, code.idx, p) - case opStructFieldStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagString: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - s := e.ptrToString(ptr + code.offset) - b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagBytes: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) - b = encodeIndentComma(b) - code = code.next case opStructFieldStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent) @@ -4723,6 +4560,168 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) b = encodeIndentComma(b) code = code.next + case opStructFieldArray: + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + array := e.ptrToSlice(p) + if p == 0 || uintptr(array.data) == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.nextField + } else { + code = code.next + } + case opStructFieldOmitEmptyArray: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + array := e.ptrToSlice(p) + if p == 0 || uintptr(array.data) == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + code = code.next + } + case opStructFieldSlice: + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + slice := e.ptrToSlice(p) + if p == 0 || uintptr(slice.data) == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.nextField + } else { + code = code.next + } + case opStructFieldOmitEmptySlice: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + slice := e.ptrToSlice(p) + if p == 0 || uintptr(slice.data) == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + code = code.next + } + case opStructFieldMap: + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + b = encodeNull(b) + code = code.nextField + } else { + p = e.ptrToPtr(p) + mlen := maplen(e.ptrToUnsafePtr(p)) + if mlen == 0 { + b = append(b, '{', '}', ',', '\n') + mapCode := code.next + code = mapCode.end.next + } else { + code = code.next + } + } + case opStructFieldOmitEmptyMap: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + code = code.next + } + } + case opStructFieldMapLoad: + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + b = encodeNull(b) + code = code.nextField + } else { + p = e.ptrToPtr(p) + mlen := maplen(e.ptrToUnsafePtr(p)) + if mlen == 0 { + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + code = code.next + } + } + case opStructFieldOmitEmptyMapLoad: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + mlen := maplen(**(**unsafe.Pointer)(unsafe.Pointer(&p))) + if mlen == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + code = code.next + } + } + case opStructFieldStruct: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + if p == 0 { + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + headCode := code.next + if headCode.next == headCode.end { + // not exists fields + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + code = code.next + store(ctxptr, code.idx, p) + } + } + case opStructFieldOmitEmptyStruct: + ptr := load(ctxptr, code.headIdx) + p := ptr + code.offset + if p == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + headCode := code.next + if headCode.next == headCode.end { + // not exists fields + b = append(b, '{', '}', ',', '\n') + code = code.nextField + } else { + code = code.next + store(ctxptr, code.idx, p) + } + } case opStructAnonymousEnd: code = code.next case opStructEnd: @@ -4920,6 +4919,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagInt16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt16Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4941,6 +4960,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagInt32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt32Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4962,6 +5001,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, e.ptrToInt64(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndOmitEmptyInt64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt64Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4983,6 +5042,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUintPtr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5004,6 +5083,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint8(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint8Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5025,6 +5124,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint16: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint16(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint16: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint16Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5046,6 +5165,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, uint64(v)) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagUint32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint32Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5067,6 +5206,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndOmitEmptyUint64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToUint64(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint64Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5088,6 +5247,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat32: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat32(ptr + code.offset) + if v != 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat32(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagFloat32: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat32Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5113,6 +5292,33 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeFloat64(b, v) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat64(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagFloat64: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeFloat64(b, v) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat64Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5138,6 +5344,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeNoEscapedString(b, e.ptrToString(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyString: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToString(ptr + code.offset) + if v != "" { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeNoEscapedString(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagString: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + s := e.ptrToString(ptr + code.offset) + b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndBool: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5146,6 +5372,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeBool(b, e.ptrToBool(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyBool: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBool(ptr + code.offset) + if v { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagBool: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeBool(b, e.ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndBytes: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5154,6 +5400,25 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyBytes: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToBytes(ptr + code.offset) + if len(v) > 0 { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeByteSlice(b, v) + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next + case opStructEndStringTagBytes: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndMarshalJSON: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -5172,272 +5437,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, buf.Bytes()...) b = e.appendStructEndIndent(b, code.indent-1) code = code.next - case opStructEndOmitEmptyInt16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyInt32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendInt(b, int64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyInt64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendInt(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint8(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint16: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint16(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, uint64(v)) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyUint64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToUint64(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = appendUint(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyFloat32: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat32(ptr + code.offset) - if v != 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeFloat32(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeFloat64(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyString: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToString(ptr + code.offset) - if v != "" { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeNoEscapedString(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyBool: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBool(ptr + code.offset) - if v { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeBool(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndOmitEmptyBytes: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToBytes(ptr + code.offset) - if len(v) > 0 { - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeByteSlice(b, v) - } - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagInt16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagInt32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint16: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagFloat32: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagFloat64: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagString: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - s := e.ptrToString(ptr + code.offset) - b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagBool: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeBool(b, e.ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next - case opStructEndStringTagBytes: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeByteSlice(b, e.ptrToBytes(ptr+code.offset)) - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next case opStructEndStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent)