|
SatCat5
|
Message formatting for the Constrained Applications Protocol (CoAP).
This class implements message formatting for the Constrained Applications Protocol (CoAP) defined in IETF RFC-7252: https://www.rfc-editor.org/rfc/rfc7252
The coap::Writer object is typically ephemeral:
Definition at line 26 of file coap_writer.h.
#include <coap_writer.h>
Public Member Functions | |
| constexpr | Writer (satcat5::io::Writeable *dst, bool write_max_age=true) |
| Create this object and set the destination. More... | |
| bool | ready () const |
| Is this object ready for writing? Note: This is the only safe method if m_dst is null. | |
| bool | write_header (u8 type, Code code, u16 msg_id, u64 token=0, u8 tkl=0) |
| Always start by writing the header, with optional token. More... | |
| bool | write_header (Code code, Connection *request) |
| Alternate version of write_header for responding to a query. More... | |
| bool | write_uri (u16 id, const char *str) |
| Convert a URI to consecutive Uri-Path options. | |
| satcat5::io::Writeable * | write_data () |
| After the last option, start writing message data. More... | |
| bool | write_finalize () |
| After the last option, finish with an empty message. | |
| bool | write_option (u16 id, unsigned len, const void *data) |
| Write option(s) one at a time, in various formats. More... | |
| bool | write_option (u16 id, const char *str) |
| Write option(s) one at a time, in various formats. More... | |
| bool | write_option (u16 id, u64 value) |
| Write option(s) one at a time, in various formats. More... | |
Protected Member Functions | |
| bool | write_optid (u16 id, unsigned len) |
| void | write_varint (u64 x, unsigned len) |
| void | insert_max_age (u16 next_id=0) |
Protected Attributes | |
| satcat5::io::Writeable *const | m_dst |
| u16 | m_last_opt |
| Previous option-ID. | |
| bool | m_insert_max_age |
| Add Max-Age=0 to disable caching. | |
|
inlineconstexpr |
Create this object and set the destination.
Note: The resulting object is safe to use even if dst is null.
Definition at line 30 of file coap_writer.h.
| satcat5::io::Writeable * Writer::write_data | ( | ) |
After the last option, start writing message data.
Call this method exactly once, then finalize when ready.
Definition at line 88 of file coap_writer.cc.
| bool Writer::write_header | ( | Code | code, |
| Connection * | request | ||
| ) |
Alternate version of write_header for responding to a query.
Automatically determines the response type, then copies the message-ID and token directly from the incoming request.
Definition at line 43 of file coap_writer.cc.
| bool Writer::write_header | ( | u8 | type, |
| Code | code, | ||
| u16 | msg_id, | ||
| u64 | token = 0, |
||
| u8 | tkl = 0 |
||
| ) |
Always start by writing the header, with optional token.
Token length can be set manually (tkl > 0) or automatically.
Definition at line 25 of file coap_writer.cc.
| bool Writer::write_option | ( | u16 | id, |
| const char * | str | ||
| ) |
Write option(s) one at a time, in various formats.
Note: Options MUST be written in ascending-ID order.
Definition at line 57 of file coap_writer.cc.
| bool Writer::write_option | ( | u16 | id, |
| u64 | value | ||
| ) |
Write option(s) one at a time, in various formats.
Note: Options MUST be written in ascending-ID order.
Definition at line 61 of file coap_writer.cc.
| bool Writer::write_option | ( | u16 | id, |
| unsigned | len, | ||
| const void * | data | ||
| ) |
Write option(s) one at a time, in various formats.
Note: Options MUST be written in ascending-ID order.
Definition at line 49 of file coap_writer.cc.