{"id":17676964,"url":"https://github.com/alluseri/riza","last_synced_at":"2025-05-12T21:57:48.960Z","repository":{"id":182999823,"uuid":"619807276","full_name":"Alluseri/Riza","owner":"Alluseri","description":"Lua string.pack/unpack implementation in C#, made primarily to assist the creation of private servers for Unity games with XLua backends.","archived":false,"fork":false,"pushed_at":"2024-06-12T20:19:34.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T18:39:55.253Z","etag":null,"topics":["c-sharp","c-sharp-library","lua","serialization","xlua"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alluseri.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}},"created_at":"2023-03-27T13:27:10.000Z","updated_at":"2025-04-17T02:55:40.000Z","dependencies_parsed_at":"2024-10-24T12:00:52.613Z","dependency_job_id":null,"html_url":"https://github.com/Alluseri/Riza","commit_stats":null,"previous_names":["alluseri/riza"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alluseri%2FRiza","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alluseri%2FRiza/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alluseri%2FRiza/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alluseri%2FRiza/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alluseri","download_url":"https://codeload.github.com/Alluseri/Riza/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253830910,"owners_count":21971001,"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":["c-sharp","c-sharp-library","lua","serialization","xlua"],"created_at":"2024-10-24T07:27:16.030Z","updated_at":"2025-05-12T21:57:48.914Z","avatar_url":"https://github.com/Alluseri.png","language":"C#","readme":"# Riza\r\nLua string.pack/unpack implementation in C#, made primarily to assist the creation of private servers for Unity games with XLua backends.\r\n\r\nOnly x64 systems. I have no respect towards nuint.\r\n\r\n**Please use MessagePack instead of Riza, unless you are using it purposefully(e.g. for XLua private servers). This project's intention and purpose is clear.**\r\n\r\n## Major differences between string.pack and LuaPack\r\n* LuaPack.Pack does not care if the format option is signed or not, while Lua will raise an Integer Overflow error if the value indeed overflows:\r\n```lua\r\nprint(string.pack(\"\u003eb\", 254)); -- input:1: bad argument #2 to 'pack' (integer overflow)\r\n```\r\n* LuaPack does not and will most likely never support the `!` and `X` options.\r\n* LuaPack does not support `j`, `J`, `n` and `z` options **yet**.\r\n* LuaPack allows you to use byte counts higher than 16 in `i/I/s/c[n]` options, unlike Lua.\r\n* All overloads of LuaPack.Unpack will NOT fail if the data feed ends prematurely.\r\n\r\n## Usage\r\n### Sample Class\r\n**WARNING:** You cannot use `struct` with LuaPack directly because __makeref and imaginary constraints don't make my life any easier!\r\n```cs\r\npublic class SampleClass {\r\n  [RizaField(0)]\r\n  public int SomeInt;\r\n  [RizaField(1)]\r\n  public string SomeString;\r\n  [RizaField(2)]\r\n  public ulong SomeUlong;\r\n  public ulong NotDeserializedField;\r\n  [RizaField(3)]\r\n  public byte SomeByte;\r\n}\r\n```\r\n### Packing\r\nUse LuaPack.Pack* just like you would use string.pack in Lua.\r\n\r\nFor this piece of code:\r\n```lua\r\nprint(string.pack(\"\u003eI4B\u003ciLs\", 1, 2, 3, 4, \"abc\"));\r\n```\r\nThe direct LuaPack representation would be:\r\n```cs\r\nConsole.WriteLine(LuaPack.PackToString(\"\u003eI4B\u003ciLs\", 1, 2, 3, 4, \"abc\"));\r\n```\r\n**Additionally, Riza supports packing entire objects:**\r\n```cs\r\nConsole.WriteLine(LuaPack.PackToString(\"\u003eI4c8Lb\", new SampleClass() {\r\n  SomeInt = 58,\r\n  SomeString = \"abcdefgh\",\r\n  SomeUlong = 0xDEADC0DECAFEBABE,\r\n  SomeByte = 210\r\n}));\r\n```\r\n\r\n### Unpacking\r\nThe primitive way, which is faster, but really annoying to work with, is this:\r\n```cs\r\nint SomeInt;\r\nstring SomeString;\r\nulong SomeUlong;\r\nbyte SomeByte;\r\n\r\nList\u003cobject\u003e Unpacked = LuaPack.Unpack(\"\u003eI4c8Lb\", SomePackedData);\r\nSomeInt = (int) (ulong) Unpacked[0]; // You have to cast to ulong first... So bad.\r\nSomeString = (string) Unpacked[1];\r\nSomeUlong = (ulong) Unpacked[2];\r\nSomeByte = (byte) Unpacked[3];\r\n```\r\n**And the better way(but slower, since it uses reflection) is this:**\r\n```cs\r\nSampleClass Sample = LuaPack.Unpack\u003cSampleClass\u003e(\"\u003eI4c8Lb\", SomePackedData); // T has a constraint of new()\r\nSampleClass SameSample = LuaPack.Unpack\u003cSampleClass\u003e(\"\u003eI4c8Lb\", SomePackedData, new SampleClass());\r\n```\r\n\r\n## Performance Benchmarks\r\n- CPU: AMD Ryzen 7 5800X\r\n- OS: tiny10 22H2\r\n- class SmallDummy (S):`\u003efB\u003ci4s\u003ec12l\u003chd` - 8 fields.\r\n- class LargeDummy (L): `\u003ebfB\u003ci4Hs\u003ec12I3l\u003cLhd` - 12 fields.\r\n- class ExtraLargeDummy (XL): `\u003ebfB\u003ci4Hs\u003ec12I3l\u003eLhd\u003cbfB\u003ei4Hs\u003cc12I3l\u003eLhd` - 24 fields.\r\n#### Pack vs Pack\u003cT\u003e\r\n|       Method |        Mean |     Error |    StdDev |\r\n|------------- |------------:|----------:|----------:|\r\n|  ManualPackS |    177.6 ns |   3.38 ns |   3.32 ns |\r\n|  ManualPackL |    233.1 ns |   2.72 ns |   2.41 ns |\r\n| ManualPackXL |    427.7 ns |   4.55 ns |   3.80 ns |\r\n|  SerialPackS |  5,390.1 ns |  29.54 ns |  23.06 ns |\r\n|  SerialPackL |  7,996.1 ns |  66.19 ns |  55.27 ns |\r\n| SerialPackXL | 15,757.9 ns | 164.70 ns | 128.58 ns |\r\n\r\n#### Unpack vs Unpack\u003cT\u003e\r\n|         Method |        Mean |     Error |    StdDev |\r\n|--------------- |------------:|----------:|----------:|\r\n|  ManualUnpackS |    177.1 ns |   2.50 ns |   2.09 ns |\r\n|  ManualUnpackL |    238.9 ns |   2.58 ns |   2.29 ns |\r\n| ManualUnpackXL |    453.6 ns |   9.10 ns |  15.70 ns |\r\n|  SerialUnpackS |  5,506.1 ns |  23.41 ns |  21.90 ns |\r\n|  SerialUnpackL |  7,949.0 ns | 110.08 ns |  97.58 ns |\r\n| SerialUnpackXL | 16,144.7 ns | 261.28 ns | 231.62 ns |\r\n\r\n## Endianness\r\nBig Endian is fully supported *when packing and unpacking*, thus using the `\u003e` flag is fully supported and will work; **but** options `i/I/s/c[n]` **will not work** correctly under a Big Endian memory layout (e.g. under Solaris).\r\n\r\nThe `=` flag is always defaulted to Little Endian.\r\n\r\n\u003c!--\r\nfunction pattern(str)\r\n  local hex = \"\"\r\n  for i = 1, #str do\r\n    hex = hex .. string.format(\"%02X\", string.byte(str, i))\r\n    if i ~= #str then\r\n      hex = hex .. \" \"\r\n    end\r\n  end\r\n  return hex\r\nend\r\nprint(pattern(string.pack(\"\u003eB\", 192)));\r\n--\u003e\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falluseri%2Friza","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falluseri%2Friza","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falluseri%2Friza/lists"}