fix TAG_List<TAG_Compound>
This commit is contained in:
@ -159,23 +159,30 @@ func writeListOrArray(e *Encoder, d *decodeState, tagName string) error {
|
|||||||
case scanBeginList: // TAG_List<TAG_List>
|
case scanBeginList: // TAG_List<TAG_List>
|
||||||
case scanBeginCompound: // TAG_List<TAG_Compound>
|
case scanBeginCompound: // TAG_List<TAG_Compound>
|
||||||
for {
|
for {
|
||||||
d.scanWhile(scanSkipSpace)
|
if d.opcode == scanSkipSpace {
|
||||||
|
d.scanWhile(scanSkipSpace)
|
||||||
|
}
|
||||||
if d.opcode != scanBeginCompound {
|
if d.opcode != scanBeginCompound {
|
||||||
return errors.New("different TagType in List")
|
return errors.New("different TagType in List")
|
||||||
}
|
}
|
||||||
writeCompoundPayload(e2, d)
|
writeCompoundPayload(e2, d)
|
||||||
count++
|
count++
|
||||||
// read ',' or ']'
|
|
||||||
if d.opcode == scanSkipSpace {
|
if d.opcode == scanSkipSpace {
|
||||||
d.scanWhile(scanSkipSpace)
|
d.scanWhile(scanSkipSpace)
|
||||||
}
|
}
|
||||||
|
// read ',' or ']'
|
||||||
d.scanNext()
|
d.scanNext()
|
||||||
|
if d.opcode == scanSkipSpace {
|
||||||
|
d.scanWhile(scanSkipSpace)
|
||||||
|
}
|
||||||
if d.opcode == scanEndValue {
|
if d.opcode == scanEndValue {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if d.opcode != scanListValue {
|
if d.opcode != scanListValue {
|
||||||
panic(phasePanicMsg)
|
panic(phasePanicMsg)
|
||||||
}
|
}
|
||||||
|
// read '{'
|
||||||
|
d.scanNext()
|
||||||
}
|
}
|
||||||
e.writeListHeader(TagCompound, tagName, count)
|
e.writeListHeader(TagCompound, tagName, count)
|
||||||
e.w.Write(buf.Bytes())
|
e.w.Write(buf.Bytes())
|
||||||
|
@ -38,7 +38,7 @@ func TestEncoder_WriteSNBT(t *testing.T) {
|
|||||||
for i := range testCases {
|
for i := range testCases {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
if err := e.WriteSNBT(testCases[i].snbt); err != nil {
|
if err := e.WriteSNBT(testCases[i].snbt); err != nil {
|
||||||
t.Error(err)
|
t.Errorf("Convert SNBT %q error: %v", testCases[i].snbt, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
want := testCases[i].nbt
|
want := testCases[i].nbt
|
||||||
|
@ -9,7 +9,7 @@ func TestSNBT_checkScanCode(t *testing.T) {
|
|||||||
//t.SkipNow()
|
//t.SkipNow()
|
||||||
var s scanner
|
var s scanner
|
||||||
s.reset()
|
s.reset()
|
||||||
for _, c := range []byte(`[I;1,2,3]`) {
|
for _, c := range []byte(`[{},{a:1b},{}]`) {
|
||||||
t.Logf("[%c] - %d", c, s.step(c))
|
t.Logf("[%c] - %d", c, s.step(c))
|
||||||
}
|
}
|
||||||
t.Logf("[%c] - %d", ' ', s.eof())
|
t.Logf("[%c] - %d", ' ', s.eof())
|
||||||
|
Reference in New Issue
Block a user