{"id":18349822,"url":"https://github.com/zash/lua-cbor","last_synced_at":"2025-04-06T09:32:18.566Z","repository":{"id":77554072,"uuid":"147011194","full_name":"Zash/lua-cbor","owner":"Zash","description":"Lua implementation of the CBOR serialization format","archived":false,"fork":false,"pushed_at":"2024-09-14T14:09:44.000Z","size":105,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-21T21:51:13.119Z","etag":null,"topics":["cbor","lua"],"latest_commit_sha":null,"homepage":"https://www.zash.se/lua-cbor.html","language":"Lua","has_issues":false,"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/Zash.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2018-09-01T15:43:24.000Z","updated_at":"2025-03-04T23:23:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"d96bfd3d-ae8e-4a51-87c2-73c61a5a5f8d","html_url":"https://github.com/Zash/lua-cbor","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zash%2Flua-cbor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zash%2Flua-cbor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zash%2Flua-cbor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zash%2Flua-cbor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zash","download_url":"https://codeload.github.com/Zash/lua-cbor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247463745,"owners_count":20942935,"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":["cbor","lua"],"created_at":"2024-11-05T21:23:52.308Z","updated_at":"2025-04-06T09:32:18.310Z","avatar_url":"https://github.com/Zash.png","language":"Lua","readme":"Lua-CBOR\n========\n\nLua-CBOR is a (mostly) pure Lua implementation of the\n[CBOR](http://cbor.io/), a compact data serialization format,\ndefined in [RFC 7049](http://tools.ietf.org/html/rfc7049).\nIt supports Lua 5.1 until 5.4 and will utilize struct packing\nand bitwise operations if available.\n\nInstalling\n----------\n\nLua-CBOR can be installed using [LuaRocks](https://luarocks.org/):\n\n    luarocks install lua-cbor\n\nSources are available from \u003chttps://code.zash.se/lua-cbor/\u003e.\n\n### Optional dependencies\n\n-   Struct library compatible with [`string.pack` and `string.unpack`\n    from Lua 5.3](http://www.lua.org/manual/5.3/manual.html#6.4.2), such\n    as \u003chttp://www.inf.puc-rio.br/~roberto/struct/\u003e.\n-   Bitwise operators compatible with\n    [those in LuaJIT](http://bitop.luajit.org/) or\n    [Lua 5.2](https://luarocks.org/modules/siffiejoe/bit32).\n\nAPI\n---\n\nLua-CBOR has a similar API to many other serialization libraries, like\nLua-CJSON.\n\n### `cbor.encode(object[, options])`\n\n`cbor.encode` encodes `object` into its CBOR representation and returns\nthat as a string.\n\nOptionally, a table `options` may be supplied, containing a mapping of\nmetatables to custom encoder functions for tables and userdata. Such\nfunctions should return an encoded CBOR data string.\n\n### `cbor.decode(string[, options])`\n\n`cbor.decode` decodes CBOR encoded data from `string` and returns a Lua\nvalue.\n\nThe optional table `options` may contain callbacks for semantic types\nand simple values encountered during decoding. Simple values use the\nfield `simple` and semantic tagged types use integer indices.\n\n### `cbor.decode_file(file[, options)`\n\n`cbor.decode_file` behaves like `cbor.decode` but reads from a Lua file\nhandle instead of a string. It can also read from anything that behaves\nlike a file handle, i.e. exposes an `:read(bytes)` method.\n\n### `cbor.simple(value, name, [cbor])`\n\n`cbor.simple` creates an object representing a [\"simple\" value][simple],\nwhich are small (up to 255) named integers.\n\nTwo such values are pre-defined:\n\n* `cbor.null` is used to represent the null value.\n* `cbor.undefined` is used to represent the undefined value.\n\n[simple]: http://tools.ietf.org/html/rfc7049#section-2.3\n\n### `cbor.tagged(tag, value)`\n\n`cbor.tagged` creates an object representing a [\"tagged\" value][tagged],\nwhich is an integer attached to a value, which can be any value.\n\n[tagged]: http://tools.ietf.org/html/rfc7049#section-2.4\n\n### `cbor.type_encoders`\n\nA table containing functions for serializing each Lua type, and a few\nwithout direct Lua equivalents.\n\n`number`\n:   Encodes as `integer` or `float` depending on the value.\n\n`integer`\n:   Encodes an integer.\n\n`float`\n:   Encodes a IEEE 754 Double-Precision Float, the default Lua number type until 5.3.\n\n`string`\n:   Encodes a Lua string as a CBOR byte string, or an UTF-8 string if it\n    appars as such to the Lua 5.3 function `utf8.len`.\n\n`boolean`\n:   Encodes a boolean value.\n\n`table`\n:   Encodes a Lua table either as a CBOR array or map. If it sees\n    succesive integer keys when iterating using `pairs`, it will return an array,\n    otherwise a map.\n\n`array`\n:   Encodes a Lua table as a CBOR array. Uses `ipairs` internally so the\n    resulting array will end at the first `nil`.\n\n`map`\n:   Encodes a Lua table as a CBOR map, without guessing if it should be an array.\n\n`ordered_map`\n:   Encodes a Lua table as a CBOR map, with ordered keys. Order can be\n    specified by listing them with incrementing integer keys, otherwise\n    the default sort order is used.\n\nCustom serialization\n--------------------\n\nTables and userdata types that have a metatable may invoke custom\nserialization, either by placing a callback in the optional `options`\nargument, or via a `__tocbor` metatable field.\n\nThis can be composed from fields in `cbor.type_encoders`.\n\nSome examples::\n\n```lua\n-- using options:\n\nlocal array_mt = { __name = \"array\" }\n\nlocal myarray = setmetatable({1, 2, 3, nil, foo= \"bar\" }, array_mt);\nlocal options = {\n    [array_mt] = cbor.type_encoders.array\n}\n\ncbor.encode(myarray, options);\n\n-- or using a __tocbor metatable field\n\nlocal array_mt = { __tocbor = cbor.type_encoders.array }\n\ncbor.encode(setmetatable({1, 2, 3, nil, foo= \"bar\" }, array_mt));\n\nlocal ordered_map_mt = { __tocbor = cbor.type_encoders.ordered_map }\n\ncbor.encode(setmetatable({ foo = \"hello\", bar = \"world\", \"foo\", \"bar\" }, array_mt));\n```\n\nBignum support\n--------------\n\nLua-CBOR has optional support for bignums, using\n[luaossl](http://www.25thandclement.com/~william/projects/luaossl.html).\n\n```lua\nlocal cbor = require\"cbor\";\nlocal bignum = require\"openssl.bignum\";\nrequire\"cbor.bignum\";\n\nio.write(cbor.encode(bignum.new(\"9000\")));\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzash%2Flua-cbor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzash%2Flua-cbor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzash%2Flua-cbor/lists"}