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
e1825f7b
Unverified
Commit
e1825f7b
authored
Apr 19, 2019
by
Lars Gierth
Committed by
GitHub
Apr 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #99 from multiformats/feat/bin
Add conformance testing
parents
0460aad0
2df5aa69
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
3 deletions
+111
-3
.gitignore
.gitignore
+2
-0
.travis.yml
.travis.yml
+2
-3
Makefile
Makefile
+12
-0
codecov.yml
codecov.yml
+2
-0
multiaddr/main.go
multiaddr/main.go
+93
-0
No files found.
.gitignore
View file @
e1825f7b
.vscode/
multiaddr/multiaddr
tmp/
.travis.yml
View file @
e1825f7b
...
...
@@ -9,8 +9,8 @@ go:
env
:
global
:
-
GOTFLAGS="-race"
-
GO111MODULE=on
matrix
:
-
BUILD_DEPTYPE=gx
-
BUILD_DEPTYPE=gomod
...
...
@@ -20,11 +20,10 @@ install:
script
:
-
bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
-
make conformance
cache
:
directories
:
-
$GOPATH/src/gx
-
$GOPATH/pkg/mod
-
/home/travis/.cache/go-build
...
...
Makefile
View file @
e1825f7b
...
...
@@ -12,3 +12,15 @@ deps: gx covertools
publish
:
gx-go rewrite
--undo
conformance
:
tmp/multiaddr
go build
-o
tmp/multiaddr/test/go-multiaddr ./multiaddr
cd
tmp/multiaddr/test
&&
MULTIADDR_BIN
=
"./go-multiaddr"
go
test
-v
tmp/multiaddr
:
mkdir
-p
tmp/
git clone https://github.com/multiformats/multiaddr tmp/multiaddr/
clean
:
rm
-rf
tmp/
.PHONY
:
gx covertools deps publish conformance clean
codecov.yml
0 → 100644
View file @
e1825f7b
ignore
:
-
"
multiaddr"
multiaddr/main.go
0 → 100644
View file @
e1825f7b
package
main
import
(
"encoding/hex"
"flag"
"fmt"
"os"
"strings"
maddr
"github.com/multiformats/go-multiaddr"
)
var
(
flagHelp
bool
)
func
main
()
{
flag
.
Usage
=
func
()
{
usage
:=
`usage: %s [options] ADDR
Print details about the given multiaddr.
Options:
`
fmt
.
Fprintf
(
os
.
Stderr
,
usage
,
os
.
Args
[
0
])
flag
.
PrintDefaults
()
}
flag
.
BoolVar
(
&
flagHelp
,
"h"
,
false
,
"display help message"
)
flag
.
Parse
()
if
flagHelp
||
len
(
flag
.
Args
())
==
0
{
flag
.
Usage
()
os
.
Exit
(
0
)
}
addrStr
:=
flag
.
Args
()[
0
]
var
addr
maddr
.
Multiaddr
var
err
error
if
strings
.
HasPrefix
(
addrStr
,
"0x"
)
{
addrBytes
,
err
:=
hex
.
DecodeString
(
addrStr
[
2
:
])
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"parse error: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
addr
,
err
=
maddr
.
NewMultiaddrBytes
(
addrBytes
)
}
else
{
addr
,
err
=
maddr
.
NewMultiaddr
(
addrStr
)
}
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"parse error: %s
\n
"
,
err
)
os
.
Exit
(
1
)
}
infoCommand
(
addr
)
}
func
infoCommand
(
addr
maddr
.
Multiaddr
)
{
var
compsJson
[]
string
maddr
.
ForEach
(
addr
,
func
(
comp
maddr
.
Component
)
bool
{
lengthPrefix
:=
""
if
comp
.
Protocol
()
.
Size
==
maddr
.
LengthPrefixedVarSize
{
lengthPrefix
=
"0x"
+
hex
.
EncodeToString
(
maddr
.
CodeToVarint
(
len
(
comp
.
RawValue
())))
}
compsJson
=
append
(
compsJson
,
`{`
+
fmt
.
Sprintf
(
`"string": "%s", `
,
comp
.
String
())
+
fmt
.
Sprintf
(
`"stringSize": "%d", `
,
len
(
comp
.
String
()))
+
fmt
.
Sprintf
(
`"packed": "0x%x", `
,
comp
.
Bytes
())
+
fmt
.
Sprintf
(
`"packedSize": "%d", `
,
len
(
comp
.
Bytes
()))
+
fmt
.
Sprintf
(
`"value": %#v, `
,
comp
.
Value
())
+
fmt
.
Sprintf
(
`"rawValue": "0x%x", `
,
comp
.
RawValue
())
+
fmt
.
Sprintf
(
`"valueSize": "%d", `
,
len
(
comp
.
RawValue
()))
+
fmt
.
Sprintf
(
`"protocol": "%s", `
,
comp
.
Protocol
()
.
Name
)
+
fmt
.
Sprintf
(
`"codec": "%d", `
,
comp
.
Protocol
()
.
Code
)
+
fmt
.
Sprintf
(
`"uvarint": "0x%x", `
,
comp
.
Protocol
()
.
VCode
)
+
fmt
.
Sprintf
(
`"lengthPrefix": "%s"`
,
lengthPrefix
)
+
`}`
)
return
true
})
addrJson
:=
`{
"string": "%[1]s",
"stringSize": "%[2]d",
"packed": "0x%[3]x",
"packedSize": "%[4]d",
"components": [
%[5]s
]
}`
fmt
.
Fprintf
(
os
.
Stdout
,
addrJson
+
"
\n
"
,
addr
.
String
(),
len
(
addr
.
String
()),
addr
.
Bytes
(),
len
(
addr
.
Bytes
()),
strings
.
Join
(
compsJson
,
",
\n
"
))
}
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