From 47d7d26a50ecf84ca3f8c5625caee8cee14d5b96 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 22 Aug 2020 18:16:06 +0900 Subject: [PATCH] Fix head operation --- encode_vm.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/encode_vm.go b/encode_vm.go index 8265cde..b5133b6 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -538,7 +538,11 @@ func (e *Encoder) run(code *opcode) error { field := code.toStructFieldCode() ptr := field.ptr if ptr == 0 { - e.encodeNull() + if code.op == opStructFieldPtrHead { + e.encodeNull() + } else { + e.encodeBytes([]byte{'{', '}'}) + } code = field.end.next } else { e.encodeByte('{') @@ -585,7 +589,7 @@ func (e *Encoder) run(code *opcode) error { code = field.end } else { e.encodeBytes(field.key) - e.encodeInt(e.ptrToInt(ptr)) + e.encodeInt(e.ptrToInt(ptr + field.offset)) field.nextField.ptr = ptr code = field.next }