6 Commits

Author SHA1 Message Date
Ivan FB
d59b6074bc
refactor(protobufutil): plain import of codec, exclude clashing symbol
Switch the brittle hand-maintained `from codec import <symbol-list>` to a
plain `import`, so adding a codec helper no longer means editing the list.
Use `except ProtobufError` because codec re-exports its own ProtobufError,
which would otherwise clash with our app-layer ./types/protobuf_error one.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 14:49:18 +02:00
Ivan FB
f3c1b118df
refactor(protobuf): skip fixed-width fields via skipValue (no alloc)
Addresses review feedback: skipping a field by reading its value
discards an allocated result. Use the codec's `skipValue`, which
advances the stream without materialising the value. (The previous
allocating length-delimited discard was already removed by the
parse-once change; this applies the same intent to the fixed32/64
skips that remain.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 17:18:41 +02:00
Ivan FB
9d13804ec1
perf(protobuf): parse the buffer once instead of rescanning per field
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>
2026-06-10 17:13:05 +02:00
Ivan FB
e2ec4d55b3
feat: replace nim-libp2p protobuf with nim-protobuf-serialization
libp2p was pulled in solely for its `minprotobuf` field codec, dragging
in its full transitive tree (secp256k1, nimcrypto, websock, etc.). Swap
it for nim-protobuf-serialization, whose low-level `codec` module gives
the same protobuf wire primitives without the networking stack.

The wire/snapshot codecs build messages by hand at the field level and
rely on a backward-compatible decode path the type-driven
`Protobuf.encode/decode` API cannot express. To keep that code intact,
`protobufutil.nim` is a thin `ProtoBuffer` shim over the new `codec`
module, preserving the exact field-level behaviour the codecs depend on
(plain varints, length-delimited bytes/strings with no UTF-8 validation,
unknown-wire-type fields skipped as protoc does).

Dependency closure (nimble.lock, nix/deps.nix) regenerated accordingly:
libp2p and its 8 exclusive transitive deps dropped, protobuf_serialization
and its npeg dependency added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 15:46:14 +02:00
Ivan FB
8ee857c908
generic refactor to make the code more aligned to logos-delivery style (#62)
* generic refactor to make the code more aligned to logos-delivery style
* use explicit return statement
2026-04-24 09:50:18 +02:00
Ivan FB
0dea35d364
feat: refactor to support building with Nimble (#52)
Changes include:

- Removing all submodules from vendor folder.
- Updating sds.nimble with required depndencies.
- Generating a nimble.lock file using Nimble.
- Updated Nim code to reference depndencies correctly.
- Added nix/deps.nix fixed output derivation that calls Nimble.
- Updated nixpkgs to use 25.11 commit which provides Nimbe 0.20.1.
- Disabled Nix Android builds on MacOS due to Nimble segfault.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2026-02-11 16:32:02 +01:00