{"id":17220827,"url":"https://github.com/kojix2/ffi-bitfield","last_synced_at":"2025-04-13T23:46:58.353Z","repository":{"id":45214552,"uuid":"344350269","full_name":"kojix2/ffi-bitfield","owner":"kojix2","description":"Bit field for Ruby-FFI","archived":false,"fork":false,"pushed_at":"2025-04-10T05:29:05.000Z","size":143,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T05:51:21.093Z","etag":null,"topics":["ffi","ruby","ruby-ffi"],"latest_commit_sha":null,"homepage":"https://kojix2.github.io/ffi-bitfield/","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/kojix2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"ko_fi":"kojix2"}},"created_at":"2021-03-04T04:33:28.000Z","updated_at":"2025-04-10T05:28:49.000Z","dependencies_parsed_at":"2024-02-10T01:30:23.910Z","dependency_job_id":"c54699f7-a680-4f8c-b525-65768517faf8","html_url":"https://github.com/kojix2/ffi-bitfield","commit_stats":{"total_commits":65,"total_committers":1,"mean_commits":65.0,"dds":0.0,"last_synced_commit":"1a2954ec35ff6d343dff4cb6f69d9dcedcff547e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fffi-bitfield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fffi-bitfield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fffi-bitfield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fffi-bitfield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kojix2","download_url":"https://codeload.github.com/kojix2/ffi-bitfield/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537003,"owners_count":21120687,"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":["ffi","ruby","ruby-ffi"],"created_at":"2024-10-15T03:53:20.368Z","updated_at":"2025-04-13T23:46:58.345Z","avatar_url":"https://github.com/kojix2.png","language":"Ruby","funding_links":["https://ko-fi.com/kojix2"],"categories":[],"sub_categories":[],"readme":"# ffi-bitfield\n\n[![Gem Version](https://badge.fury.io/rb/ffi-bitfield.svg)](https://badge.fury.io/rb/ffi-bitfield)\n[![test](https://github.com/kojix2/ffi-bitfield/actions/workflows/ci.yml/badge.svg)](https://github.com/kojix2/ffi-bitfield/actions/workflows/ci.yml)\n\nBit field for [Ruby-FFI](https://github.com/ffi/ffi)\n\n## Installation\n\n```sh\ngem install ffi-bitfield\n```\n\n## Usage\n\nClasses\n\n* class BitStruct \u003c FFI::Struct\n* class ManagedBitStruct \u003c FFI::ManagedStruct\n\nLoading\n\n```ruby\nrequire 'ffi/bit_struct'\nrequire 'ffi/managed_bit_struct'\n```\n\nDefine your struct\n\n```ruby\nclass Struct1 \u003c FFI::BitStruct\n  layout \\\n    :a, :uint8,\n    :b, :uint8\n\n  bit_fields :a,\n    :u, 2,\n    :v, 2,\n    :w, 1,\n    :x, 1,\n    :y, 1,\n    :z, 1\nend\n```\n\nReading\n\n```ruby\ns = Struct1.new\n\ns[:a] = 63\np s[:u] # 3\np s[:v] # 3\np s[:w] # 1\np s[:x] # 1\np s[:y] # 0\np s[:z] # 0\n```\n\nWriting\n\n```ruby\ns = Struct1.new\n\ns[:u] = 0\ns[:v] = 0\ns[:w] = 0\ns[:x] = 0\ns[:y] = 1\np s[:a] # 64\n```\n\n### Inspecting Bit Fields\n\nYou can use the `bit_field_members` method to get a hash of bit fields grouped by parent field:\n\n```ruby\nclass Flags \u003c FFI::BitStruct\n  layout \\\n    :value, :uint8\n\n  bit_fields :value,\n    :read,    1,\n    :write,   1,\n    :execute, 1,\n    :unused,  5\nend\n\np Flags.bit_field_members\n# =\u003e {:value=\u003e[:read, :write, :execute, :unused]}\n```\n\nFor more detailed information, you can use the `bit_field_layout` method:\n\n```ruby\np Flags.bit_field_layout\n# =\u003e {\n#      :value =\u003e {\n#        :read    =\u003e { :start =\u003e 0, :width =\u003e 1 },\n#        :write   =\u003e { :start =\u003e 1, :width =\u003e 1 },\n#        :execute =\u003e { :start =\u003e 2, :width =\u003e 1 },\n#        :unused  =\u003e { :start =\u003e 3, :width =\u003e 5 }\n#      }\n#    }\n```\n\nThese methods are useful for custom pretty printing or introspection of your bit struct classes.\n\n### Loading\n\n```ruby\nrequire 'ffi/bit_field'\n```\n\nThe above is the same as below.\n\n```ruby\nrequire 'ffi/bit_struct'\nrequire 'ffi/managed_bit_struct'\n```\n\n## Development\n\n```\ngit clone https://github.com/kojix2/ffi-bitfield\ncd ffi-bitfield\nbundle install\nbundle exec rake test\n```\n\n* [ffi-bitfield - read/write bit fields with Ruby-FFI](https://dev.to/kojix2/ffi-bitfield-g4h)\n\n## Contributing\n\nYour feedback is important.\n\nffi-bitfield is a library under development, so even small improvements like typofix are welcome! Please feel free to send us your pull requests.\nBug reports and pull requests are welcome on GitHub at https://github.com/kojix2/ffi-bitfield.\n\n    Do you need commit rights to my repository?\n    Do you want to get admin rights and take over the project?\n    If so, please feel free to contact me @kojix2.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fffi-bitfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkojix2%2Fffi-bitfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fffi-bitfield/lists"}