pub trait Message: Sized {
// Required methods
fn message_length(&self) -> usize;
fn encode_body(&self, buf: &mut BytesMut) -> PgWireResult<()>;
fn decode_body(
buf: &mut BytesMut,
full_len: usize,
_ctx: &DecodeContext,
) -> PgWireResult<Self>;
// Provided methods
fn message_type() -> Option<u8> { ... }
fn max_message_length() -> usize { ... }
fn encode(&self, buf: &mut BytesMut) -> PgWireResult<()> { ... }
fn decode(
buf: &mut BytesMut,
ctx: &DecodeContext,
) -> PgWireResult<Option<Self>> { ... }
}Expand description
Define how message encode and decoded.
Required Methods§
Sourcefn message_length(&self) -> usize
fn message_length(&self) -> usize
Return the length of the message, including the length integer itself.
Sourcefn encode_body(&self, buf: &mut BytesMut) -> PgWireResult<()>
fn encode_body(&self, buf: &mut BytesMut) -> PgWireResult<()>
Encode body part of the message.
Sourcefn decode_body(
buf: &mut BytesMut,
full_len: usize,
_ctx: &DecodeContext,
) -> PgWireResult<Self>
fn decode_body( buf: &mut BytesMut, full_len: usize, _ctx: &DecodeContext, ) -> PgWireResult<Self>
Decode body part of the message.
Provided Methods§
Sourcefn message_type() -> Option<u8>
fn message_type() -> Option<u8>
Return the type code of the message. In order to maintain backward
compatibility, Startup has no message type.
Sourcefn max_message_length() -> usize
fn max_message_length() -> usize
Return the max length of message in this type.
This is to validate the length field in decode
Sourcefn encode(&self, buf: &mut BytesMut) -> PgWireResult<()>
fn encode(&self, buf: &mut BytesMut) -> PgWireResult<()>
Default implementation for encoding message.
Message type and length are encoded in this implementation and it calls
encode_body for remaining parts.
Sourcefn decode(buf: &mut BytesMut, ctx: &DecodeContext) -> PgWireResult<Option<Self>>
fn decode(buf: &mut BytesMut, ctx: &DecodeContext) -> PgWireResult<Option<Self>>
Default implementation for decoding message.
Message type and length are decoded in this implementation and it calls
decode_body for remaining parts. Return None if the packet is not
complete for parsing.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.