Skip to main content

Message

Trait Message 

Source
pub trait Message: Sized {
    const API_KEY: i16;
    const MIN_VERSION: i16;
    const MAX_VERSION: i16;

    // Required methods
    fn encode(
        &self,
        buf: &mut impl BufMut,
        version: i16,
    ) -> Result<(), EncodeError>;
    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError>;

    // Provided methods
    fn throttle_time_ms(&self) -> Option<i32> { ... }
    fn decode_with_limits(
        buf: &mut impl Buf,
        version: i16,
        limits: Limits,
    ) -> Result<Self, DecodeError> { ... }
}
Expand description

A versioned Kafka message: encode/decode plus its identity in the api-key registry.

Generated code implements this for every top-level message, but the trait is public because hand-written implementations are a reason it exists — a proxy with its own representation of a message can join the same dispatch loops. Anything added here later will come with a default body, so such an implementation does not break; Message::decode_with_limits was added exactly that way and its documentation records why.

Required Associated Constants§

Source

const API_KEY: i16

The api key identifying this message’s request type.

Source

const MIN_VERSION: i16

The lowest schema version this snapshot can speak.

Source

const MAX_VERSION: i16

The highest schema version this snapshot can speak.

Required Methods§

Source

fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError>

Source

fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError>

Decode one message of version.

Decoding costs O(fields), not O(payload bytes), but only when buf is a Bytes: payload fields (a fetch response’s records, and the keys and values inside them) are then refcounted slices of the caller’s buffer rather than copies. That comes from Bytes’s override of Buf::copy_to_bytes; other Buf implementations — slices, Cursor, Chain — get the default, which allocates and copies every payload, measured ~370x slower for a 1 MiB fetch response. Decode from a Bytes on any path that carries records. tests/zero_copy.rs holds the property to it.

Allocation is bounded by the default Limits, derived from buf’s remaining length; see Message::decode_with_limits.

Provided Methods§

Source

fn throttle_time_ms(&self) -> Option<i32>

Decode one message of version under limits.

Every generated message overrides this. The default is here so that adding it broke no hand-written implementation: it ignores limits and decodes under that type’s own default bound, which is never less safe than Message::decode. How long the broker wants this client to wait before sending more, or None for a message that has no such field.

Kafka’s quota mechanism is advisory in the only way that matters: the broker answers, sets this, and then stops reading from the connection for that long. A client that ignores it does not get faster — its next request simply sits unanswered until the mute expires, which is indistinguishable from a hung broker and will trip a request timeout instead of a backoff.

Generated for every message whose schema carries the field; defaulted here so that adding it broke no hand-written implementation, the way Message::decode_with_limits was.

Source

fn decode_with_limits( buf: &mut impl Buf, version: i16, limits: Limits, ) -> Result<Self, DecodeError>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Message for AddOffsetsToTxnRequest

Source§

impl Message for AddOffsetsToTxnResponse

Source§

impl Message for AddPartitionsToTxnRequest

Source§

impl Message for AddPartitionsToTxnResponse

Source§

impl Message for ApiVersionsRequest

Source§

impl Message for ApiVersionsResponse

Source§

impl Message for ConsumerGroupHeartbeatRequest

Source§

impl Message for ConsumerGroupHeartbeatResponse

Source§

impl Message for CreateTopicsRequest

Source§

impl Message for CreateTopicsResponse

Source§

impl Message for DeleteTopicsRequest

Source§

impl Message for DeleteTopicsResponse

Source§

impl Message for DescribeConfigsRequest

Source§

impl Message for DescribeConfigsResponse

Source§

impl Message for DescribeGroupsRequest

Source§

impl Message for DescribeGroupsResponse

Source§

impl Message for EndTxnRequest

Source§

impl Message for EndTxnResponse

Source§

impl Message for FetchRequest

Source§

impl Message for FetchResponse

Source§

impl Message for FindCoordinatorRequest

Source§

impl Message for FindCoordinatorResponse

Source§

impl Message for HeartbeatRequest

Source§

impl Message for HeartbeatResponse

Source§

impl Message for InitProducerIdRequest

Source§

impl Message for InitProducerIdResponse

Source§

impl Message for JoinGroupRequest

Source§

impl Message for JoinGroupResponse

Source§

impl Message for LeaveGroupRequest

Source§

impl Message for LeaveGroupResponse

Source§

impl Message for ListGroupsRequest

Source§

impl Message for ListGroupsResponse

Source§

impl Message for ListOffsetsRequest

Source§

impl Message for ListOffsetsResponse

Source§

impl Message for MetadataRequest

Source§

impl Message for MetadataResponse

Source§

impl Message for OffsetCommitRequest

Source§

impl Message for OffsetCommitResponse

Source§

impl Message for OffsetFetchRequest

Source§

impl Message for OffsetFetchResponse

Source§

impl Message for ProduceRequest

Source§

impl Message for ProduceResponse

Source§

impl Message for SaslAuthenticateRequest

Source§

impl Message for SaslAuthenticateResponse

Source§

impl Message for SaslHandshakeRequest

Source§

impl Message for SaslHandshakeResponse

Source§

impl Message for SyncGroupRequest

Source§

impl Message for SyncGroupResponse

Source§

impl Message for TxnOffsetCommitRequest

Source§

impl Message for TxnOffsetCommitResponse