{"id":27938888,"url":"https://github.com/xiyoo0812/lcodec","last_synced_at":"2025-05-07T08:58:20.119Z","repository":{"id":45704386,"uuid":"398763119","full_name":"xiyoo0812/lcodec","owner":"xiyoo0812","description":"一个提供给Lua使用的基础组件编解码/序列化库。","archived":false,"fork":false,"pushed_at":"2025-04-23T13:38:31.000Z","size":138,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T08:58:15.162Z","etag":null,"topics":["decode","encode","lua","serialize"],"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/xiyoo0812.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-22T09:39:34.000Z","updated_at":"2025-04-23T13:38:34.000Z","dependencies_parsed_at":"2024-03-27T09:45:05.586Z","dependency_job_id":"bc5e61a7-f53a-431b-bb22-fd8e0342da91","html_url":"https://github.com/xiyoo0812/lcodec","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/xiyoo0812%2Flcodec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Flcodec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Flcodec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Flcodec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiyoo0812","download_url":"https://codeload.github.com/xiyoo0812/lcodec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252847510,"owners_count":21813451,"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":["decode","encode","lua","serialize"],"created_at":"2025-05-07T08:58:19.410Z","updated_at":"2025-05-07T08:58:20.108Z","avatar_url":"https://github.com/xiyoo0812.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lcodec\n一个提供给C/Lua使用的内存buffer操作以及编解码库。\n\n# 依赖\n- [lua](https://github.com/xiyoo0812/lua.git)5.2以上\n- [luakit](https://github.com/xiyoo0812/luakit.git)\n- 项目路径如下\u003cbr\u003e\n  |--proj \u003cbr\u003e\n  \u0026emsp;|--lua \u003cbr\u003e\n  \u0026emsp;|--luakit \u003cbr\u003e\n  \u0026emsp;|--lcodec\n\n# 编译\n- msvc: 准备好lua依赖库并放到指定位置，将proj文件加到sln后编译。\n- linux: 准备好lua依赖库并放到指定位置，执行make -f lcodec.mak\n\n# 用法\n```lua\n--codec_test.lua\nlocal luabus        = require(\"luabus\")\nlocal lcrypt        = require(\"lcrypt\")\nlocal lcodec        = require(\"lcodec\")\n\nlocal log_debug     = logger.debug\nlocal log_dump      = logger.dump\nlocal lhex_encode   = lcrypt.hex_encode\n\nlocal encode        = lcodec.encode\nlocal decode        = lcodec.decode\nlocal encode_slice  = lcodec.encode_slice\nlocal decode_slice  = lcodec.decode_slice\nlocal serialize     = lcodec.serialize\nlocal unserialize   = lcodec.unserialize\nlocal hash_code     = lcodec.hash_code\nlocal fnv_32a       = lcodec.fnv_1a_32\nlocal fnv_32        = lcodec.fnv_1_32\nlocal jumphash      = lcodec.jumphash\n\n--ketama\nlcodec.ketama_insert(\"test1\", quanta.id)\nlcodec.ketama_insert(\"test2\", quanta.id + 1)\nlcodec.ketama_insert(\"test3\", quanta.id + 2)\nlcodec.ketama_insert(\"test4\", quanta.id + 3)\nlcodec.ketama_insert(\"test5\", quanta.id + 4)\nlcodec.ketama_insert(\"test6\", quanta.id + 5)\nlcodec.ketama_insert(\"test7\", quanta.id + 6)\nlcodec.ketama_insert(\"test8\", quanta.id + 7)\nlcodec.ketama_insert(\"test9\", quanta.id + 8)\nlcodec.ketama_insert(\"test10\", quanta.id + 9)\n\nlocal map = lcodec.ketama_map()\nlocal qmap = qtable.mapsort(map)\nfor _, value in pairs(qmap) do\n    log_debug(\"ketama_map: %s, %s\", value[1], value[2])\nend\nlog_debug(\"ketama_insert number: %s\", qtable.size(map))\n\n--hash\n----------------------------------------------------------------\nlocal hash_n1 = hash_code(12345)\nlocal hash_n2 = hash_code(123346456545464, 1000)\nlog_debug(\"hash_code number: %s, %s\", hash_n1, hash_n2)\n\nlocal hash_s1 = hash_code(\"12345\")\nlocal hash_s2 = hash_code(\"a0b0c0d0a0b0c0d0\", 1000)\nlog_debug(\"hash_code string: %s, %s\", hash_s1, hash_s2)\n\nlocal fnv_s1 = fnv_32(\"12345\")\nlocal fnv_s2 = fnv_32(\"12345\", fnv_s1)\nlocal fnv_s3 = fnv_32(\"12345\", fnv_s2)\nlog_debug(\"fnv_32 string: %s, %s, %s\", fnv_s1, fnv_s2, fnv_s3)\n\nlocal fnv_as1 = fnv_32a(\"12345\")\nlocal fnv_as2 = fnv_32a(\"12345\", fnv_as1)\nlocal fnv_as3 = fnv_32a(\"12345\", fnv_as2)\nlog_debug(\"fnv_32a string: %s, %s, %s\", fnv_as1, fnv_as2, fnv_as3)\n--fnv_32 string: 2930711257, 991336454, 3269464323\n--fnv_32a string: 3601286043, 177295730, 3384461241\n\nlocal jmpv = jumphash(\"\", 3)\nlog_debug(\"jumphash value: %s\", jmpv)\n\n--guid\n----------------------------------------------------------------\nlocal guid = lcodec.guid_new(5, 512)\nlocal sguid = lcodec.guid_tostring(guid)\nlog_debug(\"newguid-\u003e guid: %s, n2s: %s\", guid, sguid)\nlocal nguid = lcodec.guid_number(sguid)\nlocal s2guid = lcodec.guid_tostring(nguid)\nlog_debug(\"convert-\u003e guid: %s, n2s: %s\", nguid, s2guid)\nlocal eguid = lcodec.guid_encode(9223372036854775807)\nlocal eguid1 = lcodec.guid_encode(0x7fffffffffffffff)\nlog_debug(\"encode-\u003e eguid: %s\", eguid)\nlog_debug(\"encode-\u003e eguid: %s\", eguid1)\nlocal dguid = lcodec.guid_decode(eguid)\nlocal dguid1 = lcodec.guid_decode(eguid1)\nlog_debug(\"encode-\u003e dguid: %s\", dguid)\nlog_debug(\"encode-\u003e dguid: %s\", dguid1)\nlocal nsguid = lcodec.guid_string(5, 512)\nlog_debug(\"newguid: %s\", nsguid)\nlocal group = lcodec.guid_group(nsguid)\nlocal index = lcodec.guid_index(guid)\nlocal time = lcodec.guid_time(guid)\nlog_debug(\"ssource-\u003e group: %s, index: %s, time:%s\", group, index, time)\nlocal group2, index2, time2 = lcodec.guid_source(guid)\nlog_debug(\"nsource-\u003e group: %s, index: %s, time:%s\", group2, index2, time2)\n\n--serialize\n----------------------------------------------------------------\nlocal m = {f = 3}\nlocal t = {\n    [3.63] = 1, 2, 3, 4,\n    a = 2,\n    b = {\n        s = 3, d = \"4\"\n    },\n    e = true,\n    g = m,\n}\nlocal ss = serialize(t)\nlog_debug(\"serialize-\u003e aaa: %s\", ss)\n\nlocal tt = unserialize(ss)\nfor k, v in pairs(tt) do\n    log_debug(\"unserialize k=%s, v=%s\", k, v)\nend\n\n--encode\nlocal e = {a = 1, c = {ab = 2}}\nlocal bufe = encode(e)\nlocal slice = encode_slice(e)\nlocal bufs = slice.string()\nlog_debug(\"encode-\u003e bufe: %d, %s\", #bufe, lhex_encode(bufe))\nlog_debug(\"encode-\u003e bufs: %d, %s\", #bufs, lhex_encode(bufs))\n\nlocal datas = decode_slice(slice)\nlog_debug(\"decode-\u003e %s\", datas)\nlocal datae = decode(bufe, #bufe)\nlog_debug(\"decode-\u003e %s\", datae)\n\nlocal a = 1\nlocal b = 2\nlocal c = 4\nlocal es = encode_slice(a, b, c, 5)\nlocal ess = es.string()\nlog_debug(\"encode-\u003e aa: %d, %s\", #ess, lhex_encode(ess))\nlocal da, db, dc, dd = decode_slice(es)\nlog_debug(\"decode-\u003e %s, %s, %s, %s\", da, db, dc, dd)\n\n\nlocal ip = luabus.dns(\"mtae-global-test-outer-zone-a-2-89e65514de3445cc.elb.us-east-1.amazonaws.com\")\nlog_debug(\"luabus dns-\u003e %s\", ip)\n\n--dump\nlog_dump(\"dump-\u003e a: %s\", t)\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiyoo0812%2Flcodec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiyoo0812%2Flcodec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiyoo0812%2Flcodec/lists"}