NBT RawMessage fully support

This commit is contained in:
Tnze
2021-07-05 00:58:41 +08:00
parent 43588a8894
commit d7091db5b3
13 changed files with 196 additions and 94 deletions

34
nbt/rawmsg.go Normal file
View File

@ -0,0 +1,34 @@
package nbt
import (
"bytes"
"io"
)
type RawMessage struct {
Type byte
Data []byte
}
func (m RawMessage) TagType() byte {
return m.Type
}
func (m RawMessage) Encode(w io.Writer) error {
_, err := w.Write(m.Data)
return err
}
func (m *RawMessage) Decode(tagType byte, r DecoderReader) error {
if tagType == TagEnd {
return ErrEND
}
buf := bytes.NewBuffer(m.Data[:0])
tee := io.TeeReader(r, buf)
err := NewDecoder(tee).rawRead(tagType)
if err != nil {
return err
}
m.Data = buf.Bytes()
return nil
}