MessagePack.NodaTime 3.5.8

dotnet add package MessagePack.NodaTime --version 3.5.8
                    
NuGet\Install-Package MessagePack.NodaTime -Version 3.5.8
                    
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="MessagePack.NodaTime" Version="3.5.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MessagePack.NodaTime" Version="3.5.8" />
                    
Directory.Packages.props
<PackageReference Include="MessagePack.NodaTime" />
                    
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 MessagePack.NodaTime --version 3.5.8
                    
#r "nuget: MessagePack.NodaTime, 3.5.8"
                    
#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 MessagePack.NodaTime@3.5.8
                    
#: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=MessagePack.NodaTime&version=3.5.8
                    
Install as a Cake Addin
#tool nuget:?package=MessagePack.NodaTime&version=3.5.8
                    
Install as a Cake Tool

image

MessagePack.NodaTime

This library adds support for NodaTime types to MessagePack C#.

Getting Started

Installation

Prerequisities for C#

This library is provided in NuGet.

Support for .NET Framework 4.5, .NET Framework 4.6.1, .NET Standard 1.6 and .NET Standard 2.0.

In the Package Manager Console -

Install-Package MessagePack.NodaTime

or download directly from NuGet.

How to use

To use the NodaTime resolver, you will have to add it to the composite resolver, as shown in the example below:

 CompositeResolver.RegisterAndSetAsDefault(
                BuiltinResolver.Instance,
                AttributeFormatterResolver.Instance,
                SourceGeneratedFormatterResolver.Instance,
                NodatimeResolver.Instance,
                DynamicEnumAsStringResolver.Instance,
                ContractlessStandardResolver.Instance
            );

Quick Start

For more information on either MessagePack or NodaTime, please follow the respective links below.

This is a quick guide on a basic serialization and de-serialization of a NodaTime type.

Instant inst = new Instant();
var bin = MessagePackSerializer.Serialize(inst);
var res = MessagePackSerializer.Deserialize<Instant>(bin);
// inst == res

Usage

Supported NodaTime types

Insant, LocalTime, LocalDate, LocalDateTime,Offset, OffsetDateTime, Period and ZonedDateTime

Timestamps

Serialization

As per the MessagePack spec, when we serialize a NodaTime type of LocalDateTime, LocalDate or Instant, an extension type of -1 is received meaning it is a MessagePack timestamp.

Timestamp spec can be found here.

An example of this in C# is shown below:

LocalDateTime ldt = LocalDateTime.FromDateTime(DateTime.Now);
// This date is within the range for timestamp32

var localDateTimeBinary = MessagePackSerializer.Serialize(ldt);
// Once serialized we can expect the format to be [0xd6, -1, data] (format, extension type, data in bytes),
// and ‘localDateTimeBinary’ to be a byte array of size 6
Deserialization

In the same way we can support serialization from NodaTime (eg, LocalDate) to MessagePack (timestamp), the same is applied for deserialization.

From a timestamp, we can deserialize into a LocalDate (if time part is 0), LocalDateTime or an Instant.

From the snippet of code in serialization, shown below is deserialization:

var res = MessagePackSerializer.Deserialize<LocalDateTime>(localDateTimeBinary);

❗ Deserializing a LocalDateTime into a LocalDate, will not work if the time value is not 0.

NodaTime serialized formats

<table> <tr><th>NodaTime type</th><th>Serialization format</th></tr> <tr><td>Instant</td><td>When an Instant is serialized, like LocalDateTime and LocalDate, it goes to timestamp format. Depending on the value of the Instant, it will fall into either timestamp 32, 64, or 96 format, as explained above under the Timestamp heading.</td></tr> <tr><td>LocalDate</td><td>Once a LocalDate is serialized it is in timestamp format. Depending on the value of the LocalDate, it will fall into either timestamp 32, 64 or 96. LocalDate has no time values.</td></tr> <tr><td>LocalDateTime</td><td>Once a LocalDate is serialized it is in timestamp format. This means an extension type of -1 will be received by MessagePack. LocalDateTime can be deserialized into a LocalDate if it has no time part.</td></tr> <tr><td>LocalTime</td><td>LocalTime is serialized into an int64 (64 bit int). The int64 contains the LocalTime value in nanoseconds.</td></tr> <tr><td>Offset</td><td>Offset is serialized into an int32 (32 bit int). The int32 contains the Offset value in seconds.</td></tr> <tr><td>OffsetDateTime</td><td>When an Offset is serialized, it is split up into into the LocalDateTime and Offset parts. They are then serialized using there respective formatters. This means the serialized OffsetDateTime will be put into an array of 2 elements which looks like [timestamp, int32]. The Offset and LocalDateTime serialization is explained in the headings above.</td></tr> <tr><td>Period</td><td>When the NodaTime type Period is serialized, it is split into a 'fixarray'. For a Period we have a 10 element array of four int32 amd six int64 respectively, represented in the order of → Years, Months, Weeks, Days, Hours, Minutes, Seconds, Milliseconds, Ticks, Nanoseconds.</td></tr> <tr><td>ZonedDateTime</td><td>A ZonedDateTime is split up into LocalDateTime, an Offset and a string representing a Zone, during serialization. This means the ZonedDateTime is put into an array of 3 elements. Each NodaTime type is serialized using there respective formatters, while the string is serialized using the MessagePack base class into a 'fixstr'.</td></tr> </table>

Limitations

Nanoseconds

While NodaTime supports nanoseconds accuracy, we currently do not. The lowest common level of precision between us and NodaTime is ticks. This means our serialization and deserialization process truncates at 100 nanoseconds because 100ns = 1 tick. Below are two examples explaining this:

LocalDateTime ldt = new LocalDateTime(2016, 08, 21, 0, 0, 0, 0).PlusNanoseconds(1)

var localDateTimeBinary = MessagePackSerializer.Serialize(ldt);
var result MessagePackSerializer.Deserialize<LocalDateTime>(localDateTimeBinary);

// ldt != result, nanosecond accuracy is lost in process.
LocalDateTime ldt = new LocalDateTime(2016, 08, 21, 0, 0, 0, 0).PlusNanoseconds(100);

var localDateTimeBinary = MessagePackSerializer.Serialize(ldt);
var result = MessagePackSerializer.Deserialize<LocalDateTime>(localDateTimeBinary);

// ldt == result, returns truncated value equal to 1 tick.

UTC

In the base MessagePack library, DateTime values are converted to UTC before being serialized. While using our library, you must specify DateTimeKind as UTC before serializing when using DateTime and the LocalDateTime type, and expect it as UTC when deserializing.

Interoperability

As explained previously, we use the timestamp format for some of our serialized NodaTime types. The timestamp format is interoperable with MessagePack for C#, the official MsgPack library and any other MessagePack implementations that support the extension type of -1.

Contributing

TBC

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

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 is compatible.  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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on MessagePack.NodaTime:

Package Downloads
Ark.Tools.Http

Core tools around Flurl and HttpClient

Ark.Tools.FtpClient.FtpProxy

Implementation of FtpClient.Core based on Ark.FtpProxy service

Artesian.SDK

Artesian SDK library

Ark.Tools.Reqnroll

Reqnroll utilities

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.5.8 26 9/19/2026
3.5.7 10,840 8/12/2026
3.5.6 10,561 7/15/2026
3.5.5 10,786 6/22/2026
3.5.4 93,192 4/24/2026
3.5.3 5,163 3/13/2026
3.5.2 39,381 1/23/2026
3.5.1 6,268 12/11/2025
3.5.0 2,589 11/16/2025
3.4.4 288,977 6/18/2025
3.4.3 31,832 3/23/2025
3.4.2 7,073 12/26/2024
3.4.1 868 12/12/2024
3.4.0 373 12/12/2024
3.3.2 88,244 11/19/2024
3.3.1 87,529 10/17/2024
3.3.0 6,732 10/13/2024
3.2.2 11,466 8/12/2024
3.2.1 139,560 11/13/2023
3.2.0 114,347 9/4/2023
Loading failed

chore: update base libraries
feat: add support for nullable