System.Memory.Data 9.0.0-rc.2.24473.5
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.
Showing the top 20 packages that depend on System.Memory.Data.
Packages | Downloads |
---|---|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
7 |
Azure.Core
This is the implementation of the Azure Client Pipeline
|
8 |
Azure.Core
This is the implementation of the Azure Client Pipeline
|
9 |
Azure.Core
This is the implementation of the Azure Client Pipeline
|
11 |
Azure.Core
This is the implementation of the Azure Client Pipeline
|
60 |
Azure.Storage.Queues
This client library enables working with the Microsoft Azure Storage Queue service for storing messages that may be accessed by a client.
For this release see notes - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Azure.Storage.Queues/README.md and https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Azure.Storage.Queues/CHANGELOG.md
in addition to the breaking changes https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Azure.Storage.Queues/BreakingChanges.txt
Microsoft Azure Storage quickstarts and tutorials - https://docs.microsoft.com/en-us/azure/storage/
Microsoft Azure Storage REST API Reference - https://docs.microsoft.com/en-us/rest/api/storageservices/
REST API Reference for Queue Service - https://docs.microsoft.com/en-us/rest/api/storageservices/queue-service-rest-api
|
6 |
Azure.Storage.Queues
This client library enables working with the Microsoft Azure Storage Queue service for storing messages that may be accessed by a client.
For this release see notes - https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Queues/README.md and https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Queues/CHANGELOG.md
in addition to the breaking changes https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Queues/BreakingChanges.txt
Microsoft Azure Storage quickstarts and tutorials - https://docs.microsoft.com/en-us/azure/storage/
Microsoft Azure Storage REST API Reference - https://docs.microsoft.com/en-us/rest/api/storageservices/
REST API Reference for Queue Service - https://docs.microsoft.com/en-us/rest/api/storageservices/queue-service-rest-api
|
6 |
Microsoft.Azure.WebJobs
This package contains the runtime assemblies for Microsoft.Azure.WebJobs.Host. It also adds rich diagnostics capabilities which makes it easier to monitor the WebJobs in the dashboard. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=320971
|
7 |
Microsoft.Azure.WebJobs.Core
This library simplifies the task of adding background processing to your Microsoft Azure Web Sites. The SDK uses Microsoft Azure Storage, triggering a function in your program when items are added to Queues and Blobs. A dashboard provides rich monitoring and diagnostics for the programs that you write by using the SDK. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=320971
|
6 |
Microsoft.Azure.WebJobs.Core
This library simplifies the task of adding background processing to your Microsoft Azure Web Sites. The SDK uses Microsoft Azure Storage, triggering a function in your program when items are added to Queues and Blobs. A dashboard provides rich monitoring and diagnostics for the programs that you write by using the SDK. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=320971
|
7 |
System.ClientModel
Contains building blocks for clients that call cloud services.
|
7 |
System.ClientModel
Contains building blocks for clients that call cloud services.
|
8 |
.NET Framework 4.6.2
- System.Text.Json (>= 9.0.0-rc.2.24473.5)
- System.Memory (>= 4.5.5)
.NET 8.0
- System.Text.Json (>= 9.0.0-rc.2.24473.5)
.NET 9.0
- No dependencies.
.NET Standard 2.0
- System.Text.Json (>= 9.0.0-rc.2.24473.5)
- System.Memory (>= 4.5.5)