{"id":19647588,"url":"https://github.com/vaguue/struct-compile","last_synced_at":"2025-04-28T15:32:08.203Z","repository":{"id":215520126,"uuid":"739131018","full_name":"vaguue/struct-compile","owner":"vaguue","description":"Easily parse binary data with C structure syntax ","archived":false,"fork":false,"pushed_at":"2024-05-18T16:27:49.000Z","size":123,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T04:04:27.957Z","etag":null,"topics":["binary-parsing","javascript","javascript-parser","parser"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vaguue.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-01-04T21:01:16.000Z","updated_at":"2024-11-25T09:00:01.000Z","dependencies_parsed_at":"2024-01-27T20:24:13.091Z","dependency_job_id":"6c8be5b6-dad2-435c-ac78-c9ef64ad7ef2","html_url":"https://github.com/vaguue/struct-compile","commit_stats":null,"previous_names":["vaguue/struct-compile"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaguue%2Fstruct-compile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaguue%2Fstruct-compile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaguue%2Fstruct-compile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaguue%2Fstruct-compile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaguue","download_url":"https://codeload.github.com/vaguue/struct-compile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251338741,"owners_count":21573603,"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-parsing","javascript","javascript-parser","parser"],"created_at":"2024-11-11T14:44:34.460Z","updated_at":"2025-04-28T15:32:03.183Z","avatar_url":"https://github.com/vaguue.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# struct-compile [![codecov](https://codecov.io/github/vaguue/struct-compile/graph/badge.svg?token=RX79CQ4RME)](https://codecov.io/github/vaguue/struct-compile) [![GitHub license](https://img.shields.io/github/license/vaguue/struct-compile?style=flat)](https://github.com/vaguue/struct-compile/blob/main/LICENSE) [![npm](https://img.shields.io/npm/v/struct-compile)](https://www.npmjs.com/package/struct-compile)\n\n## Installation\n\n```bash\nnpm i struct-compile --save\n```\n\n## Overview\n\nThis project provides a convenient function to create a JavaScript class from a C structure, for further parsing or creating binary data.\n\n## System Requirements\n\n- Node.js \u003e= 16.18.0\n\n## Getting Started\n\nThe main function is `compile` with the signature: \n\n`compile(string, [arch], [BufferImpl]) =\u003e object`\n\n### Example Usage\n\n```javascript\nimport { compile } from 'struct-compile';\n\n// also available for commonJS\n// const { compile } = require('struct-compile');\n\nconst { Data, PDU } = compile(`\n  //simple example\n  struct Data {\n    uint8_t c;\n    int v;\n    unsigned long da;\n  };\n\n  //@NE Network-endiannes for all members of this struct\n  struct __attribute__((__packed__)) PDU {\n    //Some useful comment\n    char name /*in-between comment*/ [16];\n    double dbl;\n    int p;\n  };\n`);\n\n// creating objects\nconst obj = new PDU();\n\nobj.name = 'seva';\nobj.dbl = 1.1;\n\nconsole.log('PDU size: ', obj.length);\nconsole.log('PDU buffer example: ', obj.buffer);\n\n// parsing raw binary data\nconst parsed = new PDU(\n  Buffer.from([0x73, 0x65, 0x76, 0x61,\n               0x00, 0x00, 0x00, 0x00,\n               0x00, 0x00, 0x00, 0x00,\n               0x00, 0x00, 0x00, 0x00,\n               0x3f, 0xf1, 0x99, 0x99,\n               0x99, 0x99, 0x99, 0x9a,\n               0x00, 0x00, 0x00, 0x00])\n);\n\nconsole.log(parsed.name.toString());\nconsole.log(parsed.dbl);\n```\n\nThe syntax for creating structures takes into account C rules for aligning objects within a structure, and auxiliary comments help to automatically set the endianness of the field. Learn more about alignment [here](https://learn.microsoft.com/en-us/cpp/c-language/padding-and-alignment-of-structure-members) and [here](https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Type-Attributes.html).\n\n## Compatibility and Project Checklist\n\nAn important note is that the input syntax is the *subset* of the C syntax, current syntax rules can be viewed [here](https://raw.githack.com/vaguue/struct-compile/main/assets/generated_diagrams.html). \n\nThis project has been tailored with specific compatibilities and limitations. Below is a checklist highlighting the current state of support for various features:\n\n| Feature             | Supported        | Notes                                         |\n|---------------------|------------------|-----------------------------------------------|\n| Nested Structures   | ❌ No            |                                               |\n| Enums               | ❌ No            |                                               |\n| Browser Support     | ❌ No            | Currently, there is no support for browsers.  |\n| Bitfields           | ✅ Yes           |                                               |\n| C Structure Parsing | ✅ Yes           |                                               |\n| Binary Data Creation| ✅ Yes           |                                               |\n| Endianness Setting  | ✅ Yes           | Via auxiliary comments within the structure.  |\n\nPlease note that while some features like bitfields, nested structures, and enums are not currently supported, the project is continually evolving. Contributions or suggestions for these areas are welcome.\n\n\n## Questions or Suggestions\n\nIf you have any ideas, or something is not working correctly, feel free to open an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaguue%2Fstruct-compile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaguue%2Fstruct-compile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaguue%2Fstruct-compile/lists"}