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() field := code.toStructFieldCode()
ptr := field.ptr ptr := field.ptr
if ptr == 0 { if ptr == 0 {
if code.op == opStructFieldPtrHead {
e.encodeNull() e.encodeNull()
} else {
e.encodeBytes([]byte{'{', '}'})
}
code = field.end.next code = field.end.next
} else { } else {
e.encodeByte('{') e.encodeByte('{')
@ -585,7 +589,7 @@ func (e *Encoder) run(code *opcode) error {
code = field.end code = field.end
} else { } else {
e.encodeBytes(field.key) e.encodeBytes(field.key)
e.encodeInt(e.ptrToInt(ptr)) e.encodeInt(e.ptrToInt(ptr + field.offset))
field.nextField.ptr = ptr field.nextField.ptr = ptr
code = field.next code = field.next
} }