Skip to main content

Protocol

Struct Protocol 

Source
pub struct Protocol {
    pub channel_kinds: ChannelKinds,
    pub message_kinds: MessageKinds,
    pub component_kinds: ComponentKinds,
    pub resource_kinds: ResourceKinds,
    pub socket: SocketConfig,
    pub tick_interval: Duration,
    pub compression: Option<CompressionConfig>,
    pub client_authoritative_entities: bool,
    /* private fields */
}
Expand description

Builder and configuration container for a naia protocol definition.

Collects channels, messages, components, and transport settings before being locked and passed to a server or client.

Fields§

§channel_kinds: ChannelKinds

Registry of all channels registered in this protocol.

§message_kinds: MessageKinds

Registry of all message types registered in this protocol.

§component_kinds: ComponentKinds

Registry of all replicated component types registered in this protocol.

§resource_kinds: ResourceKinds

Marker table — which ComponentKinds are Replicated Resources. Receiver side checks this on SpawnWithComponents to populate its ResourceRegistry. See _AGENTS/RESOURCES_PLAN.md.

§socket: SocketConfig

Used to configure the underlying socket

§tick_interval: Duration

The duration between each tick

§compression: Option<CompressionConfig>

Configuration used to control compression parameters

§client_authoritative_entities: bool

Whether or not Client Authoritative Entities will be allowed

Implementations§

Source§

impl Protocol

Source

pub fn builder() -> Self

Returns a default Protocol ready for builder-style configuration.

Source

pub fn add_plugin<P: ProtocolPlugin>(&mut self, plugin: P) -> &mut Self

Applies plugin’s registrations to this protocol. Builder-style.

Sets the link conditioning configuration (artificial latency/loss). Builder-style.

Source

pub fn rtc_endpoint(&mut self, path: String) -> &mut Self

Sets the WebRTC signalling endpoint path. Builder-style.

Source

pub fn get_rtc_endpoint(&self) -> String

Returns the configured WebRTC signalling endpoint path.

Source

pub fn tick_interval(&mut self, duration: Duration) -> &mut Self

Sets the server tick interval. Builder-style.

Source

pub fn compression(&mut self, config: CompressionConfig) -> &mut Self

Enables packet compression with the given config. Builder-style.

Source

pub fn enable_client_authoritative_entities(&mut self) -> &mut Self

Enables client-authoritative entity mode, allowing clients to own and update replicated entities. Builder-style.

Source

pub fn add_default_channels(&mut self) -> &mut Self

Registers the six built-in default channels. Builder-style.

Source

pub fn add_channel<C: Channel>( &mut self, direction: ChannelDirection, mode: ChannelMode, ) -> &mut Self

Registers channel type C with the given direction and mode. Builder-style.

Source

pub fn add_channel_settings<C: Channel>( &mut self, settings: ChannelSettings, ) -> &mut Self

Register a channel with fully-specified ChannelSettings (including criticality). Use this when you need a non-default priority tier; otherwise add_channel is sufficient.

Source

pub fn add_message<M: Message>(&mut self) -> &mut Self

Registers message type M. Builder-style.

Source

pub fn add_request<Q: Request>(&mut self) -> &mut Self

Registers request type Q and its associated response type. Builder-style.

Source

pub fn add_component<C: Replicate>(&mut self) -> &mut Self

Registers replicated component type C. Builder-style.

Source

pub fn add_resource<R: Replicate>(&mut self) -> &mut Self

Register R as a Replicated Resource.

A Resource is internally a hidden 1-component entity carrying R as its sole replicated component. This call:

  1. Calls add_component::<R>() to allocate a normal ComponentKind
    • NetId for R (Resources reuse the component wire encoding).
  2. Records the ComponentKind in resource_kinds so the receiver side can recognize incoming SpawnWithComponents messages whose components are resources, and populate its ResourceRegistry.

Idempotent — registering the same type twice is a no-op (matches add_component re-registration semantics; the underlying tables dedupe on TypeId).

Source

pub fn lock(&mut self)

Freezes the protocol, computes and caches the protocol ID. Must be called before use.

Source

pub fn check_lock(&self)

Panics if the protocol has already been locked.

Source

pub fn build(&mut self) -> Self

Moves out of the builder and returns the owned Protocol.

Source

pub fn protocol_id(&self) -> ProtocolId

Returns the cached protocol ID. Panics if protocol is not locked.

Trait Implementations§

Source§

impl Clone for Protocol

Source§

fn clone(&self) -> Protocol

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Protocol

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V