Commit 9033141f authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

gofmt

parent 3855a29d
package multiaddr
import(
"fmt"
"strings"
import (
"encoding/binary"
"fmt"
"net"
"strconv"
"strings"
)
func StringToBytes(s string) ([]byte, error) {
b := []byte{}
sp := strings.Split(s, "/")
......@@ -16,7 +15,7 @@ func StringToBytes(s string) ([]byte, error) {
// consume first empty elem
sp = sp[1:]
for ; len(sp) > 0 ; {
for len(sp) > 0 {
p := ProtocolWithName(sp[0])
if p == nil {
return nil, fmt.Errorf("no protocol with name %s", sp[0])
......@@ -42,7 +41,7 @@ func BytesToString(b []byte) (ret string, err error) {
s := ""
for ; len(b) > 0 ; {
for len(b) > 0 {
p := ProtocolWithCode(int(b[0]))
if p == nil {
return "", fmt.Errorf("no protocol with code %d", b[0])
......@@ -50,7 +49,7 @@ func BytesToString(b []byte) (ret string, err error) {
s = strings.Join([]string{s, "/", p.Name}, "")
b = b[1:]
a := AddressBytesToString(p, b[:(p.Size / 8)])
a := AddressBytesToString(p, b[:(p.Size/8)])
if len(a) > 0 {
s = strings.Join([]string{s, "/", a}, "")
}
......@@ -95,4 +94,3 @@ func AddressBytesToString(p *Protocol, b []byte) string {
return ""
}
......@@ -33,19 +33,19 @@ func (m *Multiaddr) Protocols() (ret []*Protocol, err error) {
ps := []*Protocol{}
b := m.Bytes[:]
for ; len(b) > 0 ; {
for len(b) > 0 {
p := ProtocolWithCode(int(b[0]))
if p == nil {
return nil, fmt.Errorf("no protocol with code %d", b[0])
}
ps = append(ps, p)
b = b[1 + (p.Size / 8):]
b = b[1+(p.Size/8):]
}
return ps, nil
}
func (m *Multiaddr) Encapsulate(o *Multiaddr) *Multiaddr {
b := make([]byte, len(m.Bytes) + len(o.Bytes))
b := make([]byte, len(m.Bytes)+len(o.Bytes))
b = append(m.Bytes, o.Bytes...)
return &Multiaddr{Bytes: b}
}
......
......@@ -2,11 +2,10 @@ package multiaddr
import (
"bytes"
"testing"
"encoding/hex"
"testing"
)
func TestStringToBytes(t *testing.T) {
testString := func(s string, h string) {
......@@ -49,7 +48,6 @@ func TestBytesToString(t *testing.T) {
testString("/ip4/127.0.0.1/udp/1234", "047f0000011104d2")
}
func TestProtocols(t *testing.T) {
m, err := NewMultiaddr("/ip4/127.0.0.1/udp/1234")
if err != nil {
......
......@@ -24,7 +24,7 @@ var Protocols = []*Protocol{
}
func ProtocolWithName(s string) *Protocol {
for _, p := range(Protocols) {
for _, p := range Protocols {
if p.Name == s {
return p
}
......@@ -33,7 +33,7 @@ func ProtocolWithName(s string) *Protocol {
}
func ProtocolWithCode(c int) *Protocol {
for _, p := range(Protocols) {
for _, p := range Protocols {
if p.Code == c {
return p
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment