pub struct ProtocolCodec { /* private fields */ }Expand description
Codec that translates between wire-format messages and the unified internal
ClientMessage / ServerMessage types.
Implementations§
Source§impl ProtocolCodec
impl ProtocolCodec
Sourcepub const fn new(protocol: WsProtocol) -> Self
pub const fn new(protocol: WsProtocol) -> Self
Create a new codec for the given protocol.
Sourcepub const fn protocol(&self) -> WsProtocol
pub const fn protocol(&self) -> WsProtocol
The negotiated protocol.
Sourcepub fn decode(&self, raw: &str) -> Result<ClientMessage, ProtocolError>
pub fn decode(&self, raw: &str) -> Result<ClientMessage, ProtocolError>
Decode a raw JSON string from the WebSocket into a ClientMessage.
For graphql-transport-ws this is a passthrough deserialisation.
For the legacy graphql-ws protocol, message types are translated:
start→subscribestop→complete
§Errors
Returns a ProtocolError if the JSON is malformed.
Sourcepub fn encode(
&self,
msg: &ServerMessage,
) -> Result<Option<String>, ProtocolError>
pub fn encode( &self, msg: &ServerMessage, ) -> Result<Option<String>, ProtocolError>
Encode a ServerMessage to a JSON string for sending over the WebSocket.
For graphql-transport-ws this serialises directly.
For the legacy graphql-ws protocol, message types are translated:
next→dataping→ka(keepalive, no payload)pong→ dropped (legacy protocol has no pong)
Returns None for messages that should be suppressed (e.g. pong in legacy mode).
§Errors
Returns a ProtocolError if serialisation fails.
§Panics
Cannot panic in practice — the expect on wire_type is guarded
by an is_none() early-return immediately above.
Sourcepub fn uses_keepalive(&self) -> bool
pub fn uses_keepalive(&self) -> bool
Whether the protocol uses periodic keepalive (ka) messages
instead of ping/pong.
Auto Trait Implementations§
impl Freeze for ProtocolCodec
impl RefUnwindSafe for ProtocolCodec
impl Send for ProtocolCodec
impl Sync for ProtocolCodec
impl Unpin for ProtocolCodec
impl UnsafeUnpin for ProtocolCodec
impl UnwindSafe for ProtocolCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more