Skip to content

ProtocolRawMsg: const accessors and takeBuffer(); takeable buffers for encoded messages - #31

Merged
robdobsn merged 2 commits into
mainfrom
fix/protocol-raw-msg-const
Oct 25, 2026
Merged

robdobsn merged 2 commits into
mainfrom
fix/protocol-raw-msg-const

Conversation

@robdobsn

@robdobsn robdobsn commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Lets a channel queue an outbound message without copying it. Needed by robdobsn/RaftSysMods#12, so merge this first.

  • ProtocolRawMsg::getBuf()/getBufLen() are const, so a queued message can be read in place with ThreadSafeQueue::peekWith(). BLE sent each large message in MTU-sized pieces and copied the whole message out of the queue for every piece (about 1.6 MB of copying for a 28 KB camera frame).
  • CommsChannelMsg::setBufTakeable()/isBufTakeable(): a protocol codec marks a message it made to send and doesn't use afterwards, so the channel may move its buffer out instead of copying it. ProtocolRICSerial marks its encoded message. Messages passed on as they are (ProtocolRICJSON, ProtocolRICFrame) aren't marked, as the same message may be sent again (e.g. on each channel for MSG_CHANNEL_ID_ALL).
  • ProtocolRawMsg::takeBuffer() takes a buffer's contents without copying.

No change for existing callers: nothing takes a buffer unless it checks isBufTakeable().

Tested with RaftSysMods#12 on an ESP32-S3 plant growth board, live camera frames (about 10 KB) over BLE: longest publish 5.5 ms (7.5 ms with the copy), longest loop about 7 ms.

🤖 Generated with Claude Code

So a message can be read in place in a queue (ThreadSafeQueue::peekWith passes it as const) - BLE sends a large
message in pieces and copied the whole message for each piece.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CommsChannelMsg::setBufTakeable()/isBufTakeable(): set by a protocol codec on a message it made to send and
doesn't use afterwards, so the channel sending it may move the buffer out rather than copy it. RICSerial sets it
on its encoded message. A message passed on as it is (RICJSON, RICFrame) may be sent again - e.g. on each channel
for MSG_CHANNEL_ID_ALL - so its buffer isn't takeable.

ProtocolRawMsg::takeBuffer() takes a buffer's contents without copying. BLE queues the message this way, which
saves a copy of each camera frame published (about 2 ms for a 10 KB frame on an ESP32-S3 with PSRAM).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robdobsn robdobsn changed the title ProtocolRawMsg: const getBuf() and getBufLen() ProtocolRawMsg: const accessors and takeBuffer(); takeable buffers for encoded messages Oct 25, 2026
@robdobsn
robdobsn merged commit b061402 into main Oct 25, 2026
1 check passed
@robdobsn
robdobsn deleted the fix/protocol-raw-msg-const branch October 25, 2026 17:31
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