return ErrEND when reading a TAG_End

This commit is contained in:
JunDao
2019-05-19 15:44:09 +08:00
parent e088636fbc
commit 2c41d9b901

View File

@ -24,10 +24,15 @@ func (d *Decoder) Decode(v interface{}) error {
return d.unmarshal(val.Elem(), tagType, tagName) return d.unmarshal(val.Elem(), tagType, tagName)
} }
// ErrEND error will be returned when reading a NBT with only Tag_End
var ErrEND = errors.New("unexpected TAG_End")
func (d *Decoder) unmarshal(val reflect.Value, tagType byte, tagName string) error { func (d *Decoder) unmarshal(val reflect.Value, tagType byte, tagName string) error {
switch tagType { switch tagType {
default: default:
return fmt.Errorf("unknown Tag 0x%02x", tagType) return fmt.Errorf("unknown Tag 0x%02x", tagType)
case TagEnd:
return ErrEND
case TagByte: case TagByte:
value, err := d.r.ReadByte() value, err := d.r.ReadByte()