pub struct MessageContainer { /* private fields */ }Expand description
A reference-counted wrapper around a heap-allocated Message trait object.
§Why Arc<Box<dyn Message>>?
broadcast_message and room_broadcast_message send the same logical
message to every connected user. With a plain Box<dyn Message> this
required one clone_box() call (heap allocation + copy) per user. At
1,262 CCU that is 1,262 allocations per broadcast tick.
Wrapping in Arc makes clone() a single atomic refcount increment
regardless of how many users share the message. Each connection still
serialises the message independently through its own entity converter —
the shared data is immutable (only &self methods called on the send path).
to_boxed_any (receive path only) extracts the inner Box<dyn Message>
via Arc::try_unwrap; in the rare case the Arc is still shared it falls
back to clone_box(), preserving correctness without unsafe code.
Implementations§
Source§impl MessageContainer
impl MessageContainer
Sourcepub fn new(message: Box<dyn Message>) -> Self
pub fn new(message: Box<dyn Message>) -> Self
Wraps message in an Arc so it can be cheaply shared across broadcast targets.
Sourcepub fn bit_length(
&self,
message_kinds: &MessageKinds,
converter: &mut dyn LocalEntityAndGlobalEntityConverterMut,
) -> u32
pub fn bit_length( &self, message_kinds: &MessageKinds, converter: &mut dyn LocalEntityAndGlobalEntityConverterMut, ) -> u32
Returns the serialized bit length of this message given converter for entity references.
Sourcepub fn write(
&self,
message_kinds: &MessageKinds,
writer: &mut dyn BitWrite,
converter: &mut dyn LocalEntityAndGlobalEntityConverterMut,
)
pub fn write( &self, message_kinds: &MessageKinds, writer: &mut dyn BitWrite, converter: &mut dyn LocalEntityAndGlobalEntityConverterMut, )
Writes the message’s kind tag and payload bits into writer.
Sourcepub fn is_fragment(&self) -> bool
pub fn is_fragment(&self) -> bool
Returns true if this message is a fragment of a larger logical message.
Sourcepub fn is_request_or_response(&self) -> bool
pub fn is_request_or_response(&self) -> bool
Returns true if this message envelope carries a request or response (not a plain message).
Sourcepub fn to_boxed_any(self) -> Box<dyn Any>
pub fn to_boxed_any(self) -> Box<dyn Any>
Converts this container into a Box<dyn Any> for downcasting to the concrete message type.
Sourcepub fn kind(&self) -> MessageKind
pub fn kind(&self) -> MessageKind
Returns the MessageKind identifying the concrete message type inside this container.
Sourcepub fn relations_waiting(&self) -> Option<HashSet<RemoteEntity>>
pub fn relations_waiting(&self) -> Option<HashSet<RemoteEntity>>
Returns the set of remote entities this message is still waiting on, or None if ready.
Sourcepub fn relations_complete(
&mut self,
converter: &dyn LocalEntityAndGlobalEntityConverter,
)
pub fn relations_complete( &mut self, converter: &dyn LocalEntityAndGlobalEntityConverter, )
Notifies the inner message that all awaited entity relations have been resolved.
Trait Implementations§
Source§impl Clone for MessageContainer
impl Clone for MessageContainer
Source§fn clone(&self) -> MessageContainer
fn clone(&self) -> MessageContainer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more