{"id":18099934,"url":"https://github.com/rossmacarthur/eio","last_synced_at":"2025-04-13T16:08:50.916Z","repository":{"id":57623804,"uuid":"358867474","full_name":"rossmacarthur/eio","owner":"rossmacarthur","description":"Read and write numbers in big-endian and little-endian","archived":false,"fork":false,"pushed_at":"2021-05-13T18:16:07.000Z","size":29,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"trunk","last_synced_at":"2025-03-27T07:01:39.141Z","etag":null,"topics":["bytes","crate","endianness","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rossmacarthur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-17T12:00:24.000Z","updated_at":"2023-12-12T22:40:46.000Z","dependencies_parsed_at":"2022-09-12T08:22:30.181Z","dependency_job_id":null,"html_url":"https://github.com/rossmacarthur/eio","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Feio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Feio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Feio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Feio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rossmacarthur","download_url":"https://codeload.github.com/rossmacarthur/eio/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248553888,"owners_count":21123542,"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":["bytes","crate","endianness","rust"],"created_at":"2024-10-31T21:11:50.635Z","updated_at":"2025-04-13T16:08:50.893Z","avatar_url":"https://github.com/rossmacarthur.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eio\n\nRead and write numbers in big-endian and little-endian.\n\n## 🚀 Getting started\n\nAdd the following to your Cargo manifest.\n```toml\n[dependencies]\neio = \"0.1\"\n```\n\nAnd bring the `ReadExt` and/or `WriteExt` traits into scope.\n```rust\nuse eio::{ReadExt, WriteExt};\n```\n\n## 🤸 Usage\n\nThe most common usage is parsing numbers from a source. You can do this using\nthe `read_le()` and `read_be()` methods on anything that implements `Read`.\n\n```rust\nuse eio::ReadExt;\n\n// `Cursor` implements `Read`\nlet mut rdr = std::io::Cursor::new([\n  0x37, 0x13,\n  0x12, 0x34, 0x56, 0x78,\n  0x00, 0x09, 0x10,\n]);\n\n// Read a two byte `u16` in little-endian order\nlet i: u16 = rdr.read_le()?;\nassert_eq!(i, 0x1337);\n\n// Read a four byte `i32` in big-endian order\nlet i: i32 = rdr.read_be()?;\nassert_eq!(i, 0x12345678);\n\n// Read a three byte array\nlet a: [u8; 3] = rdr.read_array()?;\nassert_eq!(a, [0x00, 0x09, 0x10]);\n```\n\nSerialization of numbers can be done using the `write_le()` and `write_be()`.\nThis can be done on anything that implements `Write`.\n\n```rust\nuse eio::WriteExt;\n\n// `\u0026mut [u8]` implements `Write`.\nlet mut wtr = Vec::new();\n\n// Write a four byte `f32` in little-endian order\nwtr.write_le(1_f32)?;\n// Write a one byte `u8`\nwtr.write_be(7_u8)?;\n\nassert_eq!(wtr, \u0026[0, 0, 0x80, 0x3f, 0x07]);\n```\n\nIn `no_std` contexts the `FromBytes` and `ToBytes` traits can be used directly.\n```rust\nuse eio::{FromBytes, ToBytes};\n\nlet x: u32 = FromBytes::from_be_bytes([0, 0, 0, 7]);\nassert_eq!(x, 7);\n\nlet data = ToBytes::to_le_bytes(x);\nassert_eq!(data, [7, 0, 0, 0]);\n```\n\n## 💡 Prior art\n\n`eio` provides the same capabilities as the popular [`byteorder`] crate but with\na very different API. The advantages of `eio` are the following:\n\n- It is extendible, anyone can implement `FromBytes` or `ToBytes` for their own\n  integer types.\n- Uses the core/std `{from,to}_{le,be}_bytes` functions to do the conversion for\n  floats and integers. [`byteorder`] reimplements these.\n- Doesn't require turbofish type annotations all the time.\n  ```rust\n  // byteorder\n  let i = rdr.read_u16::\u003cBigEndian\u003e()?;\n  // eio\n  let i: u16 = rdr.read_be()?;\n  ```\n\n[`byteorder`]: https://crates.io/crates/byteorder\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or\n  http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossmacarthur%2Feio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frossmacarthur%2Feio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossmacarthur%2Feio/lists"}