mirror of
https://github.com/waku-org/go-multiaddr.git
synced 2025-02-22 19:18:14 +00:00
rm convert
This commit is contained in:
parent
c5510ff4b8
commit
47a6842e35
40
codec.go
40
codec.go
@ -3,6 +3,9 @@ package multiaddr
|
||||
import(
|
||||
"fmt"
|
||||
"strings"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
||||
@ -48,3 +51,40 @@ func BytesToString(b []byte) (string, error) {
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func AddressStringToBytes(p *Protocol, s string) []byte {
|
||||
switch p.Code {
|
||||
|
||||
// ipv4,6
|
||||
case 4, 41:
|
||||
return net.ParseIP(s).To4()
|
||||
|
||||
// tcp udp dccp sctp
|
||||
case 6, 17, 33, 132:
|
||||
b := make([]byte, 2)
|
||||
i, err := strconv.Atoi(s)
|
||||
if err == nil {
|
||||
binary.BigEndian.PutUint16(b, uint16(i))
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
func AddressBytesToString(p *Protocol, b []byte) string {
|
||||
switch p.Code {
|
||||
|
||||
// ipv4,6
|
||||
case 4, 41:
|
||||
return net.IP(b).String()
|
||||
|
||||
// tcp udp dccp sctp
|
||||
case 6, 17, 33, 132:
|
||||
i := binary.BigEndian.Uint16(b)
|
||||
return strconv.Itoa(int(i))
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
|
43
convert.go
43
convert.go
@ -1,43 +0,0 @@
|
||||
package multiaddr
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func AddressStringToBytes(p *Protocol, s string) []byte {
|
||||
switch p.Code {
|
||||
|
||||
// ipv4,6
|
||||
case 4, 41:
|
||||
return net.ParseIP(s).To4()
|
||||
|
||||
// tcp udp dccp sctp
|
||||
case 6, 17, 33, 132:
|
||||
b := make([]byte, 2)
|
||||
i, err := strconv.Atoi(s)
|
||||
if err == nil {
|
||||
binary.BigEndian.PutUint16(b, uint16(i))
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
func AddressBytesToString(p *Protocol, b []byte) string {
|
||||
switch p.Code {
|
||||
|
||||
// ipv4,6
|
||||
case 4, 41:
|
||||
return net.IP(b).String()
|
||||
|
||||
// tcp udp dccp sctp
|
||||
case 6, 17, 33, 132:
|
||||
i := binary.BigEndian.Uint16(b)
|
||||
return strconv.Itoa(int(i))
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user