EW-10817 Add WebSocketDataMessage helper for text-or-binary payloads#6739
Conversation
There was a problem hiding this comment.
Clean wrapper — nice owned/borrowed split and thorough tests.
One medium-severity item: several methods on WebSocketDataMessage return non-owning views into *this's storage and should carry KJ_LIFETIMEBOUND so the compiler can warn on dangling use. The codebase already uses this annotation for the same pattern (e.g., blob.h getData() / getType()).
|
I'm Bonk, and I've done a quick review of your PR. Summary: Adds Issues found (1):
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## harris/EW-10817-hibernation-manager-tests #6739 +/- ##
=============================================================================
- Coverage 66.76% 66.75% -0.02%
=============================================================================
Files 403 405 +2
Lines 116449 116788 +339
Branches 19496 19615 +119
=============================================================================
+ Hits 77750 77961 +211
- Misses 27026 27052 +26
- Partials 11673 11775 +102 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owned text-or-binary message wrapper (and a non-owning Ptr counterpart) for the WebSocket auto-response and outgoing-message paths. Wraps `kj::OneOf<kj::String, kj::Array<byte>>` (and the pointer-shaped equivalent) with a domain-named, read-only inspection surface — `isText` / `isBinary` / `tryGetText` / `tryGetBinary` — plus `size()`, `sendVia(kj::WebSocket&)`, `asPtr()` / `toOwned()`, `asOneOf()` for KJ_SWITCH_ONEOF dispatch, and `operator==(kj::StringPtr)` / `operator==(kj::ArrayPtr<const byte>)` for content-equality checks at matching sites. Inspection on `WebSocketDataMessage` delegates through a temporary `WebSocketDataMessagePtr`, so `KJ_SWITCH_ONEOF(msg.asOneOf())` cases bind to `kj::StringPtr` / `kj::ArrayPtr<const byte>` (not the owned types), and `tryGetText/Binary` return `Maybe<StringPtr/ArrayPtr<const byte>>`. This makes inspection implicitly read-only (no path to obtain a mutable reference into the owned storage) and hides the storage type from callers — owned-vs-borrowed is now purely a lifetime distinction. This pattern — text-or-binary WebSocket payloads, never control frames — recurs across the codebase, and dealing with the equivalent `kj::OneOf` at every consuming site is awkward. The helper consolidates it into a single typed wrapper. Assisted-by: OpenCode:claude-opus-4.7
d4878e5 to
09a0cce
Compare
Owned text-or-binary message wrapper (and a non-owning Ptr counterpart) for the WebSocket auto-response and outgoing-message paths. Wraps
kj::OneOf<kj::String, kj::Array<byte>>(and the pointer-shaped equivalent) with a domain-named, read-only inspection surface —isText/isBinary/tryGetText/tryGetBinary— plussize(),sendVia(kj::WebSocket&),asPtr()/toOwned(),asOneOf()for KJ_SWITCH_ONEOF dispatch, andoperator==(kj::StringPtr)/operator==(kj::ArrayPtr<const byte>)for content-equality checks at matching sites.Inspection on
WebSocketDataMessagedelegates through a temporaryWebSocketDataMessagePtr, soKJ_SWITCH_ONEOF(msg.asOneOf())cases bind tokj::StringPtr/kj::ArrayPtr<const byte>(not the owned types), andtryGetText/BinaryreturnMaybe<StringPtr/ArrayPtr<const byte>>. This makes inspection implicitly read-only (no path to obtain a mutable reference into the owned storage) and hides the storage type from callers — owned-vs-borrowed is now purely a lifetime distinction.This pattern — text-or-binary WebSocket payloads, never control frames — recurs across the codebase, and dealing with the equivalent
kj::OneOfat every consuming site is awkward. The helper consolidates it into a single typed wrapper.Assisted-by: OpenCode:claude-opus-4.7