This is a C# port of Lite³.
Note that this project is in beta status, as specifications are being defined for Lite³.
This port currently tracks upstream ac7fc19.
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>. Tryand non-Tryoverloads 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'sUtf8JsonReaderandUtf8JsonWriterinternally. - Asynchronous decode/encode using
System.IO.Pipelines'sPipeReaderandPipeWriter, respectively. - Synchronous decode/encode using
Span<byte>andSystem.Buffers.IBufferWriter<byte>, respectively.
- Uses
- Enumeration by
foreachagainst astructenumerator.
The following example using the Buffer API outputs Max Retries: 3.
var buffer = new byte[1024];
Lite3.InitializeObject(buffer, out var position);
Lite3.SetString(buffer, ref position, 0, "app_name"u8, "demo_app"u8);
Lite3.SetLong(buffer, ref position, 0, "max_retries"u8, 3);
Lite3.SetBool(buffer, ref position, 0, "debug_mode"u8, false);
var maxRetries = Lite3.GetLong(buffer, 0, "max_retries"u8);
Console.WriteLine($"Max Retries: {maxRetries}");The equivalent Context API code is below.
using var context = Lite3Context.Create();
context
.InitializeObject()
.SetString(0, "app_name"u8, "demo_app"u8)
.SetLong(0, "max_retries"u8, 3)
.SetBool(0, "debug_mode"u8, false);
var maxRetries = context.GetLong(0, "max_retries"u8);
Console.WriteLine($"Max Retries: {maxRetries}");See ContextApiExamples.cs and BufferApiExamples.cs for more examples.
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.