spetz commented on code in PR #1679: URL: https://github.com/apache/iggy/pull/1679#discussion_r2050994383
########## sdk/src/models/messaging/message.rs: ########## @@ -0,0 +1,625 @@ +/* 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. + */ + +use super::message_header::{IggyMessageHeader, IGGY_MESSAGE_HEADER_SIZE}; +use super::user_headers::get_user_headers_size; +use crate::bytes_serializable::BytesSerializable; +use crate::error::IggyError; +use crate::models::messaging::user_headers::{HeaderKey, HeaderValue}; +use crate::utils::byte_size::IggyByteSize; +use crate::utils::sizeable::Sizeable; +use crate::utils::timestamp::IggyTimestamp; +use bon::bon; +use bytes::{BufMut, Bytes, BytesMut}; +use serde::{Deserialize, Serialize}; +use serde_with::base64::Base64; +use serde_with::serde_as; +use std::collections::HashMap; +use std::convert::TryFrom; +use std::str::FromStr; +use tracing::warn; + +/// Maximum allowed size in bytes for a message payload. +/// +/// This constant defines the upper limit for the size of an `IggyMessage` payload. +/// Attempting to create a message with a payload larger than this value will result +/// in an `IggyError::InvalidMessagePayloadLength` error. +/// +/// # Constraints +/// +/// * Minimum payload size: 1 byte (empty payloads are not allowed) +/// * Maximum payload size: 10 MB +/// +pub const MAX_PAYLOAD_SIZE: u32 = 10 * 1000 * 1000; + +/// Maximum allowed size in bytes for user-defined headers. +/// +/// This constant defines the upper limit for the combined size of all user headers +/// in an `IggyMessage`. Attempting to create a message with user headers larger +/// than this value will result in an `IggyError::TooBigUserHeaders` error. +/// +/// # Constraints +/// +/// * Maximum headers size: 100 KB +/// * Each individual header key is limited to 255 bytes +/// * Each individual header value is limited to 255 bytes +/// +pub const MAX_USER_HEADERS_SIZE: u32 = 100 * 1000; + +/// A message stored in the Iggy messaging system. +/// +/// `IggyMessage` represents a single message that can be sent to or received from +/// a stream. Each message consists of: +/// * A header with message metadata +/// * A payload (the actual content) +/// * Optional user-defined headers for additional context +/// +/// # Examples +/// +/// ``` +/// use iggy::prelude::*; +/// use std::str::FromStr; +/// use std::collections::HashMap; +/// use bytes::Bytes; +/// +/// // Create a simple text message +/// let message = IggyMessage::builder() +/// .payload("Hello world!".into()) +/// .build() +/// .unwrap(); +/// +/// // Create a simple message with raw binary payload +/// let message = IggyMessage::builder() +/// .payload(Bytes::from(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9])) +/// .build() +/// .unwrap(); +/// +/// // Create a message with custom ID +/// let message = IggyMessage::builder() +/// .id(42) +/// .payload("Custom message".into()) +/// .build() +/// .unwrap(); +/// +/// // Create a message with headers +/// let key = HeaderKey::from_str("content-type").unwrap(); +/// let value = HeaderValue::from_str("text/plain").unwrap(); +/// let user_headers = HashMap::from([(key, value)]); +/// +/// let message = IggyMessage::builder() +/// .payload("Message with metadata".into()) +/// .user_headers(user_headers) +/// .build() +/// .unwrap(); +/// ``` +#[serde_as] +#[derive(Debug, Serialize, Deserialize, PartialEq)] +pub struct IggyMessage { + /// Message metadata + pub header: IggyMessageHeader, Review Comment: Should we call this `header` or `metadata` or even something else? At least based on the doc comment. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
