make cast use NewMultiaddrBytes

This will perform all the correct checks *except* that it won't bother actually
stringifying the multiaddr. It should be significantly faster.
This commit is contained in:
Steven Allen 2018-10-01 15:47:59 -07:00
parent 6c70a3d7b5
commit 2e9c819c18

View File

@ -44,11 +44,11 @@ func Join(ms ...Multiaddr) Multiaddr {
// Cast re-casts a byte slice as a multiaddr. will panic if it fails to parse.
func Cast(b []byte) Multiaddr {
_, err := bytesToString(b)
m, err := NewMultiaddrBytes(b)
if err != nil {
panic(fmt.Errorf("multiaddr failed to parse: %s", err))
}
return multiaddr{bytes: b}
return m
}
// StringCast like Cast, but parses a string. Will also panic if it fails to parse.