{"id":18255253,"url":"https://github.com/arklab/messagepack","last_synced_at":"2026-01-23T18:09:35.038Z","repository":{"id":31979863,"uuid":"131140956","full_name":"ARKlab/MessagePack","owner":"ARKlab","description":"Support for NodaTime types to MessagePack C#.","archived":false,"fork":false,"pushed_at":"2024-10-31T18:33:26.000Z","size":1829,"stargazers_count":7,"open_issues_count":1,"forks_count":5,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-31T19:27:17.370Z","etag":null,"topics":["c-sharp","messagepack","msgpack","nodatime","serialization"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ARKlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-26T10:42:22.000Z","updated_at":"2024-10-31T18:33:29.000Z","dependencies_parsed_at":"2024-10-20T01:14:23.663Z","dependency_job_id":"d117893c-eb8c-4c8f-9f69-72dd46e22171","html_url":"https://github.com/ARKlab/MessagePack","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ARKlab%2FMessagePack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ARKlab%2FMessagePack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ARKlab%2FMessagePack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ARKlab%2FMessagePack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ARKlab","download_url":"https://codeload.github.com/ARKlab/MessagePack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223150661,"owners_count":17095959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","messagepack","msgpack","nodatime","serialization"],"created_at":"2024-11-05T10:15:16.842Z","updated_at":"2025-11-16T14:01:21.279Z","avatar_url":"https://github.com/ARKlab.png","language":"C#","readme":"![image](./ark-dark.png)\n# MessagePack.NodaTime\n\nThis library adds support for NodaTime types to MessagePack C#.\n\n## Getting Started\n\n### Installation\n#### Prerequisities for C#\n* [MessagePack](https://www.nuget.org/packages/MessagePack/)\n* [NodaTime](https://www.nuget.org/packages/NodaTime/)\n\n\nThis library is provided in NuGet.\n\nSupport for .NET Framework 4.5, .NET Framework 4.6.1, .NET Standard 1.6 and .NET Standard 2.0.\n\nIn the Package Manager Console -\n```\nInstall-Package MessagePack.NodaTime\n```\nor download directly from NuGet.\n## How to use\nTo use the NodaTime resolver, you will have to add it to the composite resolver, as shown in the example below:\n```csharp\n CompositeResolver.RegisterAndSetAsDefault(\n                BuiltinResolver.Instance,\n                AttributeFormatterResolver.Instance,\n                SourceGeneratedFormatterResolver.Instance,\n                NodatimeResolver.Instance,\n                DynamicEnumAsStringResolver.Instance,\n                ContractlessStandardResolver.Instance\n            );\n```\n## Quick Start\nFor more information on either MessagePack or NodaTime, please follow the respective links below. \n* [MesssagePack](https://github.com/neuecc/MessagePack-CSharp/blob/master/README.md)\n* [NodaTime](https://nodatime.org/)\n\nThis is a quick guide on a basic serialization and de-serialization of a NodaTime type.\n\n```csharp\nInstant inst = new Instant();\nvar bin = MessagePackSerializer.Serialize(inst);\nvar res = MessagePackSerializer.Deserialize\u003cInstant\u003e(bin);\n// inst == res\n```\n\n## Usage\n### Supported NodaTime types\n `Insant`, `LocalTime`,  `LocalDate`,  `LocalDateTime`,`Offset`, `OffsetDateTime`, `Period` and `ZonedDateTime`\n\n### Timestamps\n#### Serialization\nAs 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.\n\nTimestamp spec can be found [here](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type).\n\nAn example of this in C# is shown below:\n```csharp\nLocalDateTime ldt = LocalDateTime.FromDateTime(DateTime.Now);\n// This date is within the range for timestamp32\n\nvar localDateTimeBinary = MessagePackSerializer.Serialize(ldt);\n// Once serialized we can expect the format to be [0xd6, -1, data] (format, extension type, data in bytes),\n// and ‘localDateTimeBinary’ to be a byte array of size 6\n```\n\n#### Deserialization\nIn the same way we can support serialization from NodaTime (eg, LocalDate) to MessagePack (timestamp), the same is applied for deserialization. \n\nFrom a timestamp, we can deserialize into a LocalDate (if time part is 0), LocalDateTime or an Instant.\n\nFrom the snippet of code in serialization, shown below is deserialization:\n```csharp\nvar res = MessagePackSerializer.Deserialize\u003cLocalDateTime\u003e(localDateTimeBinary);\n```\n:heavy_exclamation_mark: Deserializing a LocalDateTime into a LocalDate, will not work if the time value is not 0.\n\n### NodaTime serialized formats\n\u003ctable\u003e\n  \u003ctr\u003e\u003cth\u003eNodaTime type\u003c/th\u003e\u003cth\u003eSerialization format\u003c/th\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eInstant\u003c/td\u003e\u003ctd\u003eWhen 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.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eLocalDate\u003c/td\u003e\u003ctd\u003eOnce 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.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eLocalDateTime\u003c/td\u003e\u003ctd\u003eOnce 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.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eLocalTime\u003c/td\u003e\u003ctd\u003eLocalTime is serialized into an int64 (64 bit int). The int64 contains the LocalTime value in nanoseconds.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eOffset\u003c/td\u003e\u003ctd\u003eOffset is serialized into an int32 (32 bit int). The int32 contains the Offset value in seconds.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eOffsetDateTime\u003c/td\u003e\u003ctd\u003eWhen an Offset is serialized, it is split up into into the LocalDateTime and Offset parts.\nThey are then serialized using there respective formatters. \nThis means the serialized OffsetDateTime will be put into an array of 2 elements which looks like [timestamp, int32].\nThe Offset and LocalDateTime serialization is explained in the headings above.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003ePeriod\u003c/td\u003e\u003ctd\u003eWhen the NodaTime type Period is serialized, it is split into a 'fixarray'. \nFor a Period we have a 10 element array of four int32 amd six int64 respectively, represented in the order of → \nYears, Months, Weeks, Days, Hours, Minutes, Seconds, Milliseconds, Ticks, Nanoseconds.\u003c/td\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003ctd\u003eZonedDateTime\u003c/td\u003e\u003ctd\u003eA ZonedDateTime is split up into LocalDateTime, an Offset and a string representing a Zone, during serialization.\nThis means the ZonedDateTime is put into an array of 3 elements.\nEach NodaTime type is serialized using there respective formatters, \nwhile the string is serialized using the MessagePack base class into a 'fixstr'.\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n## Limitations\n### Nanoseconds\nWhile 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. \nBelow are two examples explaining this:\n```csharp\nLocalDateTime ldt = new LocalDateTime(2016, 08, 21, 0, 0, 0, 0).PlusNanoseconds(1)\n\nvar localDateTimeBinary = MessagePackSerializer.Serialize(ldt);\nvar result MessagePackSerializer.Deserialize\u003cLocalDateTime\u003e(localDateTimeBinary);\n\n// ldt != result, nanosecond accuracy is lost in process.\n```\n\n```csharp\nLocalDateTime ldt = new LocalDateTime(2016, 08, 21, 0, 0, 0, 0).PlusNanoseconds(100);\n\nvar localDateTimeBinary = MessagePackSerializer.Serialize(ldt);\nvar result = MessagePackSerializer.Deserialize\u003cLocalDateTime\u003e(localDateTimeBinary);\n\n// ldt == result, returns truncated value equal to 1 tick.\n```\n\n### UTC\nIn the base [MessagePack](https://github.com/neuecc/MessagePack-CSharp) 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.\n\n## Interoperability\nAs explained previously, we use the timestamp format for some of our serialized NodaTime types. The timestamp format is interoperable with [MessagePack for C#](https://github.com/neuecc/MessagePack-CSharp), the official [MsgPack library](https://github.com/msgpack/msgpack/blob/master/spec.md) and any other MessagePack implementations that support the extension type of -1.\n\n## Contributing\n*TBC*\n\n## Links\n* [Nuget](https://www.nuget.org/packages/MessagePack.NodaTime/)\n* [Github](https://github.com/ARKlab/MessagePack)\n* [Ark Energy](http://www.ark-energy.eu/)\n\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE.md](https://github.com/ARKlab/MessagePack/blob/master/LICENSE) file for details\n\n## Acknowledgments\n* [MessagePack for C#](https://github.com/neuecc/MessagePack-CSharp)\n* [NodaTime](https://nodatime.org/)\n* [MsgPack Spec](https://github.com/msgpack/msgpack/blob/master/spec.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farklab%2Fmessagepack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farklab%2Fmessagepack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farklab%2Fmessagepack/lists"}