{"id":18446850,"url":"https://github.com/nmeum/zoap","last_synced_at":"2025-04-08T00:31:58.017Z","repository":{"id":74907428,"uuid":"413032875","full_name":"nmeum/zoap","owner":"nmeum","description":"A WiP CoAP implementation for bare-metal constrained devices in Zig","archived":false,"fork":false,"pushed_at":"2024-12-30T22:35:38.000Z","size":104,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T03:26:03.314Z","etag":null,"topics":["bare-metal","coap","coap-server","embedded","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nmeum.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-03T09:31:53.000Z","updated_at":"2025-02-14T03:15:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"35ba7a68-1eb9-432b-bbde-c996790de702","html_url":"https://github.com/nmeum/zoap","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/nmeum%2Fzoap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzoap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzoap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzoap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmeum","download_url":"https://codeload.github.com/nmeum/zoap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755409,"owners_count":20990617,"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":["bare-metal","coap","coap-server","embedded","zig"],"created_at":"2024-11-06T07:11:03.725Z","updated_at":"2025-04-08T00:31:58.009Z","avatar_url":"https://github.com/nmeum.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zoap\n\nA WiP [CoAP][rfc 7252] implementation for bare-metal [constrained devices][rfc 7228] in [Zig][zig web].\n\n## Status\n\nPresently, the majority of the CoAP standard is not implemented.\nHowever, creating a very basic CoAP server which sends and receives\nnon-confirmable messages is possible and already done as part of my\n[zig-riscv-embedded][zig-riscv github] project. Since the code focus\non constrained bare-metal targets, it is optimized for a small memory\nfootprint and uses statically allocated fixed-size buffers instead of\nperforming dynamic memory allocation. Furthermore, it does not use any\nOS-specific code from the Zig standard library (e.g. Sockets).\n\nThe code is known to compile with Zig `0.13.0`.\n\n## Usage\n\nAs noted above, this library targets freestanding constrained devices.\nFor this reason, all memory is statically allocated. To implement a CoAP\nserver with zoap, the central data structure is the Dispatcher. This\nDispatcher takes a list of Resources and forwards incoming requests to\nthem if the URI in the request matches one of the available resources.\nBoth, the dispatcher and the resources need to be statically allocated,\ne.g. as global variables:\n\n\tconst resources = \u0026[_]zoap.Resource{\n\t    .{ .path = \"hello\", .handler = helloHandler },\n\t    .{ .path = \"about\", .handler = aboutHandler },\n\t};\n\tvar dispatcher = zoap.Dispatcher{\n\t    .resources = resources,\n\t};\n\nThe code above allocates a dispatcher with two resources: `/hello` and\n`/about`. An incoming CoAP request for either of those resources invokes\nthe associated handler function. The `helloHandler` implementation may\nlooks as follows:\n\n\tpub fn helloHandler(resp: *zoap.Response, req: *zoap.Request) codes.Code {\n\t    if (!req.header.code.equal(codes.GET))\n\t        return codes.BAD_METHOD;\n\t\n\t    const w = resp.payloadWriter();\n\t    w.writeAll(\"Hello, World!\") catch {\n\t        return codes.INTERNAL_ERR;\n\t    };\n\t\n\t    return codes.CONTENT;\n\t}\n\nThe function takes two parameters: The resulting CoAP response and the\nincoming CoAP request. The handler returns the CoAP response code for\nthe incoming request. The implementation above first checks the request\nmethod, if it doesn't match the expected method a response with a\nMethod Not Allowed status code is returned. Otherwise, the\n`helloHandler` writes `Hello, World!` to the response body and, unless an\nerror occurs, it responses with a successful content response code.\n\nIn order to invoke these handlers, incoming CoAP requests need to be\nforwarded to the Dispatcher via the `Dispatcher.dispatch` method which\ntakes an incoming CoAP request as a parameter and forwards it to the\nmatching resource (if any). The method returns the appropriate CoAP\nresponse. Since this library attempts to be OS-independent, the code for\nretrieving incoming requests and sending responses to these requests\ndepends on your environment. For example, CoAP request may be read from\na UDP socket in a POSIX environment.\n\nFor or a more detailed and complete usage example refer to\n[zig-riscv-embedded][zig-riscv github] which reads incoming requests\nfrom a [SLIP][rfc 1055] serial interface.\n\n## Test vectors\n\nFor parsing code, test vectors are created using the existing\n[go-coap][go-coap github] implementation written in [Go][go website].\nTest vectors are generated using `./src/testvectors/generate.go` and\navailable as `./src/testvectors/*.bin` files. These files are tracked\nin the Git repositories and thus Go is not necessarily needed to run\nexisting tests.\n\nEach Zig test case embeds this file via [`@embedFile`][zig embedFile].\nAll existing Zig parser test cases can be run using:\n\n\t$ zig test src/packet.zig\n\nNew test cases can be added by modifying `./src/testvectors/generate.go` and\n`./src/packet.zig`. Afterwards, the test case files need to be regenerated\nusing:\n\n\t$ cd ./src/testvectors \u0026\u0026 go build -trimpath \u0026\u0026 ./testvectors\n\nNew test vectors must be committed to the Git repository.\n\n## License\n\nThis program is free software: you can redistribute it and/or modify it\nunder the terms of the GNU Affero General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or (at\nyour option) any later version.\n\nThis program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\nGeneral Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License\nalong with this program. If not, see \u003chttps://www.gnu.org/licenses/\u003e.\n\n[rfc 7252]: https://datatracker.ietf.org/doc/rfc7252/\n[rfc 7228]: https://datatracker.ietf.org/doc/rfc7228/\n[rfc 1055]: https://datatracker.ietf.org/doc/rfc1055/\n[zig web]: https://ziglang.org/\n[zig-riscv github]: https://github.com/nmeum/zig-riscv-embedded\n[go-coap github]: https://github.com/plgd-dev/go-coap\n[go website]: https://golang.org\n[zig embedFile]: https://ziglang.org/documentation/0.9.1/#embedFile\n[zig import]: https://ziglang.org/documentation/0.9.1/#import\n[git submodules]: https://git-scm.com/book/en/v2/Git-Tools-Submodules\n[gyro github]: https://github.com/mattnite/gyro\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmeum%2Fzoap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmeum%2Fzoap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmeum%2Fzoap/lists"}