Skip to content

Port span-based Encoding.GetBytes to Write(string) and Write(ReadOnlySpan<char>) (#1004) - #1008

Merged
AArnott merged 1 commit into
v1.2from
backport-fix
Jul 8, 2026
Merged

Port span-based Encoding.GetBytes to Write(string) and Write(ReadOnlySpan<char>) (#1004)#1008
AArnott merged 1 commit into
v1.2from
backport-fix

Conversation

@AArnott

@AArnott AArnott commented Jul 8, 2026

Copy link
Copy Markdown
Owner
  • Port MessagePack-CSharp PR #2258: use span-based Encoding.GetBytes in Write(string) and Write(ReadOnlySpan)
  • Remove unnecessary .AsSpan() in Write(string) - string implicitly converts to ReadOnlySpan
  • Fix legacy path buffer size: use bufferSize - useOffset in GetBytes calls

…Span<char>) (#1004)

* Port MessagePack-CSharp PR #2258: use span-based Encoding.GetBytes in Write(string) and Write(ReadOnlySpan<char>)

Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>

* Remove unnecessary .AsSpan() in Write(string) - string implicitly converts to ReadOnlySpan<char>

Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>

* Fix legacy path buffer size: use bufferSize - useOffset in GetBytes calls

Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
@AArnott AArnott added this to the 1.2 milestone Jul 8, 2026
Copilot AI review requested due to automatic review settings July 8, 2026 21:00
@AArnott
AArnott enabled auto-merge (squash) July 8, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates MessagePackWriter’s string-writing paths to use span-based Encoding.GetBytes where available, and corrects the legacy unsafe encoding call to respect the available destination buffer length when an offset is applied.

Changes:

  • Use span-based Encoding.GetBytes in Write(string) and Write(ReadOnlySpan<char>) under #if NET.
  • Remove unnecessary fixed (char*) usage on the modern path while keeping the pointer-based fallback for older TFMs.
  • Fix destination buffer sizing in the legacy pointer-based GetBytes call by using bufferSize - useOffset.

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.

3 participants