{"id":16405611,"url":"https://github.com/aecsocket/octs","last_synced_at":"2025-09-08T08:43:29.390Z","repository":{"id":233056339,"uuid":"785900954","full_name":"aecsocket/octs","owner":"aecsocket","description":"Finally, a good byte manipulation library","archived":false,"fork":false,"pushed_at":"2024-10-05T17:33:59.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-27T12:40:35.623Z","etag":null,"topics":[],"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/aecsocket.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-12T21:44:10.000Z","updated_at":"2024-10-05T17:34:00.000Z","dependencies_parsed_at":"2025-02-11T21:41:57.186Z","dependency_job_id":null,"html_url":"https://github.com/aecsocket/octs","commit_stats":null,"previous_names":["aecsocket/octs"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/aecsocket/octs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aecsocket%2Focts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aecsocket%2Focts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aecsocket%2Focts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aecsocket%2Focts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aecsocket","download_url":"https://codeload.github.com/aecsocket/octs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aecsocket%2Focts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274159333,"owners_count":25232633,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-11T06:06:41.452Z","updated_at":"2025-09-08T08:43:29.358Z","avatar_url":"https://github.com/aecsocket.png","language":"Rust","readme":"# `octs`\n\n[![crates.io](https://img.shields.io/crates/v/octs.svg)](https://crates.io/crates/octs)\n[![docs.rs](https://img.shields.io/docsrs/octs)](https://docs.rs/octs)\n\nFinally, a good byte manipulation library.\n\nThis crate builds on top of the types defined by [`bytes`] by replacing its panicking `get` and\n`put` functions with fallible, non-panicking `read` and `write` functions via [`octs::Read`] and\n[`octs::Write`].\n\n## Features\n\n* **Based on [`bytes`]** - which provides useful types for byte manipulation, and allows cheaply\n  cloning byte allocations via reference counting. Great for writing zero-copy networking code.\n\n* **Panicking functions were a mistake** - in networking, you can't trust your inputs. So why should\n  it ever be possible to panic on malformed input?? All functions in `octs` which can fail return a\n  [`Result`].\n\n* **Your types are first-class citizens** - instead of `get_u16`, `put_f32`, etc., just use one\n  [`read`] and [`write`] function for all types. This means you can implement [`Decode`] and be able\n  to [`read`] it from any buffer, and likewise for [`Encode`] and [`write`].\n\n* **Dedicated varints** - one of the staples of networking primitives is implemented here, without\n  needing any extensions. Just `read` or `write` a [`VarInt`] as you would any other value.\n\n* **Zero unsafe** - I'm not smart enough to write unsafe code.\n\n* `#![no_std]` - just like [`bytes`], but it still requires `alloc`.\n\n## Examples\n\n### Writing\n\n```rust\nuse octs::{Read, Write, VarInt};\n\nfn write_packet(\n    mut buf: octs::BytesMut,\n    //       ^^^^^^^^^^^^^^\n    //       | re-exports the core `bytes` types\n    packet_id: u16,\n    timestamp: u64,\n    payload: \u0026[u8],\n) -\u003e Result\u003c(), octs::BufTooShort\u003e {\n    //          ^^^^^^^^^^^^^^^^^\n    //          | the main error type\n    buf.write(packet_id)?;\n    //  ^^^^^\n    //  | one `write` function for all your types\n\n    buf.write(timestamp)?;\n    //  +---------------^\n    //  | just use ? for errors\n    //  | no panics\n\n    buf.write(VarInt(payload.len()))?;\n    //       ^^^^^^^\n    //       | inbuilt support for varints\n    //       | using the Protocol Buffers spec\n\n    buf.write_from(payload)?;\n    //  ^^^^^^^^^^\n    //  | copy from an existing buffer \n\n    Ok(())\n}\n```\n\n### Reading\n\n```rust\nuse core::num::NonZeroU8;\n\nuse octs::{Bytes, BufError, Decode, Read, BufTooShortOr, VarInt};\n\n#[derive(Debug)]\nstruct Fragment {\n    num_frags: NonZeroU8,\n    payload: Bytes,\n}\n\n#[derive(Debug)]\nenum FragmentError {\n    InvalidNumFrags,\n    PayloadTooLarge,\n}\n\nimpl Decode for Fragment {\n//   ^^^^^^\n//   | implement this trait to be able to `read`\n//   | this value from a buffer\n\n    type Error = FragmentError;\n\n    fn decode(mut buf: impl Read) -\u003e Result\u003cSelf, BufTooShortOr\u003cSelf::Error\u003e\u003e {\n        let num_frags = buf\n            .read::\u003cNonZeroU8\u003e()\n            .map_err(|e| e.map_or(|_| FragmentError::InvalidNumFrags))?;\n        // +--------------^^^^^^^\n        // | map the `InvalidValue` error of reading\n        // | a `NonZeroU8` to your own error value\n\n        let VarInt(payload_len) = buf\n            .read::\u003cVarInt\u003cusize\u003e\u003e()\n            .map_err(|e| e.map_or(|_| FragmentError::PayloadTooLarge))?;\n\n        let payload = buf.read_next(payload_len)?;\n        // +-------------^^^^^^^^^^\n        // | read the next `payload_len` bytes directly into `Bytes`\n        // | if `buf` is also a `Bytes`, this is zero-copy!\n\n        Ok(Self {\n            num_frags,\n            payload\n        })\n    }\n}\n\n```\n\n## Inspirations\n\n* [`bytes`] - core byte manipulation primitives, such as the possibly-non-contiguous [`bytes::Buf`]\n  trait, and the cheaply-cloneable [`bytes::Bytes`] type.\n* [`octets`] - general API style, and having varints be a core part of the API\n* [`safer-bytes`] - making a good version of the [`bytes`] API\n* [`integer-encoding`] - implementations of varint encode/decode\n\n[`octs::Read`]: Read\n[`octs::Write`]: Write\n[`read`]: Read::read\n[`write`]: Write::write\n[`bytes`]: https://docs.rs/bytes\n[`octets`]: https://docs.rs/octets\n[`integer-encoding`]: https://docs.rs/integer-encoding\n[`safer-bytes`]: https://docs.rs/safer-bytes\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faecsocket%2Focts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faecsocket%2Focts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faecsocket%2Focts/lists"}