Skip to content

feat(io): add a sans-io byte decoder - #59

Draft
evanlinjin wants to merge 2 commits into
bitcoindevkit:masterfrom
evanlinjin:dv/new-1
Draft

evanlinjin wants to merge 2 commits into
bitcoindevkit:masterfrom
evanlinjin:dv/new-1

Conversation

@evanlinjin

Copy link
Copy Markdown
Member

Adds io::Decoder, a sans-io decoder for Electrum's line-delimited JSON-RPC: feed(&[u8]) the bytes as they arrive, then iterate it for RawIncomings (a batch yields one per message). With io::encode for the other direction, a custom transport only has to move bytes instead of reimplementing line splitting and parsing.

ReadStreamer now uses Decoder, so there's one copy of the framing logic.

Breaking: io::blocking_write, io::async_write and io::tokio_write are removed. Each was just writer.write_all(&encode(msg)); call that instead.

Behaviour changes in ReadStreamer:

  • A reader that ends partway through a line now yields an UnexpectedEof error. It used to panic on assert_eq!(b, b'\n').
  • An invalid line yields an error, and the stream carries on with the next line instead of ending. Each message is one line, so the next one still parses; whether to stop or skip is the caller's call. The bundled clients still stop at the first error: if the bad line was a response, its request would never resolve.
  • Blank lines are skipped.

🤖 Generated with Claude Code

evanlinjin and others added 2 commits October 25, 2026 22:52
`io::Decoder` turns bytes into `RawIncoming`s with no reader attached,
and `io::encode` turns requests into bytes, so a custom transport only
moves bytes. `ReadStreamer` and the write helpers now use them.

`ReadStreamer` no longer panics when the reader ends partway through a
line: it yields an `UnexpectedEof` error. An invalid line yields an
error and decoding carries on with the next one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`blocking_write`, `async_write` and `tokio_write` were each
`writer.write_all(&encode(msg))`. The clients now call that directly,
and so can users.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.55%. Comparing base (8f480f9) to head (7cc4f65).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/io.rs 93.39% 4 Missing and 3 partials ⚠️
src/client.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
+ Coverage   48.33%   53.55%   +5.21%     
==========================================
  Files          11       11              
  Lines         902      943      +41     
  Branches       18       20       +2     
==========================================
+ Hits          436      505      +69     
+ Misses        461      433      -28     
  Partials        5        5              
Flag Coverage Δ
rust 53.55% <92.59%> (+5.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant