import { type Headers } from './header.utils.js'; import { type Id } from '../identifier.utils.js'; import { type Partitioning } from './partitioning.utils.js'; /** Valid types for message ID: numeric, bigint, or UUID string */ export type MessageIdKind = number | bigint | string; /** * Message creation parameters. */ export type CreateMessage = { /** Optional message ID (auto-generated if not provided) */ id?: MessageIdKind; /** Optional user-defined headers */ headers?: Headers; /** Message payload as string or Buffer */ payload: string | Buffer; /** Optional origin timestamp in microseconds (defaults to send time) */ originTimestamp?: bigint; }; /** * A message prepared for batch encoding. */ export type MessageToEncode = { /** Message ID as a 16-byte little-endian buffer */ id: Buffer; /** Message payload */ payload: Buffer; /** Serialized user headers */ userHeaders: Buffer; /** Origin timestamp in microseconds */ originTimestamp: bigint; }; /** * Type guard to check if a value is a valid message ID. * * @param x - Value to check * @returns True if the value is a valid MessageIdKind */ export declare const isValidMessageId: (x?: unknown) => x is MessageIdKind; /** * Serializes a message ID to a 16-byte little-endian buffer. * Supports undefined (zero), numeric, bigint, and UUID string formats. * * @param id - Message ID to serialize * @returns 16-byte buffer containing the serialized ID * @throws Error if the ID format is invalid */ export declare const serializeMessageId: (id?: unknown) => Buffer; /** * Mints a random 16-byte message ID from the pool, refilling when drained. * * @returns 16-byte buffer of random bytes owned by the caller */ export declare const mintMessageId: () => Buffer; /** * Resolves a message ID to a 16-byte little-endian buffer, minting a random * one when the ID is absent or zero. * * @param id - Optional message ID * @returns 16-byte little-endian buffer containing a non-zero ID */ export declare const resolveMessageId: (id?: MessageIdKind) => Buffer; /** * Encodes messages into the canonical batch format. * Format: [batch header][frames], one frame per message. * * @param messages - Messages to encode * @returns Serialized batch buffer * @throws Error if the batch is empty */ export declare const encodeMessagesBatch: (messages: MessageToEncode[]) => Buffer; /** * Serializes a send messages command payload. * Format: [metadata length][stream id][topic id][partitioning] * [messages count][batch]. * * @param streamId - Stream identifier * @param topicId - Topic identifier * @param messages - Array of messages to send * @param partitioning - Optional partitioning strategy * @returns Serialized command payload * @throws Error if the message array is empty */ export declare const serializeSendMessages: (streamId: Id, topicId: Id, messages: CreateMessage[], partitioning?: Partitioning) => Buffer; /** * Serializes a flush unsaved buffers command payload. * * @param streamId - Stream identifier * @param topicId - Topic identifier * @param partitionId - Partition ID to flush * @param fsync - Whether to force sync to disk * @returns Serialized command payload */ export declare const serializeFlushUnsavedBuffers: (streamId: Id, topicId: Id, partitionId: number, fsync?: boolean) => Buffer; //# sourceMappingURL=message.utils.d.ts.map