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: ChannelKindsRegistry of all channels registered in this protocol.
message_kinds: MessageKindsRegistry of all message types registered in this protocol.
component_kinds: ComponentKindsRegistry of all replicated component types registered in this protocol.
resource_kinds: ResourceKindsMarker table — which ComponentKinds are Replicated Resources.
Receiver side checks this on SpawnWithComponents to populate
its ResourceRegistry. See _AGENTS/RESOURCES_PLAN.md.
socket: SocketConfigUsed to configure the underlying socket
tick_interval: DurationThe duration between each tick
compression: Option<CompressionConfig>Configuration used to control compression parameters
Whether or not Client Authoritative Entities will be allowed
Implementations§
Source§impl Protocol
impl Protocol
Sourcepub fn add_plugin<P: ProtocolPlugin>(&mut self, plugin: P) -> &mut Self
pub fn add_plugin<P: ProtocolPlugin>(&mut self, plugin: P) -> &mut Self
Applies plugin’s registrations to this protocol. Builder-style.
Sourcepub fn link_condition(&mut self, config: LinkConditionerConfig) -> &mut Self
pub fn link_condition(&mut self, config: LinkConditionerConfig) -> &mut Self
Sets the link conditioning configuration (artificial latency/loss). Builder-style.
Sourcepub fn rtc_endpoint(&mut self, path: String) -> &mut Self
pub fn rtc_endpoint(&mut self, path: String) -> &mut Self
Sets the WebRTC signalling endpoint path. Builder-style.
Sourcepub fn get_rtc_endpoint(&self) -> String
pub fn get_rtc_endpoint(&self) -> String
Returns the configured WebRTC signalling endpoint path.
Sourcepub fn tick_interval(&mut self, duration: Duration) -> &mut Self
pub fn tick_interval(&mut self, duration: Duration) -> &mut Self
Sets the server tick interval. Builder-style.
Sourcepub fn compression(&mut self, config: CompressionConfig) -> &mut Self
pub fn compression(&mut self, config: CompressionConfig) -> &mut Self
Enables packet compression with the given config. Builder-style.
Enables client-authoritative entity mode, allowing clients to own and update replicated entities. Builder-style.
Sourcepub fn add_default_channels(&mut self) -> &mut Self
pub fn add_default_channels(&mut self) -> &mut Self
Registers the six built-in default channels. Builder-style.
Sourcepub fn add_channel<C: Channel>(
&mut self,
direction: ChannelDirection,
mode: ChannelMode,
) -> &mut Self
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.
Sourcepub fn add_channel_settings<C: Channel>(
&mut self,
settings: ChannelSettings,
) -> &mut Self
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.
Sourcepub fn add_message<M: Message>(&mut self) -> &mut Self
pub fn add_message<M: Message>(&mut self) -> &mut Self
Registers message type M. Builder-style.
Sourcepub fn add_request<Q: Request>(&mut self) -> &mut Self
pub fn add_request<Q: Request>(&mut self) -> &mut Self
Registers request type Q and its associated response type. Builder-style.
Sourcepub fn add_component<C: Replicate>(&mut self) -> &mut Self
pub fn add_component<C: Replicate>(&mut self) -> &mut Self
Registers replicated component type C. Builder-style.
Sourcepub fn add_resource<R: Replicate>(&mut self) -> &mut Self
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:
- Calls
add_component::<R>()to allocate a normalComponentKind- NetId for
R(Resources reuse the component wire encoding).
- NetId for
- Records the
ComponentKindinresource_kindsso the receiver side can recognize incoming SpawnWithComponents messages whose components are resources, and populate itsResourceRegistry.
Idempotent — registering the same type twice is a no-op (matches
add_component re-registration semantics; the underlying tables
dedupe on TypeId).
Sourcepub fn lock(&mut self)
pub fn lock(&mut self)
Freezes the protocol, computes and caches the protocol ID. Must be called before use.
Sourcepub fn check_lock(&self)
pub fn check_lock(&self)
Panics if the protocol has already been locked.
Sourcepub fn protocol_id(&self) -> ProtocolId
pub fn protocol_id(&self) -> ProtocolId
Returns the cached protocol ID. Panics if protocol is not locked.