From 90737d09e41b52a88d0d912e89ef7aca371141e9 Mon Sep 17 00:00:00 2001 From: Tnze Date: Sun, 16 Apr 2023 21:14:29 +0800 Subject: [PATCH] Clean up unnecessary garbage --- nbt/encode.go | 11 ++++++----- nbt/nbt.go | 5 ----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/nbt/encode.go b/nbt/encode.go index 1e876b4..5086109 100644 --- a/nbt/encode.go +++ b/nbt/encode.go @@ -188,14 +188,15 @@ func (e *Encoder) writeValue(val reflect.Value, tagType byte) error { continue } typ, v := getTagType(v) - if typ == TagNone { + if typ == TagEnd { return fmt.Errorf("encode %q error: unsupport type %v", t.name, v.Type()) } if t.list { - if IsArrayTag(typ) { + switch typ { + case TagByteArray, TagIntArray, TagLongArray: typ = TagList // override the parsed type - } else { + default: return fmt.Errorf("invalid use of ,list struct tag, trying to encode %v as TagList", v.Type()) } } @@ -214,7 +215,7 @@ func (e *Encoder) writeValue(val reflect.Value, tagType byte) error { tagName = r.Key().String() } tagType, tagValue := getTagType(r.Value()) - if tagType == TagNone { + if tagType == TagEnd { return fmt.Errorf("encoding %q error: unsupport type %v", tagName, tagValue.Type()) } @@ -316,7 +317,7 @@ func getTagTypeByType(vk reflect.Type) byte { case reflect.Struct, reflect.Map: return TagCompound default: - return TagNone + return TagEnd } } diff --git a/nbt/nbt.go b/nbt/nbt.go index 9ef0dd2..75668b6 100644 --- a/nbt/nbt.go +++ b/nbt/nbt.go @@ -21,13 +21,8 @@ const ( TagCompound TagIntArray TagLongArray - TagNone = 0xFF ) -func IsArrayTag(ty byte) bool { - return ty == TagByteArray || ty == TagIntArray || ty == TagLongArray -} - type DecoderReader = interface { io.ByteReader io.Reader