Skip to content

Repository files navigation

Lite³: A JSON-Compatible Zero-Copy Serialization Format

NuGet

This is a C# port of Lite³.

Current Status

Note that this project is in beta status, as specifications are being defined for Lite³.

This port currently tracks upstream ac7fc19.

Feature Parity

This port includes two APIs, which correspond closely to the C impementation:

  • Buffer API: for working directly against fixed Span<byte> buffers.
  • Context API: for working against a resizable buffer, which is internally managed by ArrayPool<byte>.
  • Try and non-Try overloads for exceptionless use if desired.

These APIs are supported by a Source Generator against the core implementation, which closely matches the reference C implementation.

Additionally, feature-parity is provided in general, with additional features specific to .NET.

  • JSON decoding and encoding
    • Uses System.Text.Json's Utf8JsonReader and Utf8JsonWriter internally.
    • Asynchronous decode/encode using System.IO.Pipelines's PipeReader and PipeWriter, respectively.
    • Synchronous decode/encode using Span<byte> and System.Buffers.IBufferWriter<byte>, respectively.
  • Enumeration by foreach against a struct enumerator.

Code Example

The following example using the Buffer API outputs Max Retries: 3.

varbuffer=newbyte[1024];Lite3.InitializeObject(buffer,outvarposition);Lite3.SetString(buffer,refposition,0,"app_name"u8,"demo_app"u8);Lite3.SetLong(buffer,refposition,0,"max_retries"u8,3);Lite3.SetBool(buffer,refposition,0,"debug_mode"u8,false);varmaxRetries=Lite3.GetLong(buffer,0,"max_retries"u8);Console.WriteLine($"Max Retries: {maxRetries}");

The equivalent Context API code is below.

usingvarcontext=Lite3Context.Create();context.InitializeObject().SetString(0,"app_name"u8,"demo_app"u8).SetLong(0,"max_retries"u8,3).SetBool(0,"debug_mode"u8,false);varmaxRetries=context.GetLong(0,"max_retries"u8);Console.WriteLine($"Max Retries: {maxRetries}");

See ContextApiExamples.cs and BufferApiExamples.cs for more examples.

Attribution

This project is a C# port of the original Lite³ C implementation by Elias de Jong. All credit for the original design belongs to the original authors.

About

C# port of Lite³, a JSON-compatible zero-copy serialization format.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages