{"id":17300388,"url":"https://github.com/eric-wieser/packet-io","last_synced_at":"2025-04-14T12:31:39.936Z","repository":{"id":55894229,"uuid":"77180193","full_name":"eric-wieser/packet-io","owner":"eric-wieser","description":"An arduino library for framing protocols, inspired by PacketSerial","archived":false,"fork":false,"pushed_at":"2020-12-08T23:26:14.000Z","size":69,"stargazers_count":23,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T01:48:29.717Z","etag":null,"topics":["arduino","cobs","framing-protocols","streaming"],"latest_commit_sha":null,"homepage":"https://packetio.readthedocs.io","language":"C++","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/eric-wieser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-22T22:33:12.000Z","updated_at":"2025-02-16T15:01:08.000Z","dependencies_parsed_at":"2022-08-15T08:50:38.615Z","dependency_job_id":null,"html_url":"https://github.com/eric-wieser/packet-io","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric-wieser%2Fpacket-io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric-wieser%2Fpacket-io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric-wieser%2Fpacket-io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric-wieser%2Fpacket-io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eric-wieser","download_url":"https://codeload.github.com/eric-wieser/packet-io/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248881520,"owners_count":21176868,"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":["arduino","cobs","framing-protocols","streaming"],"created_at":"2024-10-15T11:28:00.977Z","updated_at":"2025-04-14T12:31:39.905Z","avatar_url":"https://github.com/eric-wieser.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"PacketIO [![documentation](https://readthedocs.org/projects/packetio/badge?version=latest)](http://packetio.readthedocs.org)\n========\n\nA PlatformIO library for framing packets sent or received over an arduino `Stream`, such as `Serial`.\n\nThe framing methods are exposed through the `PacketPrint` and `PacketStream` interfaces.\n\n * `PacketPrint` - extends `Print`:\n   * `bool end()` - end a packet, returning whether it was sucessfull\n   * `void abort()` - try as best as possible to start a new packet\n * `PacketStream` - extends `Stream`:\n   * `read()`, `peek()` - return `PacketStream::EOP` (-2) if the packet is complete (without touching the underlying stream), otherwise behaves as normal\n   * `next()` - stop reading from this packet, and move on\n\nFraming Protocols\n-----------------\n\nImplemented so far\n\n* [x] COBS\n* [x] SLIPS\n* [ ] COBS-R\n* [ ] Length-prefixed\n\nExamples\n--------\n\n### Writing\n\n```c++\n// pick a protocol here - everything below doesn't need to change\nCOBSPrint cobs_out(Serial);\n\nPacketPrint\u0026 out = cobs_out;\n\nout.print(\"Hello \");\nout.print(\"World\");\nout.end(); // mark the end of a packet\n\nout.print(\"Goodbye \");\nif(something_went_horribly_wrong) {\n\tout.abort(); // terminate this packet early and try to mark what was sent as bad\n}\nelse {\n\tout.print(\"World\");\n\tout.end();\n}\n```\n\n### Reading\n\n```c++\n// pick a protocol here - everything below doesn't need to change\nCOBSStream cobs_in(Serial);\n\nPacketStream\u0026 in = cobs_in;\n\nwhile(true) {\n\tchar message[10];\n\tsize_t n = 0;\n\n\twhile(true) {\n\t\t// read until we get something\n\t\tint c = in.read();\n\t\tif(c == in::EOF) continue;\n\n\t\t// detect End Of Packet\n\t\tif(c == in::EOP) break;\n\n\t\t// save anything else\n\t\tmessage[n++] = c;\n\t}\n\n\tSerial.print(\"Got: \");\n\tSerial.write(message, n);\n\tSerial.println();\n\n\t// start reading the next message\n\tin.next();\n}\n\n```\n\nFuture work\n-----------\n\nProvide an interface to [`nanopb`](https://github.com/nanopb/nanopb), that converts `Print` into `pb_ostream_s` and `Stream` into `pb_istream_s`, to allow protobufs to be framed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feric-wieser%2Fpacket-io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feric-wieser%2Fpacket-io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feric-wieser%2Fpacket-io/lists"}