System.Memory.Data
9.0.0-rc.1.24431.7
Prefix Reserved
See the version list below for details.
dotnet add package System.Memory.Data --version 9.0.0-rc.1.24431.7
NuGet\Install-Package System.Memory.Data -Version 9.0.0-rc.1.24431.7
<PackageReference Include="System.Memory.Data" Version="9.0.0-rc.1.24431.7" />
paket add System.Memory.Data --version 9.0.0-rc.1.24431.7
#r "nuget: System.Memory.Data, 9.0.0-rc.1.24431.7"
// Install System.Memory.Data as a Cake Addin #addin nuget:?package=System.Memory.Data&version=9.0.0-rc.1.24431.7&prerelease // Install System.Memory.Data as a Cake Tool #tool nuget:?package=System.Memory.Data&version=9.0.0-rc.1.24431.7&prerelease
About
System.Memory.Data introduces the BinaryData
type, a lightweight abstraction for a byte payload.
It makes it easy to convert between string, bytes, and stream.
This abstraction can simplify the API surface by exposing a single type instead of numerous overloads or properties.
The BinaryData
type handles data ownership efficiently, wrapping passed-in bytes when using byte[]
or ReadOnlyMemory<byte>
constructors or methods, and managing data as bytes when dealing with streams, strings, or rich model types serialized as JSON.
Key Features
- Lightweight abstraction for byte payload via
BinaryData
type. - Convenient helper methods for common conversions among string, bytes, and stream.
- Efficient data ownership handling.
How to Use
To/From String:
var data = new BinaryData("some data");
// ToString will decode the bytes using UTF-8
Console.WriteLine(data.ToString()); // prints "some data"
To/From Bytes:
byte[] bytes = Encoding.UTF8.GetBytes("some data");
// Create BinaryData using a constructor ...
BinaryData data = new BinaryData(bytes);
// Or using a static factory method.
data = BinaryData.FromBytes(bytes);
// There is an implicit cast defined for ReadOnlyMemory<byte>
ReadOnlyMemory<byte> rom = data;
// There is also an implicit cast defined for ReadOnlySpan<byte>
ReadOnlySpan<byte> ros = data;
// there is also a ToMemory method that gives access to the ReadOnlyMemory.
rom = data.ToMemory();
// and a ToArray method that converts into a byte array.
byte[] array = data.ToArray();
To/From stream:
var bytes = Encoding.UTF8.GetBytes("some data");
Stream stream = new MemoryStream(bytes);
var data = BinaryData.FromStream(stream);
// Calling ToStream will give back a stream that is backed by ReadOnlyMemory, so it is not writable.
stream = data.ToStream();
Console.WriteLine(stream.CanWrite); // prints false
BinaryData
also can be used to integrate with ObjectSerializer
.
By default, the JsonObjectSerializer
will be used, but any serializer deriving from ObjectSerializer
can be used.
var model = new CustomModel
{
A = "some text",
B = 5,
C = true
};
var data = BinaryData.FromObjectAsJson(model);
model = data.ToObjectFromJson<CustomModel>();
Main Types
The main types provided by this library are:
System.BinaryData
Additional Documentation
Feedback & Contributing
System.Memory.Data is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- System.Memory (>= 4.5.5)
- System.Text.Json (>= 9.0.0-rc.1.24431.7)
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
- System.Text.Json (>= 9.0.0-rc.1.24431.7)
-
net8.0
- System.Text.Json (>= 9.0.0-rc.1.24431.7)
-
net9.0
- No dependencies.
NuGet packages (144)
Showing the top 5 NuGet packages that depend on System.Memory.Data:
Package | Downloads |
---|---|
Azure.Core
This is the implementation of the Azure Client Pipeline |
|
Microsoft.Azure.WebJobs.Core
This package provides the core Types and Attribute definitions for the WebJobs SDK. For more information, please visit https://go.microsoft.com/fwlink/?linkid=2279708. |
|
Microsoft.Azure.WebJobs
This package contains the runtime host components of the WebJobs SDK. For more information, please visit https://go.microsoft.com/fwlink/?linkid=2279708. |
|
Azure.Messaging.ServiceBus
Azure Service Bus is a fully managed enterprise integration message broker. Service Bus can decouple applications and services. Service Bus offers a reliable and secure platform for asynchronous transfer of data and state. This client library allows for both sending and receiving messages using Azure Service Bus. For more information about Service Bus, see https://learn.microsoft.com/azure/service-bus-messaging/service-bus-messaging-overview |
|
Azure.Core.Amqp
This library contains AMQP model types used by Azure libraries. |
GitHub repositories (27)
Showing the top 5 popular GitHub repositories that depend on System.Memory.Data:
Repository | Stars |
---|---|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
dotnet/orleans
Cloud Native application framework for .NET
|
|
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
|
|
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
|
|
microsoft/kernel-memory
RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
|