Skip to content

Commit

Permalink
byteorder: simplify type switches
Browse files Browse the repository at this point in the history
Assign and reuse the result of the type assertion.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser authored and aanm committed Mar 5, 2020
1 parent 0178507 commit f158204
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/byteorder/byteorder.go
Expand Up @@ -68,23 +68,23 @@ func reverse(b []byte) []byte {

// HostToNetwork converts b to the networking byte order.
func HostToNetwork(b interface{}) interface{} {
switch b.(type) {
switch bt := b.(type) {
case uint16:
return swap16(b.(uint16))
return swap16(bt)
case uint32:
return swap32(b.(uint32))
return swap32(bt)
default:
panic(unsupported(b))
}
}

// NetworkToHost converts n to host byte order.
func NetworkToHost(n interface{}) interface{} {
switch n.(type) {
switch nt := n.(type) {
case uint16:
return swap16(n.(uint16))
return swap16(nt)
case uint32:
return swap32(n.(uint32))
return swap32(nt)
default:
panic(unsupported(n))
}
Expand Down

0 comments on commit f158204

Please sign in to comment.