Ceiralizer 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ceiralizer --version 2.0.0
                    
NuGet\Install-Package Ceiralizer -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ceiralizer" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ceiralizer" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Ceiralizer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ceiralizer --version 2.0.0
                    
#r "nuget: Ceiralizer, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ceiralizer@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ceiralizer&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Ceiralizer&version=2.0.0
                    
Install as a Cake Tool

Ceiralizer

Serialize structs and classes to a byte array and deserialize them back.

NuGet: https://www.nuget.org/packages/Ceiralizer

Quick Start

1. Define Your Packet

public struct CeiraPacket : IPacket
{
    [PacketField] public short Op;

    // Fields without PacketField are ignored.
    public string Garbage;

    [PacketField] public int Value;

    [PacketField] public int[] Ceiras;
    
    [PacketField] public char Prefix;
    
    [PacketField] public CeirinhaPacket Ceirinha;
    
    [PacketField] public string Name;

    [PacketField] public bool IsWorking;
    
    [PacketField] public Vector2 Position;
    
    [PacketField] public Ceirax Ceirax;

public struct CeirinhaPacket : IPacket
{
    [PacketField] public string Ceirinha;
}

public struct Vector2 { public int X; public int Y; }


### Transforming
```csharp
using System.Text;
using Ceiralizer;

// Default is Encoding.Unicode. // Use UTF-8 to reduce the size for most text data.
PacketSerializer.StringEncoder = Encoding.UTF8;

// Register a custom serializer.
TypeSerializer.Serializers.Add(typeof(Vector2), (value, writer) =>
{
    var pos = (Vector2)value;
    writer.Write(pos.X);
    writer.Write(pos.Y);
});

// And also adding deserializer
TypeSerializer.Deserializers.Add(typeof(Vector2), reader =>
{
    int x = reader.ReadInt();
    int y = reader.ReadInt();

    return new Vector2(x, y);
});

3. Serialize & Deserialize

// Serialize
byte[] data = PacketSerializer.Serialize(new CeiraPacket
{
    Op = 2,
    Value = 255,
    Ceiras = new[] { 4, 66, 95 },
    Garbage = "Lixo",
    Prefix = 'c',
    Ceirinha = new CeirinhaPacket { Ceirinha = "Ceira purinha" },
    Name = "Ceira",
    IsWorking = true,
    Position = new Vector2(5, 25),
    Ceirax = new Ceirax { Title = "Test", Description = "Test", Price = 10.5f }
});

// Deserialize
CeiraPacket packet = PacketSerializer.Deserialize<CeiraPacket>(data);

Console.WriteLine(packet.Op);           // Output: 2
Console.WriteLine(packet.Value);        // Output: 255
Console.WriteLine(packet.Name);         // Output: Ceira
Console.WriteLine(packet.IsWorking);    // Output: True

Supported Types

  • Primitives: bool, byte, sbyte, char
  • Integer: int, uint, short, ushort, long, ulong
  • Float: float, double
  • Text: string
  • Collections: Arrays of any supported type
  • Nested Packets: Any type implementing IPacket
  • Custom Types: Any type implementing ISerializable

Custom Serialization

Implement ISerializable for complex types:

public class Ceirax : ISerializable
{
    public string Title = "";
    public string Description = "";
    public float Price;

    public void Serialize(ChunkWriter writer)
    {
        TypeSerializer.Serializers[typeof(string)].Invoke(Title, writer);
        TypeSerializer.Serializers[typeof(string)].Invoke(Description, writer);
        TypeSerializer.Serializers[typeof(float)].Invoke(Price, writer);
    }

    public void Deserialize(ChunkReader reader)
    {
        Title = (string)TypeSerializer.Deserializers[typeof(string)].Invoke(reader)!;
        Description = (string)TypeSerializer.Deserializers[typeof(string)].Invoke(reader)!;
        Price = (float)TypeSerializer.Deserializers[typeof(float)].Invoke(reader)!;
    }
}

Note: Mark ISerializable fields with [PacketField] in your packet definition.

How It Works

Ceiralizer serializes fields in declaration order:

  1. Size prefix: Arrays and strings store their byte/element count first
  2. Sequential writing: Each [PacketField] is written as-is to the byte stream
  3. Nested packets: IPacket implementations are flattened (fields merged)
  4. Custom logic: ISerializable types use their custom Serialize/Deserialize methods

Example byte structure for a short and an int:

[short: 2]          [int: 255]
00000010 00000000 | 11111111 00000000 00000000 00000000
Product 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 was computed.  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 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.1.0 171 5/26/2026
4.0.1 159 5/25/2026
4.0.0 157 5/25/2026
3.2.0 157 5/23/2026
3.1.2 158 5/23/2026
3.1.1 156 5/22/2026
3.1.0 150 5/20/2026
3.0.0 151 5/14/2026
2.0.0 2,510 5/8/2026
1.1.0 6,638 1/31/2023
1.0.5 6,781 4/12/2022
1.0.4 6,773 4/10/2022
1.0.3 6,735 4/6/2022
1.0.2 6,737 2/10/2022
1.0.1 6,746 2/7/2022
1.0.0 6,573 1/7/2022