You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: change IMessage.Data from byte[] to ReadOnlyMemory<byte> (#530)
* perf: change IMessage.Data from byte[] to ReadOnlyMemory<byte>
* Fix: Correct VitePress markdown syntax in messaging.md docs
- Replace unsupported ::: warning syntax with plain markdown bold text
- Fixes CI build error: 'Element is missing end tag' at line 207:135
- Build now passes successfully
* Fix: Remove incorrect v5.0 version reference from breaking change notice
This is a current breaking change, not from v5.0
* Address PR review: preserve byte[] no-copy path and strengthen no-copy test
- MessageBusBase: when no CLR type is mapped (Subscribe<byte[]>()), return the
underlying managed array directly when the payload wraps a full-length array
(offset 0, full count) instead of always allocating via ToArray(). Falls back
to a copy only when the memory is sliced or not array-backed, preserving the
pre-ReadOnlyMemory byte[] no-copy behavior.
- MessageTests: assert the stored ReadOnlyMemory is backed by the same array
instance and segment as the source payload to actually verify no-copy.
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* docs: restore Common Patterns heading; soften IMessage.Data buffer-lifetime wording
Address review feedback:
- Restore the '## Common Patterns' section header that was accidentally replaced
by the breaking-change note, and promote the note to a proper '#### Breaking
change' subsection so 'Event-Driven Architecture' is no longer mis-nested under
'Message Types'.
- Reword the IMessage.Data remarks to frame buffer validity as an implementation
expectation (with consumer guidance to copy via ToArray()) rather than a hard
guarantee that external implementers may not uphold.
* style: add blank lines after guards; rename tests to 3-part convention with AAA blocks
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
#### Breaking change: `IMessage.Data` is now `ReadOnlyMemory<byte>`
277
+
278
+
`IMessage.Data` exposes the raw payload as `ReadOnlyMemory<byte>` instead of `byte[]`. This lets memory-backed transports such as Azure Service Bus avoid copying the payload into a new array. Since it is a struct, follow these patterns:
279
+
280
+
- Check for an empty payload with `message.Data.IsEmpty` (not `== null`)
281
+
- Read the bytes directly via `message.Data.Span`
282
+
- Call `message.Data.ToArray()` only when you need a `byte[]`
283
+
284
+
Most code that uses `GetBody()` / `Body` is unaffected. When constructing a `Message`, you can still pass a `byte[]`; it converts implicitly to `ReadOnlyMemory<byte>`.
0 commit comments