Barchart.BinarySerializer
1.0.2
See the version list below for details.
dotnet add package Barchart.BinarySerializer --version 1.0.2
NuGet\Install-Package Barchart.BinarySerializer -Version 1.0.2
<PackageReference Include="Barchart.BinarySerializer" Version="1.0.2" />
paket add Barchart.BinarySerializer --version 1.0.2
#r "nuget: Barchart.BinarySerializer, 1.0.2"
// Install Barchart.BinarySerializer as a Cake Addin #addin nuget:?package=Barchart.BinarySerializer&version=1.0.2 // Install Barchart.BinarySerializer as a Cake Tool #tool nuget:?package=Barchart.BinarySerializer&version=1.0.2
@barchart/binary-serializer-net
Structure
BinarySerializer: All source code for the Binary Serializer library is in the
Barchart.BinarySerializer
directory. This includes the core serialization logic, attribute definitions, buffer management, schema factories, and any other utilities required for the serialization and deserialization processes.Examples: To help you get started and to demonstrate the capabilities of the Binary Serializer, example projects can be found in the
Barchart.BinarySerializer.Examples
directory. These examples cover a range of use cases, from basic serialization to more complex scenarios.Scripts: The
Barchart.BinarySerializer.Scripts
directory contains essential scripts that facilitate the library's operation and maintenance. This includestest.csx
for running the tests andpublish.csx
for publishing the package.Tests: The
Barchart.BinarySerializer.Tests
directory contains a group of tests ensuring the library's reliability.
Example Usage
Here are some simple examples of the library's usage:
Serialize a Snapshot:
using Barchart.BinarySerializer.Buffers;
using Barchart.BinarySerializer.Schemas.Factories;
public class TestEntity
{
[Serialize(true)]
public string? PropertyName { get; set; }
[Serialize(false)]
public int PropertyNumber { get; set; }
}
TestEntity entity = new()
{
PropertyName = "Name",
PropertyNumber = 123
};
const byte entityId = 1;
// Create a Serializer instance for the specified class with provided entity id
Serializer<TestEntity> serializer = new(entityId);
// Serialize the entity into a byte array
byte[] bytes = serializer.Serialize(entity);
// Deserialize the byte array back into an object
TestEntity deserializedEntity = serializer.Deserialize(bytes);
Console.WriteLine(deserializedEntity.PropertyName); // Output: Name
Console.WriteLine(deserializedEntity.PropertyNumber); // Output: 123
Serialize Changes:
using Barchart.BinarySerializer.Buffers;
using Barchart.BinarySerializer.Schemas.Factories;
public class TestEntity
{
[Serialize(true)]
public string? PropertyName { get; set; }
[Serialize(false)]
public int PropertyNumber { get; set; }
}
TestClass previousEntity = new()
{
PropertyName = "Name",
PropertyNumber = 123
};
TestClass currentEntity = new()
{
PropertyName = "Name",
PropertyNumber = 321
};
const byte entityId = 1;
// Create a Serializer instance for the specified class with provided entity id
Serializer<TestEntity> serializer = new(entityId);
// Serialize the changes into a byte array
byte[] changes = serializer.Serialize(currentEntity, previousEntity);
// Deserialize the changes back into an object
TestEntity deserializedEntity = serializer.Deserialize(changes, previousEntity);
Console.WriteLine(deserializedEntity.PropertyName); // Output: Name
Console.WriteLine(deserializedEntity.PropertyNumber); // Output: 321
[!NOTE]
TheSerialize
attribute is used to mark properties or fields for binary serialization. Whentrue
is passed to theSerialize
attribute, it indicates that the data member is part of the unique key for the object. Multiple data members can be marked as key components, allowing for compound keys in complex objects.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Barchart.Common (>= 1.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.