{"id":20999764,"url":"https://github.com/afxres/binary","last_synced_at":"2025-05-14T23:31:13.044Z","repository":{"id":44102885,"uuid":"157534169","full_name":"afxres/binary","owner":"afxres","description":"Serialization library for C# and F#.","archived":false,"fork":false,"pushed_at":"2025-05-03T15:03:00.000Z","size":2345,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-03T16:21:19.861Z","etag":null,"topics":["binary-data","csharp","dotnet","fsharp","roslyn-generator","serialization","serialization-library","source-generator"],"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/afxres.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-11-14T10:48:21.000Z","updated_at":"2025-05-03T15:00:14.000Z","dependencies_parsed_at":"2024-05-29T18:36:13.392Z","dependency_job_id":"77fbab11-735e-4bdc-921d-bf689b5d856d","html_url":"https://github.com/afxres/binary","commit_stats":{"total_commits":723,"total_committers":1,"mean_commits":723.0,"dds":0.0,"last_synced_commit":"16f5458d92a8784ccfda8d72f21f5b37a59b1f1f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afxres%2Fbinary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afxres%2Fbinary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afxres%2Fbinary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afxres%2Fbinary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afxres","download_url":"https://codeload.github.com/afxres/binary/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254248126,"owners_count":22038971,"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":["binary-data","csharp","dotnet","fsharp","roslyn-generator","serialization","serialization-library","source-generator"],"created_at":"2024-11-19T08:08:13.212Z","updated_at":"2025-05-14T23:31:07.917Z","avatar_url":"https://github.com/afxres.png","language":"C#","readme":"# Binary\n\n[![GitHub repo size](https://img.shields.io/github/repo-size/afxres/binary)](#)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/afxres/binary/dotnet-tests.yml?branch=main)](#)\n[![Coverage Status](https://coveralls.io/repos/github/afxres/binary/badge.svg?branch=main)](https://coveralls.io/github/afxres/binary?branch=main)\n\n| Package                       | Version             | Downloads             | Descriptions                 |\n| :---------------------------- | :------------------ | :-------------------- | :--------------------------- |\n| [`Mikodev.Binary`][PC]        | [![version][VC]](#) | [![downloads][IC]](#) | Main package                 |\n| [`Mikodev.Binary.FSharp`][PF] | [![version][VF]](#) | [![downloads][IF]](#) | Additional converters for F# |\n\n## Getting Started\n\n### Sample code\n\n```csharp\nusing Mikodev.Binary;\nusing System;\n\nvar generator = Generator.CreateDefault();\nvar source = new Person(\"C#\", 21);\nvar buffer = generator.Encode(source);\nvar result = generator.Decode\u003cPerson\u003e(buffer);\nConsole.WriteLine(result);\n\nrecord Person(string Name, int Age);\n```\n\n### Supported types\n\n| Category      | Details                                                                                                                                      | Comment                                  |\n| :------------ | :------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------- |\n| Primitive     | ``(U)Int(16,32,64,128)``, ``Boolean``, ``Byte``, ``Char``, ``Decimal``, ``Double``, ``Half``, ``SByte``, ``Single``, ``String``              | Default string encoding is UTF-8         |\n| Data \u0026 Time   | ``DateOnly``, ``DateTime``, ``DateTimeOffset``, ``TimeOnly``, ``TimeSpan``                                                                   |                                          |\n| Numeric       | ``BigInteger``, ``Complex``, ``Matrix3x2``, ``Matrix4x4``, ``Plane``, ``Quaternion``, ``Vector2``, ``Vector3``, ``Vector4``                  |                                          |\n| Memory        | ``T[...]``, ``Memory\u003c\u003e``, ``ReadOnlyMemory\u003c\u003e``, ``ReadOnlySequence\u003c\u003e``                                                                       |                                          |\n| Tuple         | ``KeyValuePair\u003c,\u003e``, ``Tuple\u003c...\u003e``, ``ValueTuple\u003c...\u003e``                                                                                     | Tuple can not be null                    |\n| Miscellaneous | ``BitArray``, ``BitVector32``, ``Guid``, ``IPAddress``, ``IPEndPoint``, ``Nullable\u003c\u003e``, ``PriorityQueue\u003c,\u003e``, ``Rune``, ``Uri``, ``Version`` |                                          |\n| Collection    | Implements ``IEnumerable\u003c\u003e`` and have a constructor accept ``IEnumerable\u003c\u003e`` as parameter                                                    | Stack types are explicitly not supported |\n\n### Language Features\n\n| Feature                   | JIT  | AOT  | Comment            |\n| :------------------------ | :--- | :--- | :----------------- |\n| Enumeration Types         | Yes  | Yes  | Handle as integers |\n| Anonymous Types           | Yes  |      |                    |\n| Tuple Types               | Yes  | Yes  |                    |\n| Records                   | Yes  | Yes  |                    |\n| Required Members          | Yes  | Yes  |                    |\n| Inline Arrays             | Yes  | Yes  |                    |\n| Discriminated Unions (F#) | Yes  |      |                    |\n\n### AOT Support\n\nAOT support (via source generator) is now generally available.  \nFor example, we have a data model like this:\n```csharp\nrecord Person(int Id, string Name);\n```\n\nThen create a partial type with ``SourceGeneratorContextAttribute`` and include this data model:\n```csharp\nnamespace SomeNamespace;\n\nusing Mikodev.Binary.Attributes;\n\n[SourceGeneratorContext]\n[SourceGeneratorInclude\u003cPerson\u003e]\npartial class SomeSourceGeneratorContext { }\n```\n\nThis will generate a property named ``ConverterCreators`` which contains all generated converter creators.  \nJust add those converter creators to ``IGenerator`` and it will work.\n```csharp\nvar generator = Generator.CreateAotBuilder()\n    .AddConverterCreators(SomeSourceGeneratorContext.ConverterCreators.Values)\n    .Build();\nvar converter = generator.GetConverter\u003cPerson\u003e();\nvar person = new Person(Id: 1, Name: \"Someone\");\nvar buffer = converter.Encode(person);\nvar result = converter.Decode(buffer);\nConsole.WriteLine(result.Id);   // 1\nConsole.WriteLine(result.Name); // Someone\n```\n\n## Binary Layout\n\n### Length Prefix\n\n| Leading Bit | Byte Length | Range               | Example Bytes   | Example Value |\n| :---------- | :---------- | :------------------ | :-------------- | :------------ |\n| ``0``       | ``1``       | ``0 ~ 0x7F``        | ``7F``          | ``127``       |\n| ``1``       | ``4``       | ``0 ~ 0x7FFF_FFFF`` | ``80 00 04 01`` | ``1025``      |\n\n### Object\n\nValue:\n```csharp\nnew { id = 1024, name = \"C#\" }\n```\n\nEquivalent to:\n```csharp\nnew SortedDictionary\u003cstring, object\u003e { [\"id\"] = 1024, [\"name\"] = \"C#\" }\n```\n\nBytes:\n```\n    i  d                1024\n02  69 64           04  00 04 00 00\n    n  a  m  e          C  #\n04  6e 61 6d 65     02  43 23\n```\n\n### Tuple\n\nValue:\n```csharp\n(\"Text\", 3.14F)\n```\n\nBytes:\n```\n    T  e  x  t\n04  54 65 78 74\n    3.14\n    c3 f5 48 40\n```\n\n[PC]:https://www.nuget.org/packages/Mikodev.Binary/\n[PF]:https://www.nuget.org/packages/Mikodev.Binary.FSharp/\n[VC]:https://img.shields.io/nuget/vpre/Mikodev.Binary\n[VF]:https://img.shields.io/nuget/vpre/Mikodev.Binary.FSharp\n[IC]:https://img.shields.io/nuget/dt/Mikodev.Binary\n[IF]:https://img.shields.io/nuget/dt/Mikodev.Binary.FSharp\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafxres%2Fbinary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafxres%2Fbinary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafxres%2Fbinary/lists"}