{"id":17358262,"url":"https://github.com/sklose/magic-buffer","last_synced_at":"2025-04-15T00:13:09.004Z","repository":{"id":174536778,"uuid":"648383411","full_name":"sklose/magic-buffer","owner":"sklose","description":"Virtual Ring Buffer implementation for Rust","archived":false,"fork":false,"pushed_at":"2024-12-14T20:55:10.000Z","size":60,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-15T00:12:52.118Z","etag":null,"topics":["allocation","networking","ring-buffer"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/sklose.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-06-01T21:03:57.000Z","updated_at":"2025-03-15T04:23:29.000Z","dependencies_parsed_at":"2023-11-10T23:24:06.350Z","dependency_job_id":"3aea9f31-12af-48f5-a000-d01a2b919d3c","html_url":"https://github.com/sklose/magic-buffer","commit_stats":null,"previous_names":["sklose/magic-buffer"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sklose%2Fmagic-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sklose%2Fmagic-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sklose%2Fmagic-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sklose%2Fmagic-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sklose","download_url":"https://codeload.github.com/sklose/magic-buffer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248981270,"owners_count":21193147,"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":["allocation","networking","ring-buffer"],"created_at":"2024-10-15T19:04:52.806Z","updated_at":"2025-04-15T00:13:08.987Z","avatar_url":"https://github.com/sklose.png","language":"Rust","readme":"[![CI](https://github.com/sklose/magic-buffer/actions/workflows/ci.yml/badge.svg)](https://github.com/sklose/magic-buffer/actions/workflows/ci.yml)\n[![crates.io](https://img.shields.io/crates/v/magic-buffer.svg)](https://crates.io/crates/magic-buffer)\n[![docs.rs](https://img.shields.io/docsrs/magic-buffer)](https://docs.rs/magic-buffer)\n\n# Magic Buffer\n\nA Magic Ring Buffer (or Virtual Ring Buffer) implementation for Rust. `magic-buffer` provides a simplified\nway to deal with buffers that wrap around by delegating that logic to hardware.\n\n![diagram](https://raw.githubusercontent.com/sklose/magic-buffer/main/media/magic-buffer.png)\n\nThe same underlying buffer is mapped twice into memory at adjacent addresses. This allows to wrap around the\nbuffer while still reading forward in the virtual address space.\n\nThis behavior is useful for a variety of applications:\n\n- network protocol parsers with a fixed size buffer\n- VecDec implementations that can provide a consecutive slice of memory\n  (e.g. [SliceDeq](https://github.com/gnzlbg/slice_deque))\n- IPC ring buffer implementations\n\n```toml\n[dependencies]\nmagic-buffer = \"0.1\"\n```\n\n## Examples\n\n### Allocating a Buffer\n\nBuffer lens have to be page aligned and follow the allocation\ngranularity of the operating system\n\n```rust\nuse magic_buffer::*;\nlet buf = MagicBuffer::new(1 \u003c\u003c 16).unwrap();\n```\n\n| OS      | Architecture | Min Buffer Len |\n|---------|--------------|----------------|\n| Windows | x86_64       | 64 KiB         |\n| Linux   | x86_64       | 4 KiB          |\n| OSX     | x86_64       | 4 KiB          |\n| OSX     | aarch64      | 16 KiB         |\n\n** PRs welcome to complete this list\n\n### Indexing into a Buffer\n\n```rust\nuse magic_buffer::*;\nlet mut buf = MagicBuffer::new(1 \u003c\u003c 16).unwrap();\nbuf[0] = b'1';\nbuf[1] = b'2';\n\n// index wraps around\nassert_eq!(buf[0], buf[1 \u003c\u003c 16]);\nassert_eq!(buf[1], buf[(1 \u003c\u003c 16) + 1]);\n```\n\n### Slices\n\n```rust\nuse magic_buffer::*;\nlet buf = MagicBuffer::new(1 \u003c\u003c 16).unwrap();\n\n// the whole underlying buffer starting at pos 0\nlet a = \u0026buf[..];\n\n// the whole underlying buffer starting at pos 1\n// then wrapping around with the first byte at the end\nlet b = \u0026buf[1..];\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsklose%2Fmagic-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsklose%2Fmagic-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsklose%2Fmagic-buffer/lists"}