{"id":15049469,"url":"https://github.com/mparolari/xpacket","last_synced_at":"2026-04-01T17:20:19.000Z","repository":{"id":89825919,"uuid":"111228591","full_name":"MParolari/xpacket","owner":"MParolari","description":"XPacket is an utility that generates a C struct and two functions for serialize/deserialize it into/from a given payload.","archived":false,"fork":false,"pushed_at":"2018-02-18T18:13:38.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T21:17:50.830Z","etag":null,"topics":["c","c89","cpp","serialization","serialization-library"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MParolari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING.LESSER","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":"2017-11-18T18:22:13.000Z","updated_at":"2022-02-25T16:21:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b06aaa8-d297-4975-b796-d05ddb2374bc","html_url":"https://github.com/MParolari/xpacket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MParolari%2Fxpacket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MParolari%2Fxpacket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MParolari%2Fxpacket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MParolari%2Fxpacket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MParolari","download_url":"https://codeload.github.com/MParolari/xpacket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243510126,"owners_count":20302294,"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":["c","c89","cpp","serialization","serialization-library"],"created_at":"2024-09-24T21:20:37.617Z","updated_at":"2025-12-27T21:47:04.942Z","avatar_url":"https://github.com/MParolari.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XPacket\nXPacket is an utility that generates a C struct and two functions\nfor serialize/deserialize it into/from a given payload.\n\nVersion 0.3, 02/2018.\n\nDistributed under the GNU Lesser General Public License version 3.\n\n### Bugs, warnings and todos\nWarnings:\n* Macro conflicts are possible.\n* If more arguments are used than needed, behavior is undefined.\n\nTodos and possible improvements (in random order):\n* Add an automatic delimiter (like '\\0') to the arrays\n* Check number of arguments in overloading macro.\n* Signed type marshalling.\n* Graceful error handling.\n* Enable/disable inline attribute.\n\n### Description\n\nXPacket is an utility that generates a C struct and two functions\nfor serialize/deserialize it into/from a given payload.\n\nWhen xpacket.h is included, preprocessor uses XPACKET\\_NAME and\nXPACKET\\_STRUCT macro for generate the structure; if these two mandatory\nmacro are not defined when the header is included, a compile-time\nerror is fired.\nInstead the two functions are generated only if the macro XPACKET\\_C is\ndefined (and the structure is valid).\n\nXPACKET\\_NAME is simply the name of the structure, while\nXPACKET\\_STRUCT is the list of fields.\nDifferent types of field are supported:\n* FIELD(type, name, [dim]): a simple variable,\nor an array if \"dim\" argument is given.\n* FIELD\\_PTR(type, name, [dim]): a pointer to a variable;\nor a pointer to an array if \"dim\" argument is given.\n\nOnly unsigned types are currently supported: uint8\\_t, uint16\\_t, uint32\\_t\nfrom stdint.h header, that are supposed to have fixed size (operator\nsizeof is used at compile time).\n\nFor example:\n```c\n#define XPACKET_NAME msg\n#define XPACKET_STRUCT \\\n  FIELD(uint16_t, a) \\\n  FIELD(uint8_t, b, 32) \\\n  FIELD_PTR(uint32_t, c)\n#include \u003cxpacket.h\u003e\n```\ngenerates:\n```c\nstruct msg {\n  uint16_t a;\n  uint8_t b[32];\n  uint32_t* c;\n};\nuint16_t serialize_msg(uint8_t*, const struct msg*);\nuint16_t deserialize_msg(const uint8_t*, struct msg*);\n```\n\nA decent compiler is necessary for optimize (roll/unroll) the loops.\nAttributes (such as \\_\\_attribute\\_\\_((\\_\\_packed\\_\\_))) can be assigned to\nthe structure by simply adding them before include xpacket.h.\n\nThe two functions are defined only if macro XPACKET\\_C is defined;\nin this way struct and functions declaration can be easily separeted\nin an header, while the definitions are placed in a C file.\n\nIf the XPACKET\\_OVERLOADING macro is defined, the functions will be\nsimply called \"serialize\" and \"deserialize\"; while this may generate\nname conflicts in the C language, in C++ overloading can solve the\npossible ambiguity.\n\nThe macros can be safely undefined after the header inclusion;\nit's a common practice redefine their values for include the xpacket\nheader again, in order to generate another different structure\nand their corresponding functions.\n\nIn alternative, the preprocessor can usually run as standalone\n(option -E with gcc) and generate the C code only once.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmparolari%2Fxpacket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmparolari%2Fxpacket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmparolari%2Fxpacket/lists"}