Fix head operation

This commit is contained in:
Masaaki Goshima 2020-08-22 18:16:06 +09:00
parent cdf2498285
commit 47d7d26a50
1 changed files with 6 additions and 2 deletions

View File

@ -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
}