System.Memory.Data 9.0.1

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.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://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview
25
Azure.Core
This is the implementation of the Azure Client Pipeline
24
System.ClientModel
Contains building blocks for clients that call cloud services.
24
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
23
System.ClientModel
Contains building blocks for clients that call cloud services.
21
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://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview
21
Azure.Core
This is the implementation of the Azure Client Pipeline
20
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://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview
16
System.ClientModel
Contains building blocks for clients that call cloud services.
16
Azure.Core
This is the implementation of the Azure Client Pipeline
16
System.ClientModel
Contains building blocks for clients that call cloud services.
15
Azure.Core.Amqp
This library contains AMQP model types used by Azure libraries.
14
System.ClientModel
Contains building blocks for clients that call cloud services.
14
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
14
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://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview
14
Azure.Core
This is the implementation of the Azure Client Pipeline
14
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://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview
13

https://go.microsoft.com/fwlink/?LinkID=799421

.NET Framework 4.6.2

.NET 8.0

.NET 9.0

  • No dependencies.

.NET Standard 2.0

Version Downloads Last updated
9.0.1 3 01/17/2025
9.0.0 4 11/19/2024
9.0.0-rc.2.24473.5 5 10/09/2024
9.0.0-rc.1.24431.7 2 09/17/2024
9.0.0-preview.7.24405.7 4 08/23/2024
9.0.0-preview.6.24327.7 7 07/11/2024
9.0.0-preview.5.24306.7 5 06/12/2024
9.0.0-preview.4.24266.19 22 05/23/2024
9.0.0-preview.3.24172.9 12 04/19/2024
9.0.0-preview.2.24128.5 12 03/13/2024
9.0.0-preview.1.24080.9 10 02/13/2024
8.0.1 7 10/09/2024
8.0.0 7 02/13/2024
8.0.0-rc.2.23479.6 7 02/13/2024
8.0.0-rc.1.23419.4 6 02/13/2024
8.0.0-preview.7.23375.6 7 02/13/2024
8.0.0-preview.6.23329.7 7 02/13/2024
8.0.0-preview.5.23280.8 8 02/13/2024
8.0.0-preview.4.23259.5 6 08/25/2023
8.0.0-preview.3.23174.8 7 08/31/2023
8.0.0-preview.2.23128.3 8 08/29/2023
8.0.0-preview.1.23110.8 9 08/29/2023
7.0.0 8 02/20/2024
7.0.0-rc.2.22472.3 7 08/28/2023
7.0.0-rc.1.22426.10 5 08/24/2023
7.0.0-preview.7.22375.6 5 02/20/2024
7.0.0-preview.6.22324.4 7 08/29/2023
7.0.0-preview.5.22301.12 5 02/20/2024
7.0.0-preview.4.22229.4 10 08/27/2023
7.0.0-preview.3.22175.4 7 08/28/2023
7.0.0-preview.2.22152.2 6 02/20/2024
7.0.0-preview.1.22076.8 7 08/31/2023
6.0.2-mauipre.1.22102.15 10 08/24/2023
6.0.2-mauipre.1.22054.8 4 08/31/2023
6.0.1 5 11/19/2024
6.0.0 5 02/20/2024
6.0.0-rc.2.21480.5 6 08/31/2023
6.0.0-rc.1.21451.13 9 08/26/2023
6.0.0-preview.7.21377.19 7 08/31/2023
6.0.0-preview.6.21352.12 8 08/26/2023
6.0.0-preview.5.21301.5 8 08/29/2023
6.0.0-preview.4.21253.7 7 08/27/2023
6.0.0-preview.3.21201.4 6 02/20/2024
6.0.0-preview.2.21154.6 8 08/31/2023
6.0.0-preview.1.21102.12 7 08/27/2023
1.0.2 23 02/17/2023
1.0.1 5 03/20/2023
1.0.0 6 02/20/2024
1.0.0-beta.2 6 08/31/2023
1.0.0-beta.1 6 08/29/2023