Skip to content

Commit

Permalink
Avoid double-marshal'ing strings (uint byte arrays) (#471)
Browse files Browse the repository at this point in the history
* don't double-marshall strings (uint byte arrays)

* remove logs

* added err handling
  • Loading branch information
phillip-stephens authored Nov 1, 2024
1 parent 399faf4 commit e7cd062
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func marshalIntSlice(v interface{}) ([]byte, error) {
case []uint:
return json.Marshal(v)
case []uint8:
return json.Marshal(v)
return v, nil
case []uint16:
return json.Marshal(v)
case []uint32:
Expand Down Expand Up @@ -138,14 +138,14 @@ func marshalIntSlice(v interface{}) ([]byte, error) {
}
return json.Marshal(converted)
case uint8:
converted := make([]uint8, len(v))
converted := make([]byte, len(v))
for i, val := range v {
converted[i], ok = val.(uint8)
if !ok {
return nil, errors.New("failed to convert interface to uint8")
}
converted[i], ok = val.(byte)
}
return json.Marshal(converted)
if !ok {
return nil, errors.New("failed to convert interface to byte (uint8)")
}
return converted, nil
case uint16:
converted := make([]uint16, len(v))
for i, val := range v {
Expand Down

0 comments on commit e7cd062

Please sign in to comment.