API reference@evolu/commonlocal‑first/Protocol › createProtocolBroadcastMessagesFromCrdtMessages

function createProtocolBroadcastMessagesFromCrdtMessages(
  deps: RandomBytesDep,
): (
  owner: Owner,
  messages: readonly [CrdtMessage, CrdtMessage],
  maxSize: number &
    Brand<"NonNaN"> &
    Brand<"Finite"> &
    Brand<"Int"> &
    Brand<"Between1000000-100000000">,
) => readonly [ProtocolMessage, ProtocolMessage];

Defined in: packages/common/src/local-first/Protocol.ts:604

Creates size-limited broadcast ProtocolMessages containing every supplied CrdtMessage.

Broadcasts contain no synchronization ranges or write key. Unlike createProtocolMessageFromCrdtMessages, this function splits all messages into complete frames rather than relying on later synchronization rounds to deliver messages that do not fit. Each individual message must fit the configured size limit.

Example

import {
  assertSame,
  createId,
  getOrThrow,
  testCreateDeps,
} from "@evolu/common";
import {
  createProtocolBroadcastMessagesFromCrdtMessages,
  MessageType,
  parseProtocolHeader,
  testAppOwner,
  testCreateCrdtMessage,
} from "@evolu/common/local-first";

const deps = testCreateDeps();
const broadcasts = createProtocolBroadcastMessagesFromCrdtMessages(deps)(
  testAppOwner,
  [testCreateCrdtMessage(createId(deps), 1, "Ada")],
);
assertSame(broadcasts.length, 1);
assertSame(
  getOrThrow(parseProtocolHeader(broadcasts[0])).messageType,
  MessageType.Broadcast,
);