no-std coap-lite

A lightweight CoAP message manipulation crate, ideal for embedded environments

3 releases (breaking)

✓ Uses Rust 2018 edition

0.3.0 Sep 12, 2019
0.2.0 Sep 9, 2019
0.1.0 Sep 8, 2019

#117 in No standard library

Download history 5/week @ 2019-10-05 4/week @ 2019-10-12 10/week @ 2019-10-19 43/week @ 2019-10-26 8/week @ 2019-11-02 2/week @ 2019-11-09 9/week @ 2019-11-16 9/week @ 2019-11-23 3/week @ 2019-11-30 44/week @ 2019-12-07 1/week @ 2019-12-14 3/week @ 2019-12-28 18/week @ 2020-01-11

52 downloads per month




Latest version Documentation License

A lightweight, #![no_std] CoAP message manipulation crate, ideal for embedded environments.

It's based on the improved low-level message handling code from the coap crate, made to work in bare metal environments.


This crate provides several types that can be used to build, modify and encode/decode CoAP messages to/from their byte representation.

It does require allocation, so you might have to set a global allocator depending on your target.


use coap_lite::{
    CoapOption, MessageClass, MessageType,
    Packet, RequestType, ResponseType,

let mut request = Packet::new();
request.header.message_id = 23839;
request.header.code = MessageClass::Request(RequestType::Get);
request.set_token(vec![0, 0, 57, 116]);
request.add_option(CoapOption::UriHost, b"localhost".to_vec());
request.add_option(CoapOption::UriPath, b"tv1".to_vec());
        0x44, 0x01, 0x5D, 0x1F, 0x00, 0x00, 0x39, 0x74, 0x39, 0x6C, 0x6F,
        0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x83, 0x74, 0x76, 0x31,

let response = Packet::from_bytes(&[
    0x64, 0x45, 0x5D, 0x1F, 0x00, 0x00, 0x39, 0x74, 0xFF, 0x48, 0x65,
    0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21,
assert_eq!(23839, response.header.message_id);
assert_eq!(MessageType::Acknowledgement, response.header.get_type());
assert_eq!([0, 0, 57, 116], response.get_token()[..]);
assert_eq!(b"Hello World!", &response.payload[..]);


Licensed under either of

at your option.

This is a modification of the coap crate, its license is in LICENSE-3RD-PARTY.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps