{"id":22694416,"url":"https://github.com/akopetsch/byteserialization","last_synced_at":"2026-05-01T15:34:02.331Z","repository":{"id":241396203,"uuid":"806649073","full_name":"akopetsch/ByteSerialization","owner":"akopetsch","description":"A declarative serialization library designed for bit-level control over binary representation.  You can define C# classes like C structs by assigning attributes to classes and properties.  Inspired by BinarySerializer by Jeff Haynes. ","archived":false,"fork":false,"pushed_at":"2025-01-30T17:46:35.000Z","size":175,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T17:31:45.841Z","etag":null,"topics":["binary","buffer","csharp","dotnet","library","serialization","structure"],"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/akopetsch.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}},"created_at":"2024-05-27T15:52:44.000Z","updated_at":"2025-01-30T22:04:05.000Z","dependencies_parsed_at":"2024-06-21T13:44:07.624Z","dependency_job_id":"8bbd0192-22b4-4b7f-a77a-951b78a99361","html_url":"https://github.com/akopetsch/ByteSerialization","commit_stats":null,"previous_names":["akopetsch/byteserialization"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/akopetsch/ByteSerialization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akopetsch%2FByteSerialization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akopetsch%2FByteSerialization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akopetsch%2FByteSerialization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akopetsch%2FByteSerialization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akopetsch","download_url":"https://codeload.github.com/akopetsch/ByteSerialization/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akopetsch%2FByteSerialization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32503197,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["binary","buffer","csharp","dotnet","library","serialization","structure"],"created_at":"2024-12-10T03:08:04.854Z","updated_at":"2026-05-01T15:34:02.275Z","avatar_url":"https://github.com/akopetsch.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ByteSerialization\n\n[![NuGet](https://img.shields.io/nuget/vpre/ByteSerialization)](https://nuget.org/packages/ByteSerialization)\n\nA declarative serialization library designed for bit-level control over binary representation. \nYou can define C# classes like C structs by assigning attributes to classes and properties. \nInspired by [BinarySerializer](https://github.com/jefffhaynes/BinarySerializer) by Jeff Haynes. \n\nThis library was created from the ground up to support features like references/pointers.\n\nNotably, this libary is used by [swe1r-assets](https://github.com/akopetsch/swe1r-assets).\n\n## Example\n\nConsider the following classes:\n\n```csharp\npublic class Manufacturer\n{\n    [Order(0)]\n    public byte NameLength { get; set; }\n    [Order(1), Length(nameof(NameLength))]\n    public char[] Name { get; set; }\n}\n\npublic class Car\n{\n    [Order(0)]\n    public byte NameLength { get; set; }\n    [Order(1), Length(nameof(NameLength))]\n    public char[] Name { get; set; }\n    [Order(2), Reference]\n    public Manufacturer Manufacturer { get; set; }\n}\n```\n\nCreate an object graph like this:\n\n```csharp\nvar mf = new Manufacturer() { NameLength = 2, Name = \"MF\".ToArray() };\nvar car = new Car() { NameLength = 4, Name = \"Car1\".ToArray(), Manufacturer = mf };\nusing (var ms = new MemoryStream())\n{\n    new ByteSerializer().Serialize(ms, car, Endianness.BigEndian);\n    File.WriteAllBytes(\"car.bin\", ms.ToArray());\n}\n```\n\nThat gives you the following binary output:\n\n```console\n$ xxd car.bin\n00000000: 0443 6172 3100 0000 0902 4d46            .Car1.....MF\n```\n\n| Bytes       | Property         | Value             |\n|-------------|------------------|-------------------|\n| 04          | car.NameLength   | 4                 |\n| 43 61 72 31 | car.Name         | \"Car1\" in ASCII   |\n| 00 00 00 09 | car.Manufacturer | (pointer to mf)   |\n| 02          | mf.NameLength    | 2                 |\n| 4d 46       | mf.Name          | \"MF\" in ASCII     |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakopetsch%2Fbyteserialization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakopetsch%2Fbyteserialization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakopetsch%2Fbyteserialization/lists"}