API reference › @evolu/common › local‑first/Protocol › encodeDbChange

function encodeDbChange(buffer: Buffer, message: CrdtMessage): void;

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

Encodes a CrdtMessage as encodeAndEncryptDbChange does before padding and encryption.

Values are encoded as SQLite stores them, as the drivers' contract in NativeSqlite.ts states: a safe integer binds as INTEGER, so -0 is encoded as 0, and text binds as UTF-8, so a lone surrogate is encoded as U+FFFD, as encodeSqliteValue encodes it. A change thus encodes alike before and after it's stored, including one received from an earlier release, which sent it as written. Evolu.getMutationSize measures mutations with this encoding, so maxMutationSize limits exactly what every upload of a change encodes, and every change within it fits one protocol message.