Skip to content

About

Low-allocation, UTF-8-first, polymorphic System.Text.Json serialization for the Ais.Net.Models AIS message types.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Ais.Net.Models.Json

Low-allocation, UTF-8-first, polymorphic System.Text.Json serialization for the Ais.Net.Models AIS message types.

Designed for broadcasting decoded AIS messages over byte-oriented transports such as NATS and reconstructing the concrete .NET type on receipt. Sponsored by endjin.

Package Status
Ais.Net #
Ais.Net.Models #
Ais.Net.Models.Json #
Ais.Net.Models.Json.Nats #
Ais.Net.Receiver #
Ais.Net.Receiver.Storage.Azure.Blob #

The AIS.NET project contains a series of layers, from a low-level zero allocation, high performance NMEA AIS sentence decoder, to rich high-level C# 9.0 models of AIS message types, and a receiver component that can listen to TCP streams of NMEA sentences and expose them as an IObservable<string> of raw sentences or a decoded IObservable<IAisMessage>. Ais.Net.Models.Json sits on top of Ais.Net.Models and turns the decoded messages into UTF-8 JSON and back, and Ais.Net.Models.Json.Nats is the top layer, adapting that serializer to NATS.Net so messages can be published and subscribed over NATS.

https://github.com/ais-dotnet

Features

  • Source-generated (reflection-free, trim/AOT-friendly) via System.Text.Json.
  • Polymorphic round-trip: any AisMessageBase is written with a $type discriminator (the first property) and read back as the correct concrete message type.
  • UTF-8-first, low allocation: serialize into an IBufferWriter<byte> or a reusable Utf8JsonWriter; deserialize directly from a ReadOnlySpan<byte>.
  • Enums are serialized as numbers; null values are omitted.
  • Ergonomic C# 14 extension members.
  • No NATS dependency — the transport stays a consumer concern.

Usage

using Ais.Net.Models;
using Ais.Net.Models.Json;

// Serialize to UTF-8 JSON (with a $type discriminator).
byte[] utf8 = AisMessageJson.SerializeToUtf8Bytes(message);

// ...or, lower allocation, into a buffer writer or a reusable writer:
AisMessageJson.Serialize(bufferWriter, message);

// ...or via extension members:
byte[] utf8b = message.ToJsonUtf8Bytes();

// Deserialize back into the concrete message type.
AisMessageBase? received = AisMessageJson.Deserialize(utf8);
if (received is AisMessageType18 positionReport)
{
    // ...
}

For NATS, use the dedicated Ais.Net.Models.Json.Nats package — a ready-made NATS.Net serializer and registry built on these primitives.

Building

Requires the .NET 10 SDK. Depends on the Ais.Net.Models package (1.0.0 or later).

dotnet build Solutions/Ais.Net.Models.Json.slnx -c Release

Licenses

This project is available under the Apache 2.0 open source license.

GitHub license

OpenChain

For any licensing questions, please email licensing@endjin.com

Project Sponsor

This project is sponsored by endjin, a UK based Technology Consultancy which specializes in Data & Analytics, AI & Cloud Native App Dev.

We help small teams achieve big things.

We produce three free weekly newsletters:

Keep up with everything that's going on at endjin via our blog, follow us on Twitter, YouTube or LinkedIn.

We have become the maintainers of a number of popular .NET Open Source Projects:

And we have over 50 Open Source projects of our own, spread across the following GitHub Orgs:

And the DevOps tooling we have created for managing all these projects is available on the PowerShell Gallery.

For more information about our products and services, or for commercial support of this project, please contact us.

Code of conduct

This project has adopted a code of conduct adapted from the Contributor Covenant to clarify expected behaviour in our community. This code of conduct has been adopted by many other projects. For more information see the Code of Conduct FAQ or contact hello@endjin.com with any additional questions or comments.

About

Low-allocation, UTF-8-first, polymorphic System.Text.Json serialization for the Ais.Net.Models AIS message types.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages