Skip to content

Commit 722b71d

Browse files
committed
msgpack: split type switch case to reflect.Int specific case
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent e1c3a9b commit 722b71d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

msgpack/field.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ func collectFields(fields []*field, t reflect.Type, visited map[reflect.Type]boo
101101
// Parse empty field tag
102102
if e := sf.Tag.Get("empty"); e != "" {
103103
switch sf.Type.Kind() {
104-
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
105-
bits := 0
106-
if sf.Type.Kind() != reflect.Int {
107-
bits = sf.Type.Bits()
104+
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
105+
v, err := strconv.ParseInt(e, 10, sf.Type.Bits())
106+
if err != nil {
107+
panic(fmt.Errorf("msgpack: error parsing field empty field %s.%s: %w", t.Name(), sf.Name, err))
108108
}
109-
v, err := strconv.ParseInt(e, 10, bits)
109+
f.empty = reflect.New(sf.Type).Elem()
110+
f.empty.SetInt(v)
111+
112+
case reflect.Int:
113+
v, err := strconv.ParseInt(e, 10, 0)
110114
if err != nil {
111115
panic(fmt.Errorf("msgpack: error parsing field empty field %s.%s: %w", t.Name(), sf.Name, err))
112116
}

0 commit comments

Comments
 (0)