{"id":26611256,"url":"https://github.com/hexarc-software/hexarc-borsh","last_synced_at":"2025-06-21T12:39:20.106Z","repository":{"id":50347838,"uuid":"456114797","full_name":"hexarc-software/hexarc-borsh","owner":"hexarc-software","description":".NET implementation of Binary Object Representation Serializer for Hashing","archived":false,"fork":false,"pushed_at":"2022-12-24T10:31:18.000Z","size":191,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T10:07:32.325Z","etag":null,"topics":["binary","blazor","blazor-webassembly","blockchain","borsh","cryptography","csharp","deserialization","dotnet","hashing","near","serialization","solana","webassembly"],"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/hexarc-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["fondify.app/to/9qjvN4GZf78M2JsLUxXUNQWnDo96s12Zzzkzoo8cFpqw"]}},"created_at":"2022-02-06T10:10:05.000Z","updated_at":"2025-01-10T06:34:51.000Z","dependencies_parsed_at":"2023-01-30T20:31:49.432Z","dependency_job_id":null,"html_url":"https://github.com/hexarc-software/hexarc-borsh","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hexarc-software/hexarc-borsh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexarc-software%2Fhexarc-borsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexarc-software%2Fhexarc-borsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexarc-software%2Fhexarc-borsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexarc-software%2Fhexarc-borsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hexarc-software","download_url":"https://codeload.github.com/hexarc-software/hexarc-borsh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexarc-software%2Fhexarc-borsh/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261126204,"owners_count":23113289,"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","blazor","blazor-webassembly","blockchain","borsh","cryptography","csharp","deserialization","dotnet","hashing","near","serialization","solana","webassembly"],"created_at":"2025-03-24T02:35:26.081Z","updated_at":"2025-06-21T12:39:15.086Z","avatar_url":"https://github.com/hexarc-software.png","language":"C#","funding_links":["fondify.app/to/9qjvN4GZf78M2JsLUxXUNQWnDo96s12Zzzkzoo8cFpqw"],"categories":[],"sub_categories":[],"readme":"# Borsh in .NET\n[![License](http://img.shields.io/:license-mit-blue.svg)](http://badges.mit-license.org) \n[![NuGet](https://img.shields.io/nuget/v/Hexarc.Borsh.svg)](https://www.nuget.org/packages/Hexarc.Borsh)\n[![Downloads](http://img.shields.io/nuget/dt/Hexarc.Borsh.svg)](https://www.nuget.org/packages/Hexarc.Borsh)\n[![Donate Solana](https://img.shields.io/static/v1?label=Fondify.app\u0026message=Donate%20%24SOL\u0026color=blueviolet)](https://fondify.app/to/9qjvN4GZf78M2JsLUxXUNQWnDo96s12Zzzkzoo8cFpqw)\n\nHexarc.Borsh is .NET implementation of the [Binary Object Representation Serializer for Hashing](https://borsh.io/) format.\n\n## Features\n* 100% C# library\n* Zero dependencies\n* Ready for Blazor WebAssembly\n\n## Supported platforms\n| .NET  | Hexarc.Borsh |\n|-------|--------------|\n| `6.x` | `1.x`        |\n| `7.x` | `2.x`        |\n\n## Getting started\n\nInstall the package with the `NuGet` CLI:\n```sh\ndotnet add package Hexarc.Borsh\n```\n\nReference the `Hexarc.Borsh` namespace in your code:\n```cs\nusing Hexarc.Borsh;\n```\n\nSerialize and deserialize .NET objects via the `BorshSerializer` class:\n```cs\n[BorshObject]\npublic sealed class Point\n{\n    [BorshPropertyOrder(0)]\n    public required Int32 X { get; init; }\n    \n    [BorshPropertyOrder(1)]\n    public required Int32 Y { get; init; }\n    \n    [BorshPropertyOrder(2)]\n    public required Int32 Z { get; init; }\n}\n\nvar point = new Point { X = 5, Y = 10, Z = 20 };\n\nvar raw = BorshSerializer.Serialize(point);\nvar restored = BorshSerializer.Deserialize\u003cPoint\u003e(raw);\n```\n\n## Serialization capabilities\nThese types can be serialized by default:\n* `Byte`, `SByte`, `Boolean`, `Int16`, `UInt16`, `Int32`, `UInt32`, `Int64`, `UInt64`, `Int128`, `UInt128`\n* `Single`, `Double`, `Half`\n* `Nullable\u003cT\u003e`\n* `Enum`\n* `String`\n* `DateTime`\n* `ValueTuple`\n* Arrays as `T[]`\n* `List\u003cT\u003e`\n* `HashSet\u003cT\u003e`\n* `Dictionary\u003cTKey, TValue\u003e`\n* `Hexarc.Borsh.Option\u003cT\u003e`\n* POCO like user defined classes\n\n### Object serialization\nSerializable types must be annotated with the `BorshObject` attribute. \nThe `BorshIgnore` attribute can be used to exclude properties from serialization.\n```cs\n[BorshObject]\npublic sealed class Point\n{\n    [BorshPropertyOrder(0)]\n    public required Int32 X { get; init; }\n    \n    [BorshPropertyOrder(1)]\n    public required Int32 Y { get; init; }\n    \n    [BorshPropertyOrder(2)]\n    public required Int32 Z { get; init; }\n    \n    // This property will be excluded from serialization.\n    [BorshIgnore]\n    public String? Memo { get; init; }\n}\n\nvar raw = BorshSerializer.Serialize(new Point { X = 1, Y = 2, Z = 3 });\n```\n\nRecords serialization:\n```cs\n[BorshObject]\npublic sealed record Rect(\n    [property: BorshPropertyOrder(0)] Int32 Width,\n    [property: BorshPropertyOrder(1)] Int32 Height\n);\n\nvar rect = new Rect(10, 20);\nvar raw = BorshSerializer.Serialize(rect);\n```\n\n### Nullable reference type serialization\nAnother important notice that Borsh is mostly designed to support the Rust\ntype system. So `null` reference values are not directly supported in .NET implementation.\nPlease use the special `BorshOptional` attribute or `Hexarc.Borsh.Option\u003cT\u003e` type for this purpose.\n\nProperty annotation example:\n```cs\n[BorshObject]\npublic sealed class PersonDetails\n{\n    [BorshPropertyOrder(0)]\n    [BorshOptional]\n    public String? FirstName { get; init; }\n\n    [BorshPropertyOrder(1)]\n    [BorshOptional]\n    public String? LastName { get; init; }\n}\n```\nIn case you need to serialize a top level nullable reference type object:\n```cs\nString? input = Console.ReadLine();\n\nvar raw = BorshSerializer.Serialize(Option\u003cString\u003e.Create(input));\nvar restored = BorshSerializer.Deserialize\u003cOption\u003cString\u003e\u003e(raw);\n```\n\n### Fixed array type serialization\nThe `BorshFixedArray` attribute allows to serialize fixed array types according \nto the Borsh specification:\n```cs\n[BorshObject]\npublic sealed class Data\n{\n    [BorshPropertyOrder(0)]\n    [BorshFixedArray(3)]\n    public required Int32[] Numbers { get; init; }\n}\n\nvar data = new Data { Numbers = new[] { 1, 2, 3 } };\nvar raw = BorshSerializer.Serialize(data);\n```\n\n### Union type serialization\nThe `BorshUnion` attribute allows to serialize union types:\n```cs\n[BorshObject]\n[BorshUnion\u003cCircle\u003e(0)]\n[BorshUnion\u003cSquare\u003e(1)]\npublic abstract class Figure {}\n\n[BorshObject]\npublic sealed class Circle : Figure\n{\n    [BorshPropertyOrder(0)]\n    public required Int32 Radius { get; init; }\n}\n\n[BorshObject]\npublic sealed class Square : Figure\n{\n    [BorshPropertyOrder(0)]\n    public required Int32 SideSize { get; init; }\n}\n\nFigure square = new Square { SideSize = 1 };\nvar raw = BorshSerializer.Serialize(square);\n```\n\n## Acknowledgments\nBuilt with JetBrains tools for [Open Source](https://jb.gg/OpenSourceSupport) projects.\n\n![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)\n\n## License\nMIT © [Hexarc Software and its contributors](https://github.com/hexarc-software)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexarc-software%2Fhexarc-borsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexarc-software%2Fhexarc-borsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexarc-software%2Fhexarc-borsh/lists"}