API reference › @evolu/common › local‑first/Protocol › ProtocolMessageBuffer
Defined in: packages/common/src/local-first/Protocol.ts:842
Mutable builder for constructing ProtocolMessage respecting size limits.
A frame never exceeds totalMaxSize. Make a write that may not fit inside
tryWrite, which keeps it only if the frame can still be closed; a write
known to fit, such as a closing write, can be made outside. Outside a trial,
addMessage and addRange assert that the frame fits totalMaxSize; they
do not check rangesMaxSize.
The builder references each change, which unwrap copies into the frame it
returns, so a change must not be modified while the builder is in use.
unwrap leaves the builder unchanged, so it can be called again.
Properties
addMessage
readonly addMessage: (message: EncryptedCrdtMessage) => void;
Defined in: packages/common/src/local-first/Protocol.ts:843
addRange
readonly addRange: (range:
| SkipRange
| FingerprintRange
| TimestampsRangeWithTimestampsBuffer) => void;
Defined in: packages/common/src/local-first/Protocol.ts:845
getSize
readonly getSize: () => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
Defined in: packages/common/src/local-first/Protocol.ts:869
Returns the exact encoded size of the frame.
tryWrite
readonly tryWrite: (write: () => void, reserve?: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">) => boolean;
Defined in: packages/common/src/local-first/Protocol.ts:864
Runs write and keeps what it wrote only if the frame can still be closed,
returning whether it was kept.
The frame can be closed when its exact size plus the bytes needed to append
one Fingerprint range with InfiniteUpperBound plus reserve is at
most totalMaxSize, and its ranges section plus the same bytes is at most
rangesMaxSize. Nothing is needed to close a broadcast, which holds no
ranges, or a frame whose last range has InfiniteUpperBound. Use reserve
for bytes the caller adds later, such as a range it is still collecting.
When the frame cannot be closed, or write throws, everything write
wrote is undone, so the frame is as if write never ran. Inside write,
addMessage and addRange do not assert the size limit.
unwrap
readonly unwrap: () => ProtocolMessage;
Defined in: packages/common/src/local-first/Protocol.ts:866