Documentation ¶
Index ¶
- Constants
- Variables
- func AddProtocol(p Protocol) error
- func ForEach(m Multiprotocol, cb func(c Component) bool)
- func Init(path string) error
- type Component
- func (c *Component) Bytes() []byte
- func (c *Component) Equal(o Multiprotocol) bool
- func (c *Component) MarshalBinary() ([]byte, error)
- func (c *Component) MarshalJSON() ([]byte, error)
- func (c *Component) MarshalText() ([]byte, error)
- func (c *Component) Protocol() Protocol
- func (c *Component) Protocols() []Protocol
- func (c *Component) RawValue() []byte
- func (c *Component) String() string
- func (c *Component) UnmarshalBinary(data []byte) error
- func (c *Component) UnmarshalJSON(data []byte) error
- func (c *Component) UnmarshalText(data []byte) error
- func (c *Component) Value() string
- func (c *Component) ValueForProtocol(code int) (string, error)
- type Multiprotocol
- type Protocol
Constants ¶
const (
LengthPrefixedVarSize = -1
)
These are special sizes
Variables ¶
var ErrProtocolNotFound = fmt.Errorf("protocol not found in multiprotocol")
var Protocols = []Protocol{}
Protocols is the list of multiprotocol protocols supported by this module.
Functions ¶
func AddProtocol ¶
func ForEach ¶
func ForEach(m Multiprotocol, cb func(c Component) bool)
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
func NewComponent ¶
NewComponent constructs a new multiprotocol component
func (*Component) Equal ¶
func (c *Component) Equal(o Multiprotocol) bool
func (*Component) MarshalBinary ¶
func (*Component) MarshalJSON ¶
func (*Component) MarshalText ¶
func (*Component) UnmarshalBinary ¶
func (*Component) UnmarshalJSON ¶
func (*Component) UnmarshalText ¶
type Multiprotocol ¶
type Multiprotocol interface { json.Marshaler json.Unmarshaler encoding.TextMarshaler encoding.TextUnmarshaler encoding.BinaryMarshaler encoding.BinaryUnmarshaler // Equal returns whether two Multiprotocols are exactly equal Equal(Multiprotocol) bool // Bytes returns the []byte representation of this Multiprotocol // // This function may expose immutable, internal state. Do not modify. Bytes() []byte // String returns the string representation of this Multiprotocol // (may panic if internal state is corrupted) String() string // Protocols returns the list of Protocols this Multiprotocol includes // will panic if protocol code incorrect (and bytes accessed incorrectly) Protocols() []Protocol // ValueForProtocol returns the value (if any) following the specified protocol // // Note: protocols can appear multiple times in a single multiprotocol. // Consider using `ForEach` to walk over the addr manually. ValueForProtocol(code int) (string, error) }
Multiprotocol is a cross-protocol, cross-platform format for representing self-describing protocol identifiers. Learn more here: https://github.com/vacp2p/multiprotocol
Multiprotocol have both a binary and string representation.
import mp "github.com/vacp2p/go-multiprotocol" proto, err := mp.NewMultiprotocol("/vac/waku/2") // err non-nil when parsing failed.
func NewMultiprotocol ¶
func NewMultiprotocol(s string) (p Multiprotocol, err error)
NewMultiprotocol parses and validates an input string, returning a *Multiprotocol
func NewMultiprotocolBytes ¶
func NewMultiprotocolBytes(b []byte) (a Multiprotocol, err error)
NewMultiprotocolBytes initializes a Multiprotocol from a byte representation. It validates it as an input string.
type Protocol ¶
type Protocol struct { // Name is the string representation of the protocol code. E.g., ip4, // ip6, tcp, udp, etc. Name string // Code is the protocol's multicodec (a normal, non-varint number). Code int // VCode is a precomputed varint encoded version of Code. VCode []byte // Size is the size of the argument to this protocol. // // * Size == 0 means this protocol takes no argument. // * Size > 0 means this protocol takes a constant sized argument. // * Size < 0 means this protocol takes a variable length, varint // prefixed argument. Size int // a size of -1 indicates a length-prefixed variable size // Transcoder converts between the byte representation and the string // representation of this protocol's argument (if any). // // This should only be non-nil if Size != 0 Transcoder multiaddr.Transcoder }
Protocol is a protocol description structure. This was taken from Multiaddr
func ProtocolWithCode ¶
ProtocolWithCode returns the Protocol description with given protocol code.
func ProtocolWithName ¶
ProtocolWithName returns the Protocol description with given string name.
func ProtocolsWithString ¶
ProtocolsWithString returns a slice of protocols matching given string.