mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-05 22:43:10 +00:00
commit
997959a3cb
@ -5,7 +5,7 @@ os:
|
|||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.8
|
- 1.10.x
|
||||||
|
|
||||||
install: true
|
install: true
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"math/bits"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Protocol is a Multiaddr protocol description structure.
|
// Protocol is a Multiaddr protocol description structure.
|
||||||
@ -117,7 +118,7 @@ func ProtocolsWithString(s string) ([]Protocol, error) {
|
|||||||
|
|
||||||
// CodeToVarint converts an integer to a varint-encoded []byte
|
// CodeToVarint converts an integer to a varint-encoded []byte
|
||||||
func CodeToVarint(num int) []byte {
|
func CodeToVarint(num int) []byte {
|
||||||
buf := make([]byte, (num/7)+1) // varint package is uint64
|
buf := make([]byte, bits.Len(uint(num))/7 + 1)
|
||||||
n := binary.PutUvarint(buf, uint64(num))
|
n := binary.PutUvarint(buf, uint64(num))
|
||||||
return buf[:n]
|
return buf[:n]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ func ip4StB(s string) ([]byte, error) {
|
|||||||
func ip6StB(s string) ([]byte, error) {
|
func ip6StB(s string) ([]byte, error) {
|
||||||
i := net.ParseIP(s).To16()
|
i := net.ParseIP(s).To16()
|
||||||
if i == nil {
|
if i == nil {
|
||||||
return nil, fmt.Errorf("failed to parse ip4 addr: %s", s)
|
return nil, fmt.Errorf("failed to parse ip6 addr: %s", s)
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user