Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
47a6842e
Commit
47a6842e
authored
Jul 03, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rm convert
parent
c5510ff4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
43 deletions
+40
-43
codec.go
codec.go
+40
-0
convert.go
convert.go
+0
-43
No files found.
codec.go
View file @
47a6842e
...
...
@@ -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
""
}
convert.go
deleted
100644 → 0
View file @
c5510ff4
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
""
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment