mirror of
https://github.com/logos-messaging/nim-sds.git
synced 2026-07-02 22:10:13 +00:00
Addresses review feedback on PR #77: `getField` rescanned the whole buffer on every call, giving O(fields × len) decode. Parse the message once at `ProtoBuffer.init(data)` in a single forward pass with the library's reader, indexing values by field number; the accessors are then plain lookups (last-wins / repeated semantics fall out of wire order). Public API and wire behaviour are unchanged. The full type-driven `Protobuf.encode/decode` API is intentionally not used here: it cannot express the backward-compatible causal-history decode (field 3 is repeated HistoryEntry now, repeated bare-string IDs in legacy messages), and its default-value omission would drop the always-written empty fields the strict decoder requires (e.g. empty `content` on sync messages), breaking compatibility with peers on the current wire format. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>