{"id":17087537,"url":"https://github.com/rzcoder/data-struct","last_synced_at":"2025-04-12T21:53:25.221Z","repository":{"id":17381041,"uuid":"20153033","full_name":"rzcoder/data-struct","owner":"rzcoder","description":"Convert between JS object and Node.js buffer","archived":false,"fork":false,"pushed_at":"2014-06-01T14:56:44.000Z","size":196,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T16:04:21.673Z","etag":null,"topics":[],"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/rzcoder.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-05-25T11:35:10.000Z","updated_at":"2023-03-10T11:53:05.000Z","dependencies_parsed_at":"2022-09-24T15:52:03.460Z","dependency_job_id":null,"html_url":"https://github.com/rzcoder/data-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/rzcoder%2Fdata-struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzcoder%2Fdata-struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzcoder%2Fdata-struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzcoder%2Fdata-struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rzcoder","download_url":"https://codeload.github.com/rzcoder/data-struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248550634,"owners_count":21122933,"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":[],"created_at":"2024-10-14T13:33:56.742Z","updated_at":"2025-04-12T21:53:25.190Z","avatar_url":"https://github.com/rzcoder.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data structure\n\nConvert between JS object and Node.js buffer with rigidly predetermined scheme.\n\n## Installing\n\n```shell\n    npm install data-struct\n```\n\n\n## Usage\n\n`require(\"data-struct\")` exports just 3 namespaces:\n\n  * `DataTypes` – dictonary of supported types:\n      * **boolean** – 1 byte\n      * **int8** – 1 byte\n      * **uint8** – 1 byte\n      * **int16** – 2 bytes\n      * **uint16** – 2 bytes\n      * **int32** – 4 bytes\n      * **uint32** – 4 bytes\n      * **float** – 4 bytes\n      * **double** – 8 bytes\n      * **string** – 2 bytes header + string bytes length (max length: 65535 bytes, **not string length!**)\n      * **shortBuffer**  – 2 bytes header  + buffer length (max length: 65535 bytes)\n      * **buffer** – 4 bytes header + buffer length (max length 4294967295 bytes)\n  * `DataReader(buffer, scheme)` – buffer -\u003e object function.\n  * `DataWriter(object, scheme)` – object -\u003e buffer function.\n\n## Example\n\n\n```javascript\n\nvar DataTypes = require(\"data-struct\").DataTypes;\nvar DataReader = require(\"data-struct\").DataReader;\nvar DataWriter = require(\"data-struct\").DataWriter;\n\nvar hero = {\n    id: 9,\n    name: 'CirnoBaka',\n    hp: 146,\n    skills: [\n        {\n            id: 34,\n            description: 'freezing frogs'\n        },\n        {\n            id: 16,\n            description: 'perfect math'\n        }\n    ],\n    playable: false,\n    experience: 99999999,\n    position: {\n        x: 2,\n        y: 3\n    }\n};\n\nvar heroScheme = {\n    id: DataTypes.uint32,\n    name: DataTypes.string,\n    hp: DataTypes.int16,\n    skills: [{\n        id: DataTypes.uint16,\n        description: DataTypes.string\n    }],\n    playable: DataTypes.boolean,\n    experience: DataTypes.uint32,\n    position: {\n        x: DataTypes.uint16,\n        y: DataTypes.uint16\n    }\n};\n\nvar heroBuf = DataWriter(hero, heroScheme);\nvar heroClone = DataReader(heroBuf, heroScheme);\n\n\n//nested arrays\nvar map = [\n    [0,1,0,0,1,1,1,1],\n    [1,1,0,0,0,1,1,1],\n    [1,1,0,0,0,0,1,1],\n    [1,1,1,1,0,0,1,1],\n    [0,1,1,0,0,0,1,1],\n    [0,0,0,0,0,1,1,1],\n    [0,0,0,0,1,1,1,1]\n];\n\nvar mapScheme = [[DataTypes.uint8]];\n\nvar mapBuf = DataWriter(map, mapScheme);\nvar mapClone = DataReader(mapBuf, mapScheme);\n```\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzcoder%2Fdata-struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frzcoder%2Fdata-struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzcoder%2Fdata-struct/lists"}