Fix old-spec raw headers - #1028
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 507e76c5-0c79-42e3-995a-4cb3995ab97e
There was a problem hiding this comment.
Pull request overview
Updates MessagePackWriter’s OldSpec behavior to match the legacy MessagePack “raw” encoding rules (avoiding str8) and to explicitly reject extension formats that the old spec does not define.
Changes:
- In
OldSpecmode, emitstr16(raw16) headers for 32–255 byte string payloads (and, viaWriteBinHeader, for byte[] payloads encoded as strings). - Throw
NotSupportedExceptionwhen writingExtensionHeaderinOldSpecmode. - Add test coverage for boundary lengths and unsupported extension writing in
OldSpec.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Nerdbank.MessagePack.Tests/BuiltInConverterTests.cs | Adds parameterized tests asserting legacy-compatible headers in OldSpec mode and verifies extensions are rejected. |
| src/Nerdbank.MessagePack/MessagePackWriter.cs | Forces OldSpec string headers for 32–255 bytes to use Str16 and blocks extension header writes under OldSpec. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 507e76c5-0c79-42e3-995a-4cb3995ab97e
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
src/Nerdbank.MessagePack/MessagePackWriter.cs:558
- This XML doc comment says the msgpack code used in OldSpec mode is
MinFixStr, but the actual header byte will vary across the fixstr range (MinFixStr..MaxFixStr). Referring to the whole range avoids implying a single constant header code.
/// When <see cref="OldSpec"/> is <see langword="true"/>, the msgpack code used is <see cref="MessagePackCode.MinFixStr"/>, <see cref="MessagePackCode.Str16"/> or <see cref="MessagePackCode.Str32"/> instead.
src/Nerdbank.MessagePack/MessagePackWriter.cs:584
- This XML doc comment says the msgpack code used in OldSpec mode is
MinFixStr, but the actual header byte will vary across the fixstr range (MinFixStr..MaxFixStr). Referring to the whole range avoids implying a single constant header code.
/// When <see cref="OldSpec"/> is <see langword="true"/>, the msgpack code used is <see cref="MessagePackCode.MinFixStr"/>, <see cref="MessagePackCode.Str16"/> or <see cref="MessagePackCode.Str32"/> instead.
src/Nerdbank.MessagePack/MessagePackWriter.cs:534
- This XML doc comment says the msgpack code used in OldSpec mode is
MinFixStr, but the actual header byte will vary across the fixstr range (MinFixStr..MaxFixStr). Referring to the whole range avoids implying a single constant header code.
This issue also appears in the following locations of the same file:
- line 558
- line 584
/// When <see cref="OldSpec"/> is <see langword="true"/>, the msgpack code used is <see cref="MessagePackCode.MinFixStr"/>, <see cref="MessagePackCode.Str16"/> or <see cref="MessagePackCode.Str32"/> instead.
Summary
Credit
Thanks to @mikegoodspeed for reporting the original MessagePack-CSharp issue (MessagePack-CSharp#2286).