-
Notifications
You must be signed in to change notification settings - Fork 587
Use ReadOnlyMemory<byte> for binary data to eliminate UTF-16 transcoding #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
7dca602
4287694
8e6fcf0
e405dfc
ebe3eef
1d76c11
39213fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| using System.Globalization; | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Nodes; | ||
|
|
@@ -391,7 +392,14 @@ public override async ValueTask<ReadResourceResult> ReadAsync( | |
|
|
||
| DataContent dc => new() | ||
| { | ||
| Contents = [new BlobResourceContents { Uri = request.Params!.Uri, MimeType = dc.MediaType, Blob = System.Text.Encoding.UTF8.GetBytes(dc.Base64Data.ToString()) }], | ||
| Contents = [new BlobResourceContents | ||
| { | ||
| Uri = request.Params!.Uri, | ||
| MimeType = dc.MediaType, | ||
| Blob = MemoryMarshal.TryGetArray(dc.Base64Data, out ArraySegment<char> segment) && segment.Offset == 0 && segment.Count == segment.Array!.Length | ||
|
||
| ? System.Text.Encoding.UTF8.GetBytes(segment.Array) | ||
| : System.Text.Encoding.UTF8.GetBytes(dc.Base64Data.ToString()) | ||
| }], | ||
| }, | ||
|
|
||
| string text => new() | ||
|
|
@@ -420,7 +428,9 @@ public override async ValueTask<ReadResourceResult> ReadAsync( | |
| { | ||
| Uri = request.Params!.Uri, | ||
| MimeType = dc.MediaType, | ||
| Blob = System.Text.Encoding.UTF8.GetBytes(dc.Base64Data.ToString()) | ||
| Blob = MemoryMarshal.TryGetArray(dc.Base64Data, out ArraySegment<char> segment) && segment.Offset == 0 && segment.Count == segment.Array!.Length | ||
| ? System.Text.Encoding.UTF8.GetBytes(segment.Array) | ||
| : System.Text.Encoding.UTF8.GetBytes(dc.Base64Data.ToString()) | ||
| }, | ||
|
|
||
| _ => throw new InvalidOperationException($"Unsupported AIContent type '{ac.GetType()}' returned from resource function."), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.