interface.go 1.43 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3 4 5
package multiaddr

/*
Multiaddr is a cross-protocol, cross-platform format for representing
internet addresses. It emphasizes explicitness and self-description.
6
Learn more here: https://github.com/multiformats/multiaddr
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
7 8 9

Multiaddrs have both a binary and string representation.

Lars Gierth's avatar
Lars Gierth committed
10
    import ma "github.com/multiformats/go-multiaddr"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
11 12 13 14 15 16 17 18 19 20

    addr, err := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/80")
    // err non-nil when parsing failed.

*/
type Multiaddr interface {
	// Equal returns whether two Multiaddrs are exactly equal
	Equal(Multiaddr) bool

	// Bytes returns the []byte representation of this Multiaddr
21 22
	//
	// This function may expose immutable, internal state. Do not modify.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
23 24 25 26 27 28 29 30
	Bytes() []byte

	// String returns the string representation of this Multiaddr
	// (may panic if internal state is corrupted)
	String() string

	// Protocols returns the list of Protocols this Multiaddr includes
	// will panic if protocol code incorrect (and bytes accessed incorrectly)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
31
	Protocols() []Protocol
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
32 33 34 35 36 37 38 39 40 41 42 43

	// Encapsulate wraps this Multiaddr around another. For example:
	//
	//      /ip4/1.2.3.4 encapsulate /tcp/80 = /ip4/1.2.3.4/tcp/80
	//
	Encapsulate(Multiaddr) Multiaddr

	// Decapsultate removes a Multiaddr wrapping. For example:
	//
	//      /ip4/1.2.3.4/tcp/80 decapsulate /ip4/1.2.3.4 = /tcp/80
	//
	Decapsulate(Multiaddr) Multiaddr
44 45 46

	// ValueForProtocol returns the value (if any) following the specified protocol
	ValueForProtocol(code int) (string, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
47
}