Clean up unnecessary garbage

This commit is contained in:
Tnze
2023-04-16 21:14:29 +08:00
parent 7bef059b44
commit 90737d09e4
2 changed files with 6 additions and 10 deletions

View File

@ -188,14 +188,15 @@ func (e *Encoder) writeValue(val reflect.Value, tagType byte) error {
continue continue
} }
typ, v := getTagType(v) typ, v := getTagType(v)
if typ == TagNone { if typ == TagEnd {
return fmt.Errorf("encode %q error: unsupport type %v", t.name, v.Type()) return fmt.Errorf("encode %q error: unsupport type %v", t.name, v.Type())
} }
if t.list { if t.list {
if IsArrayTag(typ) { switch typ {
case TagByteArray, TagIntArray, TagLongArray:
typ = TagList // override the parsed type 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()) 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() tagName = r.Key().String()
} }
tagType, tagValue := getTagType(r.Value()) tagType, tagValue := getTagType(r.Value())
if tagType == TagNone { if tagType == TagEnd {
return fmt.Errorf("encoding %q error: unsupport type %v", tagName, tagValue.Type()) 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: case reflect.Struct, reflect.Map:
return TagCompound return TagCompound
default: default:
return TagNone return TagEnd
} }
} }

View File

@ -21,13 +21,8 @@ const (
TagCompound TagCompound
TagIntArray TagIntArray
TagLongArray TagLongArray
TagNone = 0xFF
) )
func IsArrayTag(ty byte) bool {
return ty == TagByteArray || ty == TagIntArray || ty == TagLongArray
}
type DecoderReader = interface { type DecoderReader = interface {
io.ByteReader io.ByteReader
io.Reader io.Reader