{"id":13526220,"url":"https://github.com/megagrump/moonblob","last_synced_at":"2025-04-01T07:31:40.802Z","repository":{"id":215193118,"uuid":"155223120","full_name":"megagrump/moonblob","owner":"megagrump","description":"Binary serialization for moonscript + LuaJIT","archived":false,"fork":false,"pushed_at":"2024-03-13T10:44:35.000Z","size":193,"stargazers_count":30,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-02T06:19:47.490Z","etag":null,"topics":["blob","lua","luajit","moonscript","serialization"],"latest_commit_sha":null,"homepage":null,"language":"MoonScript","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/megagrump.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}},"created_at":"2018-10-29T14:12:17.000Z","updated_at":"2024-07-31T09:34:51.000Z","dependencies_parsed_at":"2024-01-03T03:59:50.252Z","dependency_job_id":"f9eae19d-19bf-4168-a4eb-2e238f13f760","html_url":"https://github.com/megagrump/moonblob","commit_stats":null,"previous_names":["megagrump/moonblob"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megagrump%2Fmoonblob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megagrump%2Fmoonblob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megagrump%2Fmoonblob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megagrump%2Fmoonblob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/megagrump","download_url":"https://codeload.github.com/megagrump/moonblob/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222709408,"owners_count":17026761,"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":["blob","lua","luajit","moonscript","serialization"],"created_at":"2024-08-01T06:01:26.555Z","updated_at":"2024-11-02T11:30:18.689Z","avatar_url":"https://github.com/megagrump.png","language":"MoonScript","funding_links":[],"categories":["Serialization"],"sub_categories":[],"readme":"# moonblob - binary serialization library\n\n## Note: If you can, use LuaJIT's [String Buffer Library](https://repo.or.cz/luajit-2.0.git/blob_plain/HEAD:/doc/ext_buffer.html) library instead. It's better designed and probably a lot faster than moonblob.\n\nmoonblob is a compact LuaJIT library written in moonscript that performs serialization into an efficient binary format. It can be used to parse arbitrary binary data, or to serialize data for efficient storage or transmission.\n\n## How to use\n\n### Writing data\n```lua\nBlobWriter = require('BlobWriter')\n\nblob = BlobWriter()\n\n-- Store raw binary data\nblob\n\t:u8(23)\n\t:number(123.45)\n\t:f32(23.0)\n\t:string('string')\n\t...\n\n-- Store Lua types\nblob\n\t:write({ key: 'value', tbl: { 1, 2, 3 } }) -- no cycles allowed!\n\t:write(23)\n\t:write(true)\n\t:write('string')\n\n-- Write data to file\nfile = io.open('filename.ext', 'wb')\nfile:write(blob:tostring())\nfile:close()\n```\n### Reading data\n```lua\nBlobReader = require('BlobReader')\n\n-- Load data from file\nfile = io.open('filename.ext', 'rb')\nblob = BlobReader(file:read('*all'))\nfile:close()\n\n-- Parse raw binary data\nu8 = blob:u8()\ns16 = blob:s16()\nstr = blob:cstring()\nfloat = blob:f32()\n...\n\n-- Read Lua types\ntbl = blob:table()\nbool = blob:bool() -- 8 bits, 0 == false\nnum = blob:number()\nstr = blob:string()\n```\n## Documentation\n\n[API reference](https://megagrump.github.io/moonblob/doc/)\n\n### Reading and writing Lua types\n\n[`BlobReader:read`](https://megagrump.github.io/moonblob/doc/classes/BlobReader.html#read) and [`BlobWriter:write`](https://megagrump.github.io/moonblob/doc/classes/BlobWriter.html#write) can be used to store Lua values along with their type. `BlobReader:read` can only read data that was previously written by `BlobWriter:write`.\n\nThese data types are supported by `BlobReader:read` and `BlobWriter:write`:\n* `number` (64 bit)\n* `string` (up to 2^32-1 bytes)\n* `boolean`\n* `table`\n* `cdata`\n\nType and length information will be added as metadata by the `write` function. Metadata overhead is 1 byte per value written for type information, and between 1 and 5 bytes per string written for length information. Tables can contain `number`, `string`, `boolean`, 'cdata', and `table` as key and value types. An error is being thrown if other types or cyclic nested tables are encountered.\n\n### Low level I/O\n\nA low level interface is provided for handling arbitrary binary data.\n\n\tnumber       -- Lua number (64 bit floating point)\n\tbool         -- boolean value (8 bits; 0 == false)\n\tstring       -- Lua string\n\ttable        -- Lua table\n\ts8  / u8     -- signed/unsigned 8 bit integer value\n\ts16 / u16    -- signed/unsigned 16 bit integer value\n\ts32 / u32    -- signed/unsigned 32 bit integer value\n\ts64 / u64    -- signed/unsigned 64 bit integer value\n\tvs32 / vu32  -- length-encoded signed/unsigned 32 bit value\n\tf32 / f64    -- 32/64 bit floating point value\n\traw          -- raw binary data (length must be specified)\n\tcstring      -- zero-terminated string\n\tarray        -- sequential table of typed values\n\tcdata        -- LuaJIT cdata\n\nTo describe the raw data format in a more concise manner, use [`BlobWriter:pack`](https://megagrump.github.io/moonblob/doc/classes/BlobWriter.html#pack) and [`BlobReader:unpack`](https://megagrump.github.io/moonblob/doc/classes/BlobReader.html#unpack). These functions work similar to `string.unpack` and `string.pack` in Lua 5.3, although some details are different (fixed instead of native data sizes; more supported data types; some features are not implemented). See [API reference](https://megagrump.github.io/moonblob/doc) for details.\n\n### Compatibility\n\nThe library was developed on and for x86 and x64 machines - other architectures are currently untested.\n\nSince moonblob uses the ffi library and C data types, it is not compatible with vanilla Lua and can only be used with LuaJIT.\n\n### License\n\nCopyright 2017-2021 megagrump\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegagrump%2Fmoonblob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmegagrump%2Fmoonblob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegagrump%2Fmoonblob/lists"}