{"id":16754437,"url":"https://github.com/coastalwhite/cobs-rs","last_synced_at":"2025-10-07T04:24:48.392Z","repository":{"id":57607193,"uuid":"346448987","full_name":"coastalwhite/cobs-rs","owner":"coastalwhite","description":"A minimal heapless no-std Rust library to do Consistent Overhead Byte Stuffing","archived":false,"fork":false,"pushed_at":"2022-07-29T04:58:28.000Z","size":16,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T02:15:54.001Z","etag":null,"topics":["buffer","cobs-algorithm","cobs-rs","embedded","encoding-buffers","rust","rust-lang","stuffing"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/cobs-rs","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/coastalwhite.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":"2021-03-10T18:10:33.000Z","updated_at":"2025-03-11T14:41:58.000Z","dependencies_parsed_at":"2022-08-30T00:00:45.979Z","dependency_job_id":null,"html_url":"https://github.com/coastalwhite/cobs-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coastalwhite%2Fcobs-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coastalwhite%2Fcobs-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coastalwhite%2Fcobs-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coastalwhite%2Fcobs-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coastalwhite","download_url":"https://codeload.github.com/coastalwhite/cobs-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248251668,"owners_count":21072692,"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":["buffer","cobs-algorithm","cobs-rs","embedded","encoding-buffers","rust","rust-lang","stuffing"],"created_at":"2024-10-13T03:04:56.001Z","updated_at":"2025-10-07T04:24:43.352Z","avatar_url":"https://github.com/coastalwhite.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# COBS-RS\n\n![GitHub](https://img.shields.io/github/license/coastalwhite/cobs-rs)\n![docs.rs](https://img.shields.io/docsrs/cobs-rs)\n\nA very minimal no_std [Consistent Overhead Byte\nStuffing](https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing)\nlibrary written in Rust. The COBS algorithm, and thus also this crate, provides\nan encoding for arbitrary data which removes any occurrence of a specific marker\nbyte. This is mostly useful when we are transferring arbitrary data which\nis terminated with a null byte, and therefore we don't want our arbitrary data\nbuffer to contain any null bytes. In fact, this crate will automatically append the\nmarker byte at the end of any encoded buffer.\n\nTake a look at [the documentation](https://docs.rs/cobs-rs/).\n\n## Features\n\nThe *cobs-rs* crate only provides two specific functions. Namely, the\n[`stuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.stuff.html) and the\n[`unstuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.unstuff.html) function,\nwhich encode and decode respectively. This, together with the fact that the\ncrate doesn't use the [`std`](https://doc.rust-lang.org/std/), makes the crate\nperfect for embedded hardware. However, it can also be used outside of embedded\nsystems.\n\n## Usage\n\nBoth the encode([`stuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.stuff.html))\nand decode([`unstuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.unstuff.html))\nfunctions, use [const\ngenerics](https://blog.rust-lang.org/2021/02/26/const-generics-mvp-beta). This\nmay make usage a bit counter-intuitive for people unfamiliar with this feature\nat first.\n\nSomething to take into account here is that the COBS algorithm will __at most__\nadd `2 + (size of input buffer / 256)` (with integer division) bytes to the\nencoded buffer in size compared to input buffer. This fact allows us to always\nreserve enough space for the output buffer.\n\n### Encoding buffers\n\nLet us have a look at a small example of how to encode some data using the\n[`stuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.stuff.html) function.\n\n```rust\nlet data: [u8; 254] = [\n    // ...snip\n];\n\n// Our input buffer is 254 bytes long.\n// Thus, we need to reserve 2 + (254 / 256) = 2 extra bytes\n// for the encoded buffer.\nlet encoded: [u8; 256] = cobs_rs::stuff(data, 0x00);\n\n// We can also encode much larger buffers\nlet a_lot_of_data: [u8; 1337] = [\n    // ...snip\n];\n\n// Our input buffer is 1337 bytes long.\n// Thus, we need to reserve 2 + (1337 / 256) = 7 extra bytes\n// for the encoded buffer.\nlet a_lot_of_output: [u8; 1344] = cobs_rs::stuff(a_lot_of_data, 0x00);\n```\n\n\u003e **Note:** The output buffer type specifications are always necessary. The type\n\u003e specifications for the input data isn't necessary most of the time.\n\n### Decoding buffers\n\nNow, let us look at an example of how to decode data using the\n[`unstuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.stuff.html) function.\n\nIt is generally a good idea to reserve `size of encoded buffer - 2` bytes for\nthe decoded buffer. With this rule, we will always have enough space for the\nencoded buffer. Next to the decoded buffer, the\n[`unstuff`](https://docs.rs/cobs-rs/1.0.2/cobs_rs/fn.stuff.html) function will\nalso return the actual filled size of the buffer.\n\n```rust\n// We are given some encoded data buffer\nlet encoded_data: [u8; 256] = [\n    //... snip\n];\n\n// We reserve 256 - 2 = 254 bytes for the decoded buffer.\nlet (decoded_data: [u8; 254], decoded_data_length) =\n    cobs_rs::unstuff(encoded_data, 0x00);\n\n// We can also decode bigger buffers\nlet a_lot_of_encoded_data: [u8; 1344] = [\n    //... snip\n];\n\n// We reserve 1344 - 2 = 1342 bytes for the decoded buffer.\nlet (a_lot_of_decoded_data: [u8; 1342], a_lot_of_decoded_data_length) =\n    cobs_rs::unstuff(encoded_data, 0x00);\n```\n\n\u003e **Note:** The decoded buffer type specifications are always necessary. The\n\u003e type specifications for the encoded data isn't necessary most of the time.\n\n## License\n\nLicensed under a __MIT__ license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoastalwhite%2Fcobs-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoastalwhite%2Fcobs-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoastalwhite%2Fcobs-rs/lists"}