{"id":20952155,"url":"https://github.com/dimohy/GenPack","last_synced_at":"2025-05-14T04:32:03.417Z","repository":{"id":230811733,"uuid":"779101727","full_name":"dimohy/GenPack","owner":"dimohy","description":"Packet generation and serialization/deserialization library using the .NET Source Generator","archived":false,"fork":false,"pushed_at":"2024-04-12T00:54:04.000Z","size":94,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T09:50:00.636Z","etag":null,"topics":["csharp-sourcegenerator"],"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/dimohy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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-03-29T03:28:15.000Z","updated_at":"2025-04-08T17:00:24.000Z","dependencies_parsed_at":"2024-04-01T05:23:27.995Z","dependency_job_id":"6dc08a4d-de73-429d-8a69-23928eed343c","html_url":"https://github.com/dimohy/GenPack","commit_stats":null,"previous_names":["dimohy/genpack"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimohy%2FGenPack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimohy%2FGenPack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimohy%2FGenPack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimohy%2FGenPack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dimohy","download_url":"https://codeload.github.com/dimohy/GenPack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254071293,"owners_count":22009766,"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":["csharp-sourcegenerator"],"created_at":"2024-11-19T01:00:57.996Z","updated_at":"2025-05-14T04:32:03.134Z","avatar_url":"https://github.com/dimohy.png","language":"C#","readme":"\u003cimg src=\"logo.png\" width=\"128\" height=\"128\"\u003e\n\n# GenPack\n[![latest version](https://img.shields.io/nuget/v/GenPack)](https://www.nuget.org/packages/GenPack)\n[![downloads](https://img.shields.io/nuget/dt/GenPack)](https://www.nuget.org/packages/GenPack)\n\nGenPack is a library that uses the .NET source generator to automatically generate packets as classes once you define a schema for the packets.\nIt's easy to use and the results are useful.\n\nGenPack also works well with Native AOT. You can take advantage of the benefits of Native AOT.\n\n## Simple to use\n```csharp\n[GenPackable]\npublic partial record PeoplePacket\n{\n    public readonly static PacketSchema Schema = PacketSchemaBuilder.Create()\n        .@short(\"Age\", \"Age description\")\n        .@string(\"Name\", \"Name description\")\n        .Build();\n}\n```\n\nThe following code is automatically generated by the schema information.\n\n```csharp\n    public partial record PeoplePacket : GenPack.IGenPackable\n    {\n        /// \u003csummary\u003e\n        /// Age description\n        /// \u003c/summary\u003e\n        public short Age { get; set; }\n        /// \u003csummary\u003e\n        /// Name description\n        /// \u003c/summary\u003e\n        public string Name { get; set; } = string.Empty;\n        public byte[] ToPacket()\n        {\n            using var ms = new System.IO.MemoryStream();\n            ToPacket(ms);\n            return ms.ToArray();\n        }\n        public void ToPacket(System.IO.Stream stream)\n        {\n            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);\n            writer.Write(Age);\n            writer.Write(Name);\n        }\n        public static PeoplePacket FromPacket(byte[] data)\n        {\n            using var ms = new System.IO.MemoryStream(data);\n            return FromPacket(ms);\n        }\n        public static PeoplePacket FromPacket(System.IO.Stream stream)\n        {\n            PeoplePacket result = new PeoplePacket();\n            System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);\n            int size = 0;\n            byte[] buffer = null;\n            result.Age = reader.ReadInt16();\n            result.Name = reader.ReadString();\n            return result;\n        }\n    }\n```\n\nIt's simple to use. You can binary serialize with `ToPacket()` and deserialize with `FromPacket()`.\n\n```csharp\nvar p = new PeoplePacket()\n{\n    Age = 10,\n    Name = \"John\"\n};\nvar data = p.ToPacket();\nvar newP = PeoplePacket.FromPacket(data);\n\nConsole.WriteLine(newP);\n```\n\n```shell\nPeoplePacket { Age = 10, Name = John }\n```\n\n## How to create a packet schema\nDecorate the attribute of `class` or `record` with `GenPackable`. At this point, the target must be given `partial`.\nGenPack's packet schema is represented by creating a `PacketSchema` using the `PacketSchemaBuilder`.\n\n```csharp\n[GenPackable]\npublic partial record PeoplePacket\n{\n    public readonly static PacketSchema Schema = PacketSchemaBuilder.Create()\n        .@short(\"Age\", \"Age description\")\n        .@string(\"Name\", \"Name description\")\n        .Build();\n}\n```\n\nThe format beginning with `@` means the schema property to be created. For example, `@short(\"Age\", \"Age description\")` gives the `Age` property the type `short` and the description `Age description`.\nThis translates to the following,\n\n```csharp\n        /// \u003csummary\u003e\n        /// Age description\n        /// \u003c/summary\u003e\n        public short Age { get; set; }\n```\nYou can then use the auto-generated properties.\n\n```csharp\nvar p = new PeoplePacket()\np.Age = 32;\n```\n\n### Schema Properties\n| Property        | Description         | Bits | Arguments                        |\n|-----------------|---------------------|------|----------------------------------|\n| @byte           | byte                |   8  | property name, description       |\n| @sbyte          | signed byte           |   8  | property name, description       |\n| @short          | short int           |  16  | property name, description       |\n| @ushort         | unsigned short int  |  16  | property name, description       |\n| @int            | int                 |  32  | property name, description       |\n| @uint           | unsigned int        |  32  | property name, description       |\n| @long           | long int            |  64  | property name, description       |\n| @ulong          | unsigned long int   |  64  | property name, description       |\n| @float          | single float        |  32  | property name, description       |\n| @double         | double float        |  64  | property name, description       |\n| @string         | string              |   N  | property name, description       |\n| @object\\\u003ctype\\\u003e | genpackable object  |   N  | property name, description       |\n| @list\\\u003ctype\\\u003e   | variable list       |   N  | property name, description       |\n| @dict\\\u003ctype\\\u003e   | variable dictionary |   N  | property name, description       |\n| @array\\\u003ctype\\\u003e  | fixed array         |   N  | property name, size, description |\n\n## Tasks\n- [ ] Support for Endian, string Encoding.\n- [ ] Support for checksums.\n- [ ] Support 8-bit, 16-bit, 32-bit, 64-bit, or variable 7-bit sizes for `@list` and `@dict`.\n- [ ] Add `@ver` property to allow revision control of packets.\n- [ ] Automatically select and deserialize target structures based on packet command(identification code).\n- [ ] Generate JSON and gRPC schema with `PacketSchema`.\n- [ ] Process device packets with uncomplicated packet structures.\n- [ ] Process structures with complex packets, such as PLCs.\n- [ ] Process packets that require speed, such as `MemoryPack`.\n\n------\n\n\u003cimg src=\"logo.png\" width=\"32\" height=\"32\"\u003e\n\n[Icon creator: Freepik - Flaticon](https://www.flaticon.com/kr/free-icon/blocks_2021305)\n","funding_links":[],"categories":["Source Generators","Content"],"sub_categories":["Serialization","169. [GenPack](https://ignatandrei.github.io/RSCG_Examples/v2/docs/GenPack) , in the [Serializer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#serializer) category"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimohy%2FGenPack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimohy%2FGenPack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimohy%2FGenPack/lists"}