Skip to content

Commit

Permalink
msgpack: split type switch case to reflect.Int specific case
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <[email protected]>
  • Loading branch information
zchee committed Sep 26, 2021
1 parent e1c3a9b commit 722b71d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions msgpack/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ func collectFields(fields []*field, t reflect.Type, visited map[reflect.Type]boo
// Parse empty field tag
if e := sf.Tag.Get("empty"); e != "" {
switch sf.Type.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
bits := 0
if sf.Type.Kind() != reflect.Int {
bits = sf.Type.Bits()
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
v, err := strconv.ParseInt(e, 10, sf.Type.Bits())
if err != nil {
panic(fmt.Errorf("msgpack: error parsing field empty field %s.%s: %w", t.Name(), sf.Name, err))
}
v, err := strconv.ParseInt(e, 10, bits)
f.empty = reflect.New(sf.Type).Elem()
f.empty.SetInt(v)

case reflect.Int:
v, err := strconv.ParseInt(e, 10, 0)
if err != nil {
panic(fmt.Errorf("msgpack: error parsing field empty field %s.%s: %w", t.Name(), sf.Name, err))
}
Expand Down

0 comments on commit 722b71d

Please sign in to comment.