{"id":18814375,"url":"https://github.com/nullsoftware/ubinaryserializer","last_synced_at":"2025-10-06T23:04:42.700Z","repository":{"id":41895411,"uuid":"400315773","full_name":"nullsoftware/UBinarySerializer","owner":"nullsoftware","description":"Library that allows to serialize .NET objects to byte array (or deserialize from it).","archived":false,"fork":false,"pushed_at":"2023-01-20T07:15:59.000Z","size":157,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T23:03:36.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nullsoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-26T21:56:50.000Z","updated_at":"2024-05-02T02:28:45.000Z","dependencies_parsed_at":"2023-02-12T00:31:27.336Z","dependency_job_id":null,"html_url":"https://github.com/nullsoftware/UBinarySerializer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nullsoftware/UBinarySerializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullsoftware%2FUBinarySerializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullsoftware%2FUBinarySerializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullsoftware%2FUBinarySerializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullsoftware%2FUBinarySerializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nullsoftware","download_url":"https://codeload.github.com/nullsoftware/UBinarySerializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nullsoftware%2FUBinarySerializer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278692948,"owners_count":26029408,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-07T23:40:35.499Z","updated_at":"2025-10-06T23:04:42.672Z","avatar_url":"https://github.com/nullsoftware.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)\n\n[![](https://img.shields.io/nuget/vpre/UBinarySerializer)](https://www.nuget.org/packages/UBinarySerializer/)\n[![](https://img.shields.io/nuget/dt/UBinarySerializer)](https://www.nuget.org/packages/UBinarySerializer/)\n\n# UBinarySerializer\nFramework for data binary serialization.\n\n## Getting started.\nUse one of the follwing methods to install and use this library:\n\n- **Package Manager:**\n\n    ```batch\n    PM\u003e Install-Package UBinarySerializer\n    ```\n\n- **.NET CLI:**\n\n    ```batch\n    \u003e dotnet add package UBinarySerializer\n    ```\n----\nTo create serializer for specific object type, \nyou need to create `BinarySerializer\u003c\u003e` instance:\n```C#\nBinarySerializer\u003cMyObject\u003e serializer = new BinarySerializer\u003cMyObject\u003e();\n```\nOr to create unsafe serializer:\n```C#\nBinaryUnsafeSerializer\u003cMyObject\u003e serializer = new BinaryUnsafeSerializer\u003cMyObject\u003e();\n```\n\nThen to serialize object to binary data use `Serialize` or `SerializeObject` methods.  \n\nDifference between unsafe and safe serializers, is that **safe** serializer serializes the data safely, \nallows to serialize null-reference objects and saves object data version (generation) for backward-compatibility.  \n**Unsafe** serializer optimized for fast serialization, and disallows null-references.  \n\nTo control fields and properties during serialization use `BinIndexAttribute`:\n\n```C#\nusing System;\nusing NullSoftware.Serialization;\n\npublic class Player\n{\n    [BinIndex(0)]\n    public int Health { get; set; }\n\n    [BinIndex(1, Generation = 2)]\n    public int Hunger { get; set; }\n\n    [BinIndex(2)]\n    public Vector3 Postion { get; set; }\n\n    [BinIndex(3)]\n    public GameMode GameMode { get; set; }\n\n    [BinIndex(4)]\n    public Texture Skin { get; set; }\n\n    [BinIndex(5)]\n    public List\u003cItem\u003e Items { get; set; }\n        = new List\u003cItem\u003e();\n    \n    public int DeathsCount { get; set; } // will not be serialized.\n}\n```\n`Generation` allows to add new fields/properties for already serialized object without breaking serialization (in case if **safe** serializer was used).\nIf there is no `BinIndexAttribute` specified in object will be serialized all not-readonly fields/properties.  \n\nAlso can be used `RequiredAttribute` from `System.ComponentModel.DataAnnotations` to specify that current field/property can not have null-reference even in **safe** serialization.\n\nAlso there is possible to craete custom binary converter using `IBinaryConverter` interface, and `BinaryConverterAttribute` for target object.\n\nConverter:\n```C#\npublic class FourCharacterCodeConverter : IBinaryConverter\n{\n    public void ToBytes(MemberInfo member, BinaryWriter stream, object value, object parameter)\n    {\n        stream.Write(((FourCharacterCode)value).Value);\n    }\n\n    public object ToValue(MemberInfo member, BinaryReader stream, object parameter)\n    {\n        return new FourCharacterCode(stream.ReadBytes(4));\n    }\n}\n```\n\nConverter target:\n```C#\n[BinaryConverter(typeof(FourCharacterCodeConverter)/*,  SerializerType = typeof(BinaryUnsafeSerializer) */)]\npublic struct FourCharacterCode : IEquatable\u003cFourCharacterCode\u003e\n{\n    public byte[] Value { get; } // must be 4-bytes length\n\n    public FourCharacterCode(params byte[] value)\n    {\n        if (value == null) throw new ArgumentNullException();\n        if (value.Length != 4) throw new ArgumentOutOfRangeException();\n\n        Value = value;\n    }\n\n    public FourCharacterCode(string value)\n    {\n        if (value == null) throw new ArgumentNullException();\n        if (value.Length != 4) throw new ArgumentOutOfRangeException();\n\n        Value = Encoding.ASCII.GetBytes(value);\n    }\n\n    public override string ToString()\n    {\n        return Encoding.ASCII.GetString(Value);\n    }\n\n    public bool Equals(FourCharacterCode other)\n    {\n        return Value.SequenceEqual(other.Value);\n    }\n\n    public override bool Equals(object obj)\n    {\n        if (obj is FourCharacterCode fourCC)\n            return Equals(fourCC);\n        else\n            return false;\n    }\n\n    public override int GetHashCode()\n    {\n        return BitConverter.ToInt32(Value);\n    }\n\n    public static bool operator ==(FourCharacterCode left, FourCharacterCode right)\n    {\n        return left.Equals(right);\n    }\n\n    public static bool operator !=(FourCharacterCode left, FourCharacterCode right)\n    {\n        return !left.Equals(right);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullsoftware%2Fubinaryserializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnullsoftware%2Fubinaryserializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullsoftware%2Fubinaryserializer/lists"}