Crate coap_message[][src]

CoAP mesage abstraction

This crate defines interfaces for readable and writable CoAP messages. Thus, it allows CoAP servers (and possibly clients) to be written independent of the actual CoAP library that is used to serialize and deserialize the messages to the protocol.

It also provides some trivial implementations of the types: Code for u8, OptionNumber for u16, as well as the heapmessage::HeapMessage for easy message storage on alloc systems.

Error handling

The readable message types are designed with minimal fallability -- for example, iterating over the options can not raise a "premature end of message" style error. This encodes the concept that having a message type implies validity of the message. It is backed by currently used libraries (RIOT's Gcoap, jnet-coap) performing the necessary validation steps when constructing message objects.

Whether this is a good idea remains to be seen.

Libraries that insist on minimizing the cycles spent parsing can opt to present invalid messages in truncated form, but need to be aware that this has important security implications.

Modules

heapmessage

This module provides HeapMessage, an implementation of all the message traits backed by heap memory.

numtraits

Traits

Code
FromOtherOption

Experimental trait for conversion between option representation, with the goal to later avoid the conversion step via u16 and specialize for T->T conversions.

MessageOption

Iteration item for option values

MinimalWritableMessage

A message that needs to have its code, any options in ascending order and its payload set in that very sequence.

MutableWritableMessage

A message that allows later manipulation of a once set payload, and later truncation.

OptionNumber
ReadableMessage
SeekWritableMessage

Marker trait that indicates that the sequence of calling set_code, add_option and set_payload is not fixed. The sequence of calls only has meaning in that later set_code and set_payload calls override earlier ones, and that add_option on the same option number are stored in their sequence.

WithSortedOptions

Marker trait that indicates that ReadableMessage::options are produced in ascending sequence.