Skip to main content

define_protocol

Macro define_protocol 

Source
macro_rules! define_protocol {
    (
        $(#[$meta:meta])*
        name: $name:ident,
        transport: $transport:expr,
        identify: |$data:ident| $body:expr
    ) => { ... };
}
Expand description

Macro to define a new protocol by implementing the RefractiumProtocol trait.

This macro simplifies the creation of simple protocols that identify themselves by checking if the initial data slice matches a specific condition.

ยงExample

use refractium::{define_protocol, types::Transport};

define_protocol!(
    /// My custom protocol identifier.
    name: MyProto,
    transport: Transport::Tcp,
    identify: |data| data.starts_with(b"MY_MAGIC")
);