Add nbt.RawMessage

This commit is contained in:
Tnze
2021-07-04 00:37:41 +08:00
parent 085b2efd6f
commit 8ecb6478a6
2 changed files with 29 additions and 2 deletions

23
nbt/raw.go Normal file
View File

@ -0,0 +1,23 @@
package nbt
import (
"bytes"
"io"
)
type RawMessage []byte
func (m *RawMessage) Unmarshal(tagType byte, _ string, r DecoderReader) error {
if tagType == TagEnd {
return ErrEND
}
buf := bytes.NewBuffer((*m)[:0])
tee := io.TeeReader(r, buf)
err := NewDecoder(tee).rawRead(tagType)
if err != nil {
return err
}
*m = buf.Bytes()
return nil
}