{"id":51421896,"url":"https://github.com/firechip/cobs_codec_swift","last_synced_at":"2026-07-05T00:17:23.808Z","repository":{"id":369359461,"uuid":"1289504928","full_name":"firechip/cobs_codec_swift","owner":"firechip","description":"Pure-Swift, dependency-free Consistent Overhead Byte Stuffing (COBS) and COBS/R codec (Swift Package Manager). The Swift member of the Firechip COBS family.","archived":false,"fork":false,"pushed_at":"2026-07-04T21:47:38.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-04T23:08:31.740Z","etag":null,"topics":["byte-stuffing","cobs","cobs-r","encoding","framing","macos","serial","spm","swift","swift-package-manager"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/firechip.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-07-04T20:52:48.000Z","updated_at":"2026-07-04T21:47:41.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/firechip/cobs_codec_swift","commit_stats":null,"previous_names":["firechip/cobs_codec_swift"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/firechip/cobs_codec_swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firechip%2Fcobs_codec_swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firechip%2Fcobs_codec_swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firechip%2Fcobs_codec_swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firechip%2Fcobs_codec_swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firechip","download_url":"https://codeload.github.com/firechip/cobs_codec_swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firechip%2Fcobs_codec_swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35140187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"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":["byte-stuffing","cobs","cobs-r","encoding","framing","macos","serial","spm","swift","swift-package-manager"],"created_at":"2026-07-05T00:17:23.217Z","updated_at":"2026-07-05T00:17:23.793Z","avatar_url":"https://github.com/firechip.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CobsCodec\n\n[![CI](https://github.com/firechip/cobs_codec_swift/actions/workflows/ci.yml/badge.svg)](https://github.com/firechip/cobs_codec_swift/actions/workflows/ci.yml)\n[![Swift 6](https://img.shields.io/badge/swift-6-orange.svg)](https://swift.org)\n[![Platforms](https://img.shields.io/badge/platforms-macOS%20%7C%20iOS%20%7C%20Linux-lightgrey.svg)](#)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nPure-Swift **Consistent Overhead Byte Stuffing (COBS)** and **COBS/R** codec — the\nSwift member of the Firechip COBS family (alongside the\n[Rust](https://crates.io/crates/cobs_codec_rs),\n[Dart](https://pub.dev/packages/cobs_codec) and\n[Kotlin](https://github.com/firechip/cobs_codec_kt) implementations), verified\nbyte-identical against the shared\n[conformance vectors](https://github.com/firechip/cobs-conformance).\n\nCOBS encodes an arbitrary byte sequence into one that contains no zero (`0x00`)\nbyte, at a small, predictable cost (at most one extra byte per 254 bytes, plus\none). A single `0x00` can then reliably delimit packets on a serial/UART, USB, or\nBLE link. The `CobsCodec` library is **Swift-standard-library-only** — no\nFoundation, no Apple frameworks, no dependencies — so it runs on macOS, iOS,\ntvOS, watchOS, and Linux (and embedded Swift).\n\n## Install\n\nSwift Package Manager — add the dependency to your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/firechip/cobs_codec_swift.git\", from: \"1.0.0\"),\n],\ntargets: [\n    .target(name: \"YourTarget\", dependencies: [\"CobsCodec\"]),\n]\n```\n\nOr in Xcode: **File ▸ Add Package Dependencies…** and paste the repository URL.\n\n## Usage\n\n```swift\nimport CobsCodec\n\n// Encode / decode a single packet.\nlet encoded = Cobs.encode([0x11, 0x22, 0x00, 0x33]) // [0x03, 0x11, 0x22, 0x02, 0x33] — no 0x00\nlet decoded = try Cobs.decode(encoded)              // [0x11, 0x22, 0x00, 0x33]\n\n// COBS/R often saves the trailing overhead byte for small messages.\nCobsr.encode(Array(\"12345\".utf8))                   // [0x35, 0x31, 0x32, 0x33, 0x34] — \"51234\"\n\n// A custom delimiter byte (sentinel): the output avoids it, so it can delimit\n// frames instead of 0x00. `sentinel: 0` is identical to the plain codec.\nlet stuffed = Cobs.encode([0x11, 0x00, 0x22], sentinel: 0xAA) // [0xA8, 0xBB, 0xA8, 0x88] — no 0xAA\ntry Cobs.decode(stuffed, sentinel: 0xAA)                      // [0x11, 0x00, 0x22]\n\n// Decode in place, without a second buffer (COBS never expands on decode).\nvar buffer = Cobs.encode([0x11, 0x00, 0x22])\nlet n = try Cobs.decodeInPlace(\u0026buffer)             // n == 3; buffer[0..\u003cn] == [0x11, 0x00, 0x22]\n```\n\nReading a delimited serial stream — `CobsStreamDecoder` reassembles packets across\narbitrarily chunked reads (chunks need not align with frames):\n\n```swift\nlet frame = Framing.frame([0x11, 0x00, 0x22]) // COBS + trailing 0x00 delimiter\n\nlet decoder = CobsStreamDecoder(maxFrameLength: 4096)\nfor chunk in incomingChunks {                 // `chunk` is any [UInt8] read from the link\n    for packet in try decoder.feed(chunk) {\n        handle(packet)\n    }\n}\n```\n\nInvalid encoded input throws `CobsDecodeError` (`.zeroByte` / `.truncated`).\n\n## Features\n\n- **Basic COBS** and **COBS/R (Reduced)** — `Cobs` and `Cobsr`.\n- **Configurable sentinel** — every `encode`/`decode` takes a `sentinel:` byte\n  (default `0`) so frames can be delimited by any byte, not just `0x00`.\n- **In-place decoding** — `decodeInPlace(_:)` decodes within the buffer.\n- **Stream framing** — `Framing.frame`/`unframe` and the incremental\n  `CobsStreamDecoder`, with an optional `maxFrameLength` guard.\n- **Size helpers** — `maxEncodedLength(_:)` / `encodingOverhead(_:)` for\n  pre-allocation; `cobsMaxBlockLength` (`254`).\n- **Portable \u0026 dependency-free** — Swift-stdlib-only; macOS, iOS, tvOS, watchOS,\n  Linux, and embedded Swift.\n\n## Conformance\n\n`CobsCodec` is verified byte-identical against the shared\n[firechip/cobs-conformance](https://github.com/firechip/cobs-conformance) vectors\n(basic, COBS/R, configurable-sentinel, and decode-error cases) in CI, so it\ninteroperates exactly with the Rust, Dart, and Kotlin members of the family.\n\n## Benchmarks\n\nThroughput on a 1 KiB payload (`swift run -c release cobs-bench`), Swift 6.2 on an\nAMD Ryzen 7 3800XT under WSL2 — indicative (includes result allocation):\n\n| Operation | Throughput |\n| --------- | ---------- |\n| `Cobs.encode` | ~1090 MB/s |\n| `Cobs.decode` | ~1150 MB/s |\n| `Cobsr.encode` | ~850 MB/s |\n\n## Integrations\n\nThe module stays stdlib-only and Foundation-free, so framework glue lives in\nyour app rather than in the package. [INTEGRATIONS.md](INTEGRATIONS.md) has a\nverified copy-paste recipe: an `AsyncSequence` adapter (`bytes.cobsFrames()`)\nthat reframes a raw byte stream into decoded packets, built on the public\n`CobsStreamDecoder`.\n\n## Background\n\nStuart Cheshire and Mary Baker, \"Consistent Overhead Byte Stuffing\",\n*IEEE/ACM Transactions on Networking*, Vol. 7, No. 2, April 1999. **COBS/R** is a\nvariant by Craig McQueen.\n\n## License\n\nMIT © 2026 Alexander Salas Bastidas ([Firechip](https://firechip.dev)). See\n[LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirechip%2Fcobs_codec_swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirechip%2Fcobs_codec_swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirechip%2Fcobs_codec_swift/lists"}