{"id":20438811,"url":"https://github.com/neoxic/lua-amf3","last_synced_at":"2025-04-12T22:41:26.290Z","repository":{"id":3648568,"uuid":"4716235","full_name":"neoxic/lua-amf3","owner":"neoxic","description":"AMF3 encoding/decoding module for Lua","archived":false,"fork":false,"pushed_at":"2021-05-05T22:51:06.000Z","size":108,"stargazers_count":34,"open_issues_count":0,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-26T16:48:07.838Z","etag":null,"topics":["amf3","lua"],"latest_commit_sha":null,"homepage":"","language":"C","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/neoxic.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":"2012-06-19T16:34:23.000Z","updated_at":"2024-11-01T22:11:46.000Z","dependencies_parsed_at":"2022-08-19T04:21:41.671Z","dependency_job_id":null,"html_url":"https://github.com/neoxic/lua-amf3","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxic%2Flua-amf3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxic%2Flua-amf3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxic%2Flua-amf3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxic%2Flua-amf3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neoxic","download_url":"https://codeload.github.com/neoxic/lua-amf3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643045,"owners_count":21138353,"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":["amf3","lua"],"created_at":"2024-11-15T09:13:28.700Z","updated_at":"2025-04-12T22:41:26.269Z","avatar_url":"https://github.com/neoxic.png","language":"C","readme":"AMF3 encoding/decoding module for Lua\n=====================================\n\n[lua-amf3] provides fast AMF3 encoding/decoding routines for Lua:\n- Support for inline data transformation/filtering via metamethods/handlers.\n- Additional binary packing/unpacking routines.\n- Written in C with 32/64-bit little/big-endian awareness.\n- No external dependencies.\n\n\n### amf3.encode(value, [event])\nReturns a binary string containing an AMF3 representation of `value`. Optional `event` may be used\nto specify a metamethod name (default is `__toAMF3`) that is called for every processed value. The\nvalue returned by the metamethod is used instead of the original value.\n\nA table (root or nested) is encoded into a dense array if it has a field `__array` whose value is\n_true_. The length of the resulting array can be adjusted by storing an integer value in that field.\nOtherwise, it is assumed to be equal to the raw length of the table.\n\n### amf3.decode(data, [pos], [handler])\nReturns the value encoded in `data` along with the index of the first unread byte. Optional `pos`\nmarks where to start reading in `data` (default is 1). Optional `handler` is called for each new\ntable (root or nested), and its return value is used instead of the original table.\n\nWhen an array is decoded, its length is stored in a field `__array`. When an object is decoded,\nfields `__class` (class name) and `__data` (externalizable data) are set depending on its type.\n\n### amf3.pack(fmt, ...)\nReturns a binary string containing the values `...` packed according to the format string `fmt`.\nA format string is a sequence of the following options:\n- `b`: an unsigned byte;\n- `i`: a signed integer packed as a U29 value;\n- `I`: a signed integer packed as a U32 value;\n- `u`: an unsigned integer packed as a U29 value;\n- `U`: an unsigned integer packed as a U32 value;\n- `f`: a number packed as a 32-bit IEEE-754 single precision value;\n- `d`: a number packed as a 64-bit IEEE-754 double precision value;\n- `s`: a string preceded by its length packed as a U29 value;\n- `S`: a string preceded by its length packed as a U32 value;\n\n| Format                | Length | Signed range    | Unsigned range |\n|-----------------------|--------|-----------------|----------------|\n| U29 (variable length) | 1 .. 4 | -2^28 .. 2^28-1 | 0 .. 2^29-1    |\n| U32 (fixed length)    | 4      | -2^31 .. 2^31-1 | 0 .. 2^32-1    |\n\nAll numeric data is stored as big-endian. All integral options check overflows.\n\n### amf3.unpack(fmt, data, [pos])\nReturns the values packed in `data` according to the format string `fmt` (see above) along with the\nindex of the first unread byte. Optional `pos` marks where to start reading in `data` (default is 1).\n\n### amf3.null\nA Lua value that represents AMF3 Null.\n\n\nBuilding and installing with LuaRocks\n-------------------------------------\n\nTo build and install, run:\n\n    luarocks make\n\nTo install the latest release using [luarocks.org], run:\n\n    luarocks install lua-amf3\n\n\nBuilding and installing with CMake\n----------------------------------\n\nTo build and install, run:\n\n    cmake .\n    make\n    make install\n\nTo build for a specific Lua version, set `USE_LUA_VERSION`. For example:\n\n    cmake -D USE_LUA_VERSION=5.1 .\n\nor for LuaJIT:\n\n    cmake -D USE_LUA_VERSION=jit .\n\nTo build in a separate directory, replace `.` with a path to the source.\n\n\nGetting started\n---------------\n\n```Lua\nlocal amf3 = require 'amf3'\n\n-- Helpers\nlocal function encode_decode(val, ev, h)\n    return amf3.decode(amf3.encode(val, ev), nil, h)\nend\nlocal function pack_unpack(fmt, ...)\n    return amf3.unpack(fmt, amf3.pack(fmt, ...))\nend\n\n-- Primitive types\nassert(encode_decode(nil) == nil)\nassert(encode_decode(amf3.null) == amf3.null)\nassert(encode_decode(false) == false)\nassert(encode_decode(true) == true)\nassert(encode_decode(123) == 123)\nassert(encode_decode(123.456) == 123.456)\nassert(encode_decode('abc') == 'abc')\n\n-- Complex types\nlocal data = {\n    obj = { -- A table with only string keys translates into an object\n        str = 'abc',\n        len = 3,\n        val = -10.2,\n        null = amf3.null,\n    },\n    dict = { -- A table with mixed keys translates into a dictionary\n        [-1] = 2,\n        [-1.2] = 3.4,\n        abc = 'def',\n        [amf3.null] = amf3.null,\n        [{a = 1}] = {b = 2}, -- A table can be a key\n    },\n    arr1 = {__array = true, 1, 2, 3}, -- A table with a field '__array' translates into an array\n    arr2 = {__array = 5, nil, 2, nil, 4, nil}, -- Array length can be adjusted to form a sparse array\n}\ndata[data] = data -- All kinds of circular references are safe\n\nlocal out = encode_decode(data)\nassert(out[out].obj.str == 'abc') -- Circular references are properly restored\nassert(out.obj.null == amf3.null) -- 'null' as a field value\nassert(out.dict[amf3.null] == amf3.null) -- 'null' as a key or value\nassert(out.arr1.__array == #out.arr1) -- Array length is restored\nassert(out.arr2.__array == 5) -- Access to the number of items in a sparse array\n\n-- Packing/unpacking values using AMF3-compatible numeric formats\nlocal b, i, d, s = pack_unpack('bids', 123, 123456, -1.2, 'abc')\n\n-- Serialization metamethods can be used to produce multiple AMF3 representations of the same object.\n-- Deserialization handlers can be used to restore Lua objects from complex AMF3 types on the way back.\n-- This is helpful, for example, when objects are exchanged with both trusted and untrusted parties.\n-- Various custom filters/wrappers can also be implemented using this API.\n\nlocal mt = {\n    __tostring = function (t) return (t.a or '') .. (t.b or '') end,\n    __toA = function (t) return {A = t.a} end, -- [a -\u003e A]\n    __toB = function (t) return {B = t.b} end, -- [b -\u003e B]\n}\n\nlocal function new(t) return setmetatable(t, mt) end\nlocal function fromA(t) return new{a = t.A} end -- [A -\u003e a]\nlocal function fromB(t) return new{b = t.B} end -- [B -\u003e b]\n\nlocal obj = new{a = 'a', b = 'b'}\nassert(tostring(obj) == 'ab')\nassert(tostring(encode_decode(obj, '__toA', fromA)) == 'a')\nassert(tostring(encode_decode(obj, '__toB', fromB)) == 'b')\n```\n\n\n[lua-amf3]: https://github.com/neoxic/lua-amf3\n[luarocks.org]: https://luarocks.org\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneoxic%2Flua-amf3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneoxic%2Flua-amf3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneoxic%2Flua-amf3/lists"}