Skip to content

Latest commit

 

History

History
 
 

README.md

Nalix.Codec

Serialization, packet framing, compression, and cryptographic transform primitives for Nalix.

Nalix.Codec owns the data representation layer: source-generated serialization, packet/frame models, LZ4 compression, AEAD envelope ciphers, and the transform pipeline used by the runtime and SDK.

Install

dotnet add package Nalix.Codec

What It Provides

Area Purpose Main types
Packet model Packet base types and runtime packet metadata PacketBase<TPacket>, FrameBase, PacketRegistry, PacketSchema
Protocol frames Built-in control, directive, handshake, key exchange, and resume frames Control, Directive, Handshake, KeyExchange, SessionResume
Serialization Source-generated binary serialization LiteSerializer, FormatterProvider, IFormatter<T>, IFillableFormatter<T>
Transform pipeline Ordered compression and encryption stages FrameTransformer, FramePipeline, FrameCompression, FrameCipher
Cryptography X25519 handshakes, envelope ciphers, hashes, and MACs HandshakeX25519, EnvelopeCipher, Keccak256, HmacKeccak256, Poly1305
Compression Pool-backed LZ4 block and stream compression LZ4BlockEncoder, LZ4Codec, LZ4Encoder, LZ4Decoder
Pooling Scoped packet allocation and object lifecycle helpers PacketScope, PacketFactory

Minimal Packet

using Nalix.Abstractions.Serialization;
using Nalix.Codec.DataFrames;

[Packet]
[GenerateFormatter]
[SerializePackable(SerializeLayout.Explicit)]
public partial class ChatMessage : PacketBase<ChatMessage>
{
    [SerializeOrder(0)]
    public string Text { get; set; } = string.Empty;

    public ChatMessage()
    {
        this.OpCode = 201;
    }
}

Serialization

byte[] encoded = LiteSerializer.Serialize(new ChatMessage { Text = "hello" });
ChatMessage decoded = LiteSerializer.Deserialize<ChatMessage>(encoded, out int bytesRead);

Design Notes

  • Hot paths use spans and pooled buffers.
  • Packet serialization is source generated instead of reflection based.
  • Cryptographic primitives live in Nalix.Codec.Security; do not replace them with application code.

Documentation