Skip to content

*: extract PacketAssembler for frame-to-packet assembly#43

Open
shubhamdhama wants to merge 6 commits intostream-multiplexingfrom
shubham/extract-out-assembly
Open

*: extract PacketAssembler for frame-to-packet assembly#43
shubhamdhama wants to merge 6 commits intostream-multiplexingfrom
shubham/extract-out-assembly

Conversation

@shubhamdhama
Copy link
Copy Markdown

@shubhamdhama shubhamdhama commented Mar 26, 2026

Extract the frame assembly logic from Stream.HandleFrame into a
reusable PacketAssembler type in drpcwire. Both the stream and the
manager now use their own PacketAssembler instance, keeping assembly
logic in one place.

The manager's assembler handles the invoke sequence (metadata +
invoke), which removes the restriction that only KindMessage packets
could be split across frames. This also simplifies NewServerStream
from a packet-at-a-time loop into a single receive.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors wire handling to separate frame parsing from frame-to-packet assembly by introducing a reusable PacketAssembler in drpcwire. This centralizes assembly invariants and lets both drpcstream.Stream and drpcmanager.Manager assemble packets from frames in a consistent way, while drpcwire.Reader now returns individual frames.

Changes:

  • drpcwire.Reader now exposes ReadFrame (frame parsing only) and tests were updated accordingly.
  • Added drpcwire.PacketAssembler to assemble frames into packets with monotonicity/kind invariants and stream-ID consistency.
  • Updated drpcstream.Stream and drpcmanager.Manager to ingest frames and assemble/route complete packets; expanded test coverage around frame handling.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
drpcwire/reader.go Convert reader from packet reconstruction to single-frame reads (ReadFrame).
drpcwire/reader_test.go Update tests to validate frame-by-frame reading and buffering behavior.
drpcwire/packet_builder.go Introduce PacketAssembler for reusable frame-to-packet assembly and invariants.
drpcstream/stream.go Replace HandlePacket entrypoint with HandleFrame + internal handlePacket.
drpcstream/stream_test.go Update existing tests for frame handling; add a large suite of HandleFrame tests.
drpcmanager/manager.go Switch manager reader loop to ReadFrame, add invoke-sequence assembly and routing updates.
drpcmanager/manager_test.go Add tests for global monotonicity, invoke sequencing, and frame delivery behavior.
drpcconn/conn_test.go Update conn tests to use ReadFrame for verifying on-wire output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Extract the frame assembly logic from Stream.HandleFrame into a
reusable PacketAssembler type in drpcwire. Both the stream and the
manager now use their own PacketAssembler instance, keeping assembly
logic in one place.

The manager's assembler handles the invoke sequence (metadata +
invoke), which removes the restriction that only KindMessage packets
could be split across frames. This also simplifies NewServerStream
from a packet-at-a-time loop into a single receive.
@shubhamdhama shubhamdhama force-pushed the shubham/extract-out-assembly branch from 2e5ff8e to 0f1fbbe Compare March 27, 2026 04:54
@shubhamdhama shubhamdhama force-pushed the shubham/extract-out-assembly branch from 0b8ee3d to 162c5ab Compare March 28, 2026 12:58
@shubhamdhama
Copy link
Copy Markdown
Author

shubhamdhama commented Mar 28, 2026

I've moved the invoke packet assembler and metadata from from manageReader to Manager as a field and clearly mentioned that Manager.metadata/pa are used in handleInvokeFrame. This is completely for readability. Having them passed as an argument to handleInvoke.. was a mouthful and having them initialized in manageReader adds up to the context one has to keep in mind. Now that it's in Manager it's much readable IMO at the obvious cost of increased scope but some documentation and common-sense should save us there.
I'm focusing on readability to reduce the number of things we have to keep in mind while reading manageReader. In subsequent PR I will change these fields to map from string to these types and no change would appear in manageReader.

I'm think we may move manageReader to its own struct.

Rename packet_builder.go to packet_assembler.go for clarity. Move
frame-to-packet assembly tests from drpcstream/stream_test.go to
drpcwire/packet_assembler_test.go, testing PacketAssembler directly
without Stream dependencies. Stream tests now focus on handlePacket
behavior (delivery, termination, invoke rejection).
@shubhamdhama shubhamdhama force-pushed the shubham/extract-out-assembly branch from 04265e8 to 6ea6efb Compare March 30, 2026 14:25
@cthumuluru-crdb cthumuluru-crdb self-requested a review March 31, 2026 12:23
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.

4 participants