{"id":21806570,"url":"https://github.com/majimboo/c-struct","last_synced_at":"2025-10-29T22:22:55.753Z","repository":{"id":19067467,"uuid":"22294335","full_name":"majimboo/c-struct","owner":"majimboo","description":"a binary data packing \u0026 unpacking library for node.js","archived":false,"fork":false,"pushed_at":"2021-02-06T06:05:45.000Z","size":23,"stargazers_count":44,"open_issues_count":5,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T10:46:20.916Z","etag":null,"topics":["buffer","javascript","unpacking-library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/majimboo.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}},"created_at":"2014-07-26T19:16:06.000Z","updated_at":"2025-02-11T21:33:16.000Z","dependencies_parsed_at":"2022-09-26T22:10:16.784Z","dependency_job_id":null,"html_url":"https://github.com/majimboo/c-struct","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/majimboo%2Fc-struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majimboo%2Fc-struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majimboo%2Fc-struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majimboo%2Fc-struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/majimboo","download_url":"https://codeload.github.com/majimboo/c-struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565060,"owners_count":21125415,"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":["buffer","javascript","unpacking-library"],"created_at":"2024-11-27T12:20:49.982Z","updated_at":"2025-10-29T22:22:55.694Z","avatar_url":"https://github.com/majimboo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"c-struct [![Build Status](https://travis-ci.org/majimboo/c-struct.svg?branch=master)](https://travis-ci.org/majimboo/c-struct)\n========\n\n[![NPM](https://nodei.co/npm/c-struct.png?downloads=true)](https://nodei.co/npm/c-struct/)\n\nA fast binary data packing \u0026amp; unpacking library for node.js designed for multiplayer games.\n\nWhat can it do?\n---------------\n\n* 8, 16, 24, 32, 40, 48, (56 and 64*) bit unsigned integers.\n* String with length and null-terminated cstrings.\n* Boolean, nibble, float and double.\n* Big and little endianness.\n* Schema based packing and unpacking.\n* Unpack from buffer to object.\n* Pack from object to buffer.\n* Pack with default value if key isn't specified.\n\nMore\n----\n* Available via [npm](https://npmjs.org/package/c-struct).\n* Zero production dependencies.\n\nInstallation\n------------\n\n    npm install c-struct --save\n\n\u003e Execute `$ node examples/` to see the examples.\n\nUsage\n-----\n\n#### Unpacking ####\n\n    var _ = require('c-struct');\n\n    var playerSchema = new _.Schema({\n      id: _.type.uint16,\n      name: _.type.string(16),\n      hp: _.type.uint24,\n      exp: _.type.uint32,\n      status: _.type.uint8,\n      motd: _.type.string(), // null-terminated if no length\n      motw: _.type.string(), // cstring if no length\n      skills: [{\n        id: _.type.uint8,\n        name: _.type.string(32),\n        secret: _.type.uint40\n      }],\n      position: {\n        x: _.type.uint16,\n        y: _.type.uint16\n      },\n      hash: _.type.uint48\n    });\n\n    // register to cache\n    _.register('Player', playerSchema);\n\n    // object to buffer | this can be on another file\n    var buf = _.packSync('Player', {\n      id: 1,\n      name: 'Foobar',\n      hp: 1000,\n      exp: 88888888,\n      status: 100,\n      skills: [{\n        id: 1,\n        name: 'traps of thunder',\n        secret: 5151515151\n      }, {\n        id: 2,\n      }, {\n        name: 'fatal blow'\n      }, {\n        id: 3,\n        name: 'galvano strike'\n      }],\n      position: {\n        x: 102,\n        y: 351\n      },\n      motd: 'welcome',\n      motw: 'weekly',\n      hash: 99999999,\n    });\n\n#### Packing ####\n\n    var _ = require('c-struct');\n\n    var playerSchema = new _.Schema({\n      id: _.type.uint16,\n      name: _.type.string(16),\n      hp: _.type.uint24,\n      exp: _.type.uint32,\n      status: _.type.uint8,\n      motd: _.type.string(), // null-terminated if no length\n      motw: _.type.string(), // cstring if no length\n      skills: [{\n        id: _.type.uint8,\n        name: _.type.string(32),\n        secret: _.type.uint40\n      }],\n      position: {\n        x: _.type.uint16,\n        y: _.type.uint16\n      },\n      hash: _.type.uint48\n    });\n\n    // register to cache\n    _.register('Player', playerSchema);\n\n    // buffer to object | this can be on another file\n    var obj = _.unpackSync('Player', BUFFER_HERE);\n\n\nAPI\n---\n\nCurrently only unsigned values in little endian are supported\n\n    _.type.uint8    // unsigned char\n    _.type.uint16   // unsigned short\n    _.type.uint24\n    _.type.uint32   // unsigned long\n    _.type.uint40\n    _.type.uint48\n    _.type.uint56\n    _.type.uint64\n\nYou can also specify default values\n\n    _.type.u8(9999) // default value 9999\n    _.type.u16(999) // default value 999\n    _.type.u24(888) // default value 888\n    _.type.u32(777) // default value 777\n    _.type.u40(666) // default value 666\n    _.type.u48(555) // default value 555\n    _.type.u56(444) // default value 444\n    _.type.u64(333) // default value 333\n\nConfigurations\n----\n\n\u003e There is currently no configs.\n\nTODO\n----\n\n- add configurable endianness\n- add async methods\n- add signed\n- add boolean and nibble\n- add float and double\n- add benchmark\n- documentation\n- more testing\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajimboo%2Fc-struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmajimboo%2Fc-struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajimboo%2Fc-struct/lists"}