Trait ockam_multiaddr::Protocol

source ·
pub trait Protocol<'a>: Sized {
    const CODE: Code;
    const PREFIX: &'static str;

    // Required methods
    fn read_str(input: Checked<&'a str>) -> Result<Self, Error>;
    fn write_str(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
    fn read_bytes(input: Checked<&'a [u8]>) -> Result<Self, Error>;
    fn write_bytes(&self, buf: &mut dyn Buffer);
}
Expand description

Component of a MultiAddr.

A protocol supports a textual and a binary representation.

Protocol <- Text / Binary
Text     <- '/' Prefix '/' Char+
Prefix   <- Char+
Binary   <- Code Byte+
Code     <- UnsignedVarint

To process a protocol, one needs to know the code and prefix as they determine the protocol value.

NB: Protocol values which contain ’/’s create ambiguity in the textual representation. These so called “path protocols” must be the last protocol component in a multi-address.

Required Associated Constants§

source

const CODE: Code

Registered protocol code.

source

const PREFIX: &'static str

Registered protocol prefix.

Required Methods§

source

fn read_str(input: Checked<&'a str>) -> Result<Self, Error>

Parse the string value of this protocol.

source

fn write_str(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Write the protocol as a string, including the prefix.

source

fn read_bytes(input: Checked<&'a [u8]>) -> Result<Self, Error>

Decode the binary value of this protocol.

source

fn write_bytes(&self, buf: &mut dyn Buffer)

Write the protocol as a binary value, including the code.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Protocol<'_> for Ip4

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "ip4"

source§

impl Protocol<'_> for Ip6

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "ip6"

source§

impl Protocol<'_> for Tcp

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "tcp"

source§

impl<'a> Protocol<'a> for DnsAddr<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "dnsaddr"

source§

impl<'a> Protocol<'a> for Node<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "node"

source§

impl<'a> Protocol<'a> for Project<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "project"

source§

impl<'a> Protocol<'a> for Secure<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "secure"

source§

impl<'a> Protocol<'a> for Service<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "service"

source§

impl<'a> Protocol<'a> for Space<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "space"

source§

impl<'a> Protocol<'a> for Worker<'a>

source§

const CODE: Code = _

source§

const PREFIX: &'static str = "worker"