{"id":20269900,"url":"https://github.com/teliosdev/packed_struct","last_synced_at":"2025-03-03T23:09:33.328Z","repository":{"id":9169811,"uuid":"10968665","full_name":"teliosdev/packed_struct","owner":"teliosdev","description":"Cleans up the string mess when packing items.","archived":false,"fork":false,"pushed_at":"2014-08-15T18:52:13.000Z","size":197,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T21:26:59.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://rdoc.info/github/redjazz96/packed_struct","language":"Ruby","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/teliosdev.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":"2013-06-26T13:32:44.000Z","updated_at":"2019-11-05T13:00:22.000Z","dependencies_parsed_at":"2022-07-07T19:22:35.786Z","dependency_job_id":null,"html_url":"https://github.com/teliosdev/packed_struct","commit_stats":null,"previous_names":["redjazz96/packed_struct"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Fpacked_struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Fpacked_struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Fpacked_struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Fpacked_struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teliosdev","download_url":"https://codeload.github.com/teliosdev/packed_struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241589455,"owners_count":19986907,"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":[],"created_at":"2024-11-14T12:27:57.553Z","updated_at":"2025-03-03T23:09:33.310Z","avatar_url":"https://github.com/teliosdev.png","language":"Ruby","readme":"# PackedStruct [![Build Status](https://travis-ci.org/medcat/packed_struct.png?branch=master)](https://travis-ci.org/redjazz96/packed_struct)\n\n`PackedStruct` is a way to define packing strings (see [`Array#pack`](http://ruby-doc.org/core-2.0/Array.html#method-i-pack)).\nIt was created after @charliesome suggested [a format](https://gist.github.com/medcat/6dda0554f62e4f77253a) for defining these strings, but never finished it.\n\nThe basic way of defining a packed struct is such:\n\n```Ruby\nclass RconPacket\n  include PackedStruct\n  struct_layout :packet do\n    little_endian signed size[32] # defaults to a number of size 32.\n                                  # also the same as: `little_endian signed long size`\n    little_endian signed id[32]\n    little_endian signed type[32]\n    string body[size]\n    null\n  end\nend\n```\n\nThis can be accessed as:\n\n```Ruby\nRconPacket.structs[:packet].pack(size: 11, id: 1, type: 0, body: \"hello world\")\n# =\u003e \"\\v\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00hello world\\x00\"\n```\n\nYou can also unpack strings.\n\n```Ruby\nRconPacket.structs[:packet].unpack(\"\\v\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00hello world\\x00\")\n# =\u003e {:size =\u003e 11, :id =\u003e 1, :type =\u003e 0, :body =\u003e \"hello world\"}\n```\n\nFrom sockets, too.  Anything that responds to `#read`.\n\n```Ruby\nfile = File.open(\"/path/to/some/file\", \"r\")\n\nRconPacket.structs[:packet].unpack_from_socket(file)\n# =\u003e ...\n```\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/redjazz96/packed_struct/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteliosdev%2Fpacked_struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteliosdev%2Fpacked_struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteliosdev%2Fpacked_struct/lists"}