From bf5220c3fb5e7166eace996c9358f6a71bf170f2 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Fri, 22 Jan 2021 20:06:20 +0900 Subject: [PATCH] Fix struct end operation --- encode_vm.go | 300 ++++++++++++++++++++++++++++++++---- encode_vm_escaped.go | 300 ++++++++++++++++++++++++++++++++---- encode_vm_escaped_indent.go | 214 +++++++++++++++++++++---- encode_vm_indent.go | 214 +++++++++++++++++++++---- 4 files changed, 912 insertions(+), 116 deletions(-) diff --git a/encode_vm.go b/encode_vm.go index dcea6c1..7fc7438 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -8028,8 +8028,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt: ptr := load(ctxptr, code.headIdx) @@ -8056,8 +8064,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendInt(b, int64(e.ptrToInt(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagIntPtr: b = append(b, code.key...) @@ -8101,8 +8117,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt8: ptr := load(ctxptr, code.headIdx) @@ -8129,8 +8153,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendInt(b, int64(e.ptrToInt8(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt8Ptr: b = append(b, code.key...) @@ -8174,8 +8206,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) @@ -8202,8 +8242,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendInt(b, int64(e.ptrToInt16(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt16Ptr: b = append(b, code.key...) @@ -8247,8 +8295,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt32: ptr := load(ctxptr, code.headIdx) @@ -8275,8 +8331,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendInt(b, int64(e.ptrToInt32(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt32Ptr: b = append(b, code.key...) @@ -8320,8 +8384,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendInt(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt64: ptr := load(ctxptr, code.headIdx) @@ -8348,8 +8420,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendInt(b, e.ptrToInt64(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt64Ptr: b = append(b, code.key...) @@ -8393,8 +8473,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint: ptr := load(ctxptr, code.headIdx) @@ -8421,8 +8509,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendUint(b, uint64(e.ptrToUint(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUintPtr: b = append(b, code.key...) @@ -8466,8 +8562,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint8: ptr := load(ctxptr, code.headIdx) @@ -8494,8 +8598,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendUint(b, uint64(e.ptrToUint8(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint8Ptr: b = append(b, code.key...) @@ -8539,8 +8651,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint16: ptr := load(ctxptr, code.headIdx) @@ -8567,8 +8687,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendUint(b, uint64(e.ptrToUint16(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint16Ptr: b = append(b, code.key...) @@ -8612,8 +8740,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint32: ptr := load(ctxptr, code.headIdx) @@ -8640,8 +8776,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendUint(b, uint64(e.ptrToUint32(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint32Ptr: b = append(b, code.key...) @@ -8685,8 +8829,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendUint(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint64: ptr := load(ctxptr, code.headIdx) @@ -8713,8 +8865,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = appendUint(b, e.ptrToUint64(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint64Ptr: b = append(b, code.key...) @@ -8758,8 +8918,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = encodeFloat32(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat32: ptr := load(ctxptr, code.headIdx) @@ -8786,8 +8954,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = encodeFloat32(b, e.ptrToFloat32(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat32Ptr: b = append(b, code.key...) @@ -8838,8 +9014,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = append(b, code.key...) b = encodeFloat64(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat64: ptr := load(ctxptr, code.headIdx) @@ -8880,8 +9064,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte return nil, errUnsupportedFloat(v) } b = encodeFloat64(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat64Ptr: b = append(b, code.key...) @@ -8933,8 +9125,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != "" { b = append(b, code.key...) b = encodeNoEscapedString(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagString: ptr := load(ctxptr, code.headIdx) @@ -8960,8 +9160,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if p != 0 { b = append(b, code.key...) b = encodeNoEscapedString(b, e.ptrToString(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagStringPtr: b = append(b, code.key...) @@ -9004,8 +9212,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v { b = append(b, code.key...) b = encodeBool(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagBool: ptr := load(ctxptr, code.headIdx) @@ -9038,8 +9254,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if len(v) > 0 { b = append(b, code.key...) b = encodeByteSlice(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagBytes: ptr := load(ctxptr, code.headIdx) @@ -9079,8 +9303,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = append(b, code.key...) b = append(b, buf.Bytes()...) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) @@ -9121,8 +9353,16 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = append(b, code.key...) b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagMarshalText: ptr := load(ctxptr, code.headIdx) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 9a08d36..d2f9c0f 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -8014,8 +8014,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt: ptr := load(ctxptr, code.headIdx) @@ -8042,8 +8050,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(e.ptrToInt(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagIntPtr: b = append(b, code.escapedKey...) @@ -8087,8 +8103,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt8: ptr := load(ctxptr, code.headIdx) @@ -8115,8 +8139,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(e.ptrToInt8(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt8Ptr: b = append(b, code.escapedKey...) @@ -8160,8 +8192,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) @@ -8188,8 +8228,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(e.ptrToInt16(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt16Ptr: b = append(b, code.escapedKey...) @@ -8233,8 +8281,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt32: ptr := load(ctxptr, code.headIdx) @@ -8261,8 +8317,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendInt(b, int64(e.ptrToInt32(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt32Ptr: b = append(b, code.escapedKey...) @@ -8306,8 +8370,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendInt(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt64: ptr := load(ctxptr, code.headIdx) @@ -8334,8 +8406,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendInt(b, e.ptrToInt64(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagInt64Ptr: b = append(b, code.escapedKey...) @@ -8379,8 +8459,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint: ptr := load(ctxptr, code.headIdx) @@ -8407,8 +8495,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(e.ptrToUint(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUintPtr: b = append(b, code.escapedKey...) @@ -8452,8 +8548,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint8: ptr := load(ctxptr, code.headIdx) @@ -8480,8 +8584,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(e.ptrToUint8(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint8Ptr: b = append(b, code.escapedKey...) @@ -8525,8 +8637,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint16: ptr := load(ctxptr, code.headIdx) @@ -8553,8 +8673,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(e.ptrToUint16(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint16Ptr: b = append(b, code.escapedKey...) @@ -8598,8 +8726,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(v)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint32: ptr := load(ctxptr, code.headIdx) @@ -8626,8 +8762,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendUint(b, uint64(e.ptrToUint32(p))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint32Ptr: b = append(b, code.escapedKey...) @@ -8671,8 +8815,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = appendUint(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint64: ptr := load(ctxptr, code.headIdx) @@ -8699,8 +8851,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = appendUint(b, e.ptrToUint64(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagUint64Ptr: b = append(b, code.escapedKey...) @@ -8744,8 +8904,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != 0 { b = append(b, code.escapedKey...) b = encodeFloat32(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat32: ptr := load(ctxptr, code.headIdx) @@ -8772,8 +8940,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = encodeFloat32(b, e.ptrToFloat32(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat32Ptr: b = append(b, code.escapedKey...) @@ -8824,8 +9000,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = append(b, code.escapedKey...) b = encodeFloat64(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat64: ptr := load(ctxptr, code.headIdx) @@ -8866,8 +9050,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) return nil, errUnsupportedFloat(v) } b = encodeFloat64(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagFloat64Ptr: b = append(b, code.escapedKey...) @@ -8919,8 +9111,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v != "" { b = append(b, code.escapedKey...) b = encodeEscapedString(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagString: ptr := load(ctxptr, code.headIdx) @@ -8946,8 +9146,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if p != 0 { b = append(b, code.escapedKey...) b = encodeEscapedString(b, e.ptrToString(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagStringPtr: b = append(b, code.escapedKey...) @@ -8990,8 +9198,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if v { b = append(b, code.escapedKey...) b = encodeBool(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagBool: ptr := load(ctxptr, code.headIdx) @@ -9024,8 +9240,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) if len(v) > 0 { b = append(b, code.escapedKey...) b = encodeByteSlice(b, v) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagBytes: ptr := load(ctxptr, code.headIdx) @@ -9065,8 +9289,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = append(b, code.escapedKey...) b = append(b, buf.Bytes()...) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagMarshalJSON: ptr := load(ctxptr, code.headIdx) @@ -9107,8 +9339,16 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = append(b, code.escapedKey...) b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes))) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } } - b = appendStructEnd(b) code = code.next case opStructEndStringTagMarshalText: ptr := load(ctxptr, code.headIdx) diff --git a/encode_vm_escaped_indent.go b/encode_vm_escaped_indent.go index ce7f662..319e812 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -7895,9 +7895,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -7937,9 +7942,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -7980,9 +7990,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8022,9 +8037,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8065,9 +8085,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8107,9 +8132,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8150,9 +8180,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8192,9 +8227,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8235,9 +8275,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8277,9 +8322,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8320,9 +8370,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8362,9 +8417,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8405,9 +8465,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8447,9 +8512,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8490,9 +8560,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8532,9 +8607,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8575,9 +8655,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8617,9 +8702,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8660,9 +8750,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8702,9 +8797,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8745,9 +8845,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8787,9 +8892,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8837,9 +8947,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8891,9 +9006,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8938,9 +9058,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8980,9 +9105,14 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -9017,8 +9147,22 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = encodeBool(b, v) + b = e.appendStructEndIndent(b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + b[last] = '}' + } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) + b = append(b, '}') + } + b = encodeIndentComma(b) } - b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndStringTagBool: ptr := load(ctxptr, code.headIdx) @@ -9045,8 +9189,22 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = encodeByteSlice(b, v) + b = e.appendStructEndIndent(b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + b[last] = '}' + } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) + b = append(b, '}') + } + b = encodeIndentComma(b) } - b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndStringTagBytes: ptr := load(ctxptr, code.headIdx) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index e08a54d..536e962 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -7895,9 +7895,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -7937,9 +7942,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -7980,9 +7990,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8022,9 +8037,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8065,9 +8085,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8107,9 +8132,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8150,9 +8180,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8192,9 +8227,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8235,9 +8275,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8277,9 +8322,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8320,9 +8370,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8362,9 +8417,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8405,9 +8465,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8447,9 +8512,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8490,9 +8560,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8532,9 +8607,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8575,9 +8655,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8617,9 +8702,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8660,9 +8750,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8702,9 +8797,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8745,9 +8845,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8787,9 +8892,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8837,9 +8947,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8891,9 +9006,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8938,9 +9058,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -8980,9 +9105,14 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } else { last := len(b) - 1 if b[last-1] == '{' { - // doesn't exist any fields b[last] = '}' } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) b = append(b, '}') } b = encodeIndentComma(b) @@ -9017,8 +9147,22 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = encodeBool(b, v) + b = e.appendStructEndIndent(b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + b[last] = '}' + } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) + b = append(b, '}') + } + b = encodeIndentComma(b) } - b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndStringTagBool: ptr := load(ctxptr, code.headIdx) @@ -9045,8 +9189,22 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = encodeByteSlice(b, v) + b = e.appendStructEndIndent(b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + b[last] = '}' + } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = e.encodeIndent(b, code.indent) + b = append(b, '}') + } + b = encodeIndentComma(b) } - b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndStringTagBytes: ptr := load(ctxptr, code.headIdx)