Supplement document of nbt API

This commit is contained in:
Tnze
2021-07-06 09:41:32 +08:00
parent 870b4b1a0f
commit 08d2c03a58
4 changed files with 98 additions and 31 deletions

View File

@ -2,10 +2,13 @@ package nbt
import (
"bytes"
"errors"
"io"
"reflect"
"strings"
)
// RawMessage stores the raw binary data of NBT.
type RawMessage struct {
Type byte
Data []byte
@ -49,3 +52,12 @@ func (m RawMessage) String() string {
}
return sb.String()
}
func (m RawMessage) Unmarshal(v interface{}) error {
d := NewDecoder(bytes.NewReader(m.Data))
val := reflect.ValueOf(v)
if val.Kind() != reflect.Ptr {
return errors.New("nbt: non-pointer passed to Decode")
}
return d.unmarshal(val, m.Type)
}