blob: 49a85d6b7c47f8a8df0ce30aa8213539ed0716ae [file]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//! Wire protocol types and codec for the Iggy binary protocol.
//!
//! This crate is the single source of truth for the binary wire format
//! shared between the Iggy server and SDK. It is a pure codec - no I/O,
//! no async, no runtime dependencies.
//!
//! # Design
//!
//! Protocol types are independent from domain types.
//! Conversion between wire types and domain types happens at the boundary
//! (SDK client impls, server handlers).
//!
//! # Wire frame format
//!
//! **Request** (client -> server):
//! ```text
//! [length:4 bytes, u32 LE][code:4 bytes, u32 LE][payload:N bytes]
//! ```
//!
//! **Response** (server -> client):
//! ```text
//! [status:4 bytes, u32 LE][length:4 bytes, u32 LE][payload:N bytes]
//! ```
//!
//! All multi-byte integers are little-endian. Strings are length-prefixed
//! (u8 length for names, u32 length for longer strings).
//!
//! # VSR consensus framing
//!
//! All consensus headers are 256 bytes with `#[repr(C)]` layout.
//! Deserialization is zero-copy via `bytemuck`. Runtime message wrappers
//! (`Message`, `MessageBag`, backings) live in `server_common`; this crate
//! exposes only the wire-level header types.
//!
//! - Client-facing: [`RequestHeader`], [`ReplyHeader`]
//! - Replication: [`PrepareHeader`], [`PrepareOkHeader`], [`CommitHeader`]
//! - View change: [`StartViewChangeHeader`], [`DoViewChangeHeader`],
//! [`StartViewHeader`]
//! - Dispatch: [`GenericHeader`] for type-erased initial parsing
pub mod batch;
pub mod codec;
pub mod codes;
pub mod consensus;
pub mod dispatch;
pub mod error;
pub mod framing;
pub mod namespace;
pub mod placement;
pub mod primitives;
pub mod requests;
pub mod responses;
pub mod version;
pub use codec::{WireDecode, WireEncode};
pub use consensus::{
CHECKSUM_UNSEALED, COMMIT_BATCH_ENTRIES_MAX, COMMIT_BATCH_FRAME_MAX,
COMMIT_REPLY_BATCH_ENTRIES_MAX, Command, CommitEntry, CommitHeader, CommitReplyEntry,
CommitReplyHeader, ConsensusError, ConsensusHeader, ConsumerSession,
ConsumerSessionHeartbeatHeader, DVC_HEADERS_MAX, DoViewChangeHeader, EvictionHeader,
EvictionReason, ForwardCompletionHeader, ForwardLogoutHeader, ForwardLogoutOutcome,
ForwardLogoutResultHeader, ForwardRegisterHeader, ForwardRegisterOutcome,
ForwardRegisterResultHeader, GenericHeader, HEADER_SIZE, HeartbeatState,
LIFECYCLE_BATCH_HEADER_SIZE, LIFECYCLE_COMPLETION_SIZE, LIFECYCLE_COMPLETIONS_MAX,
MAX_CONSUMER_SESSIONS_PER_HEARTBEAT, Operation, PrepareHeader, PrepareOkHeader,
PrepareProgressHeader, PrimaryRebalanceHeader, PrimaryRebalanceKind, REJECTION_SECTION_LEN,
RESERVED_COMMAND_LEN, RepairPrepareHeader, RepairRangeReplyHeader, ReplyHeader, RequestHeader,
RequestPreparesHeader, RequestStartViewHeader, RequestStateChunkHeader,
RequestStateTransferHeader, RoutedRequestHeader, SIZE_FIELD_OFFSET, SegmentDeleteHeader,
SegmentDeleteKind, StartViewChangeHeader, StartViewHeader, StateChunkHeader,
StateTransferTargetHeader, batch_entries, batch_frame_size, frame_body, frame_checksum_bytes,
prepare_identity_checksum_bytes, read_size_field, result_code, result_section_len,
write_rejection_section,
};
pub use dispatch::{
COMMAND_TABLE, CommandMeta, command_index, lookup_by_operation, lookup_command,
};
pub use error::WireError;
pub use framing::{RequestFrame, ResponseFrame, STATUS_OK};
pub use primitives::ack_level::AckLevel;
pub use primitives::consumer::{
KIND_CONSUMER, KIND_CONSUMER_GROUP, KIND_EXTERNAL_GROUP, WireConsumer,
};
pub use primitives::identifier::{MAX_WIRE_NAME_LENGTH, WireIdentifier, WireName};
pub use primitives::options::{MAX_OPTIONS, MAX_OPTIONS_BYTES, WireOptions, validate_options};
pub use primitives::partition_assignment::CreatedPartitionAssignment;
pub use primitives::partition_history::{ConsumerGroupOwner, PartitionContext};
pub use primitives::partitioning::{MAX_MESSAGES_KEY_LENGTH, WirePartitioning};
pub use primitives::permissions::{
WireGlobalPermissions, WirePermissions, WireStreamPermissions, WireTopicPermissions,
};
pub use primitives::polling_strategy::WirePollingStrategy;
pub use primitives::user_headers::{
WireHeaderKind, WireUserHeaderEntry, WireUserHeaderIterator, WireUserHeaders,
encode_user_headers, user_headers_encoded_size, validate_user_headers,
};
pub use version::{
ClientVersionInfo, IGGY_PROTOCOL_VERSION, IGGY_PROTOCOL_VERSION_MIN, ProtocolVersion,
REPLICA_WIRE_REVISION, is_protocol_compatible,
};
/// Maximum number of partitions allowed in a single create/delete request.
pub const MAX_PARTITIONS_PER_REQUEST: u32 = 1000;
/// The largest payload of one message.
pub const MAX_MESSAGE_PAYLOAD_SIZE: usize = 64 * 1000 * 1000;
/// The largest user headers of one message.
pub const MAX_MESSAGE_USER_HEADERS_SIZE: usize = 100 * 1000;
/// The largest record of one message in a read reply, with its batch and message headers. A
/// read returns a first record up to this size even above its `max_bytes`, so every client
/// reply cap holds it.
pub const MAX_RECORD_SIZE: usize = batch::BATCH_HEADER_SIZE
+ batch::BATCH_MESSAGE_HEADER_SIZE
+ MAX_MESSAGE_PAYLOAD_SIZE
+ MAX_MESSAGE_USER_HEADERS_SIZE;
/// The largest frame of a read reply that holds one record of [`MAX_RECORD_SIZE`]: the frame
/// header, the largest fetch table and the record. A poll reply has a smaller head.
pub const MAX_RECORD_REPLY_SIZE: usize = consensus::HEADER_SIZE
+ responses::messages::FetchMessagesResponse::head_size(MAX_PARTITIONS_PER_REQUEST as usize)
+ MAX_RECORD_SIZE;