{"id":16533956,"url":"https://github.com/martindisch/coap-lite","last_synced_at":"2025-04-04T16:09:41.472Z","repository":{"id":35103463,"uuid":"206935868","full_name":"martindisch/coap-lite","owner":"martindisch","description":"A lightweight CoAP message manipulation crate, ideal for embedded environments","archived":false,"fork":false,"pushed_at":"2025-01-22T20:02:14.000Z","size":320,"stargazers_count":30,"open_issues_count":3,"forks_count":22,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-28T15:09:34.036Z","etag":null,"topics":["coap","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martindisch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-3RD-PARTY","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":"2019-09-07T08:00:50.000Z","updated_at":"2025-01-22T20:02:17.000Z","dependencies_parsed_at":"2024-06-21T04:41:43.768Z","dependency_job_id":"a8d6e940-82ce-4486-a595-3a646ea7a5da","html_url":"https://github.com/martindisch/coap-lite","commit_stats":{"total_commits":143,"total_committers":9,"mean_commits":15.88888888888889,"dds":0.2517482517482518,"last_synced_commit":"54ea990369c0c4248d8a933321cf50fc646cfc86"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martindisch%2Fcoap-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martindisch%2Fcoap-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martindisch%2Fcoap-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martindisch%2Fcoap-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martindisch","download_url":"https://codeload.github.com/martindisch/coap-lite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208142,"owners_count":20901570,"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":["coap","rust"],"created_at":"2024-10-11T18:16:16.993Z","updated_at":"2025-04-04T16:09:41.431Z","avatar_url":"https://github.com/martindisch.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# coap-lite\n\n[![Latest version](https://img.shields.io/crates/v/coap-lite)](https://crates.io/crates/coap-lite)\n[![Documentation](https://docs.rs/coap-lite/badge.svg)](https://docs.rs/coap-lite)\n[![License](https://img.shields.io/crates/l/coap-lite)](https://github.com/martindisch/coap-lite#license)\n\n\u003c!-- cargo-sync-readme start --\u003e\n\nA lightweight low-level CoAP message manipulation crate.\n\nIts goal is to be compliant with the CoAP standards and to provide a\nbuilding block for libraries (e.g.\n[coap](https://github.com/Covertness/coap-rs)) and applications.\n\n`coap-lite` supports `#![no_std]` and embedded environments.\n\nIt was originally based on the improved low-level message handling code\nfrom the [coap] crate as well as [rust-async-coap], made to work in bare\nmetal environments.\n\n## Supported RFCs\n\n- CoAP [RFC 7252](https://tools.ietf.org/html/rfc7252)\n- CoAP Observe Option [RFC 7641](https://tools.ietf.org/html/rfc7641)\n- Too Many Requests Response Code [RFC 8516](https://tools.ietf.org/html/rfc8516)\n- Block-Wise Transfers [RFC 7959](https://tools.ietf.org/html/rfc7959)\n- Constrained RESTful Environments (CoRE) Link Format\n  [RFC6690](https://tools.ietf.org/html/rfc6690#:~:text=well-known%2Fcore)\n\n## Usage\n\nThis crate provides several types that can be used to build, modify and\nencode/decode CoAP messages to/from their byte representation.\n\n**Note for no_std users**: it does require allocation, so you might have to\nset a global allocator depending on your target.\n\n### Client\n\nThe following example uses `std::net::UdpSocket` to send the UDP packet but\nyou can use anything, e.g. [smoltcp](https://github.com/smoltcp-rs/smoltcp)\nfor embedded.\n\n```rust\nuse coap_lite::{\n    CoapRequest, RequestType as Method\n};\nuse std::net::{SocketAddr, UdpSocket};\n\nfn main() {\n    let mut request: CoapRequest\u003cSocketAddr\u003e = CoapRequest::new();\n\n    request.set_method(Method::Get);\n    request.set_path(\"/test\");\n\n    let socket = UdpSocket::bind(\"127.0.0.1:0\").unwrap();\n\n    let packet = request.message.to_bytes().unwrap();\n    socket.send_to(\u0026packet[..], \"127.0.0.1:5683\").expect(\"Could not send the data\");\n}\n```\n\n### Server\n\n```rust\nuse coap_lite::{CoapRequest, Packet};\nuse std::net::{UdpSocket};\n\nfn main() {\n    let socket = UdpSocket::bind(\"127.0.0.1:5683\").unwrap();\n    let mut buf = [0; 100];\n    let (size, src) = socket.recv_from(\u0026mut buf).expect(\"Didn't receive data\");\n\n    println!(\"Payload {:x?}\", \u0026buf[..size]);\n\n    let packet = Packet::from_bytes(\u0026buf[..size]).unwrap();\n    let request = CoapRequest::from_packet(packet, src);\n\n    let method = request.get_method().clone();\n    let path = request.get_path();\n\n    println!(\"Received CoAP request '{:?} {}' from {}\", method, path, src);\n\n    let mut response = request.response.unwrap();\n    response.message.payload = b\"OK\".to_vec();\n\n    let packet = response.message.to_bytes().unwrap();\n    socket.send_to(\u0026packet[..], \u0026src).expect(\"Could not send the data\");\n}\n```\n\n### Low-level binary conversion\n\n```rust\nuse coap_lite::{\n    CoapOption, MessageClass, MessageType,\n    Packet, RequestType, ResponseType,\n};\n\nlet mut request = Packet::new();\nrequest.header.message_id = 23839;\nrequest.header.code = MessageClass::Request(RequestType::Get);\nrequest.set_token(vec![0, 0, 57, 116]);\nrequest.add_option(CoapOption::UriHost, b\"localhost\".to_vec());\nrequest.add_option(CoapOption::UriPath, b\"tv1\".to_vec());\nassert_eq!(\n    [\n        0x44, 0x01, 0x5D, 0x1F, 0x00, 0x00, 0x39, 0x74, 0x39, 0x6C, 0x6F,\n        0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x83, 0x74, 0x76, 0x31,\n    ],\n    request.to_bytes().unwrap()[..]\n);\n\nlet response = Packet::from_bytes(\u0026[\n    0x64, 0x45, 0x5D, 0x1F, 0x00, 0x00, 0x39, 0x74, 0xFF, 0x48, 0x65,\n    0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21,\n])\n.unwrap();\nassert_eq!(23839, response.header.message_id);\nassert_eq!(\n    MessageClass::Response(ResponseType::Content),\n    response.header.code\n);\nassert_eq!(MessageType::Acknowledgement, response.header.get_type());\nassert_eq!([0, 0, 57, 116], response.get_token()[..]);\nassert_eq!(b\"Hello World!\", \u0026response.payload[..]);\n```\n\n[coap]: https://github.com/covertness/coap-rs\n[rust-async-coap]: https://github.com/google/rust-async-coap\n\n\u003c!-- cargo-sync-readme end --\u003e\n\n## License\n\nLicensed under either of\n\n- [Apache License, Version 2.0](LICENSE-APACHE)\n- [MIT license](LICENSE-MIT)\n\nat your option.\n\nThis is a modification of the [coap](https://github.com/covertness/coap-rs)\nand [rust-async-coap](https://github.com/google/rust-async-coap) crates, their\nlicenses are in [LICENSE-3RD-PARTY](LICENSE-3RD-PARTY).\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartindisch%2Fcoap-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartindisch%2Fcoap-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartindisch%2Fcoap-lite/lists"}