15 unsigned Option::value_str(
char* dst) {
25 for (
unsigned a = 0 ; a < m_len ; ++a) {
26 accum = (accum << 8) +
read_u8();
33 , m_state(
State::OPTIONS)
34 , m_error_code(CODE_EMPTY)
35 , m_error_msg(nullptr)
36 , m_type(src->read_u8())
37 , m_code(src->read_u8())
38 , m_id(src->read_u16())
42 if ((
version() != satcat5::coap::VERSION1) || (
tkl() > 8)) {
53 for (
unsigned a = 0 ; a <
tkl() ; ++a) {
61 if (
m_state != State::OPTIONS)
return false;
68 m_state = State::DATA;
return false;
74 m_state = State::DATA;
return false;
99 if (nybb <= 12)
return u16(nybb);
101 if (nybb == 14)
return u16(269u +
m_src->read_u16());
110 , m_uri_path_wridx(0)
Accessor for a single CoAP option field.
u16 len() const
Option Number (RFC-7252, Section 3.1).
bool is_critical() const
Option bit mapping indicates relevant properties (Section 5.4.6).
u16 id() const
Option Number (RFC-7252, Section 3.1).
unsigned value_str(char *dst)
Access the Option Value as a UTF-8 string ("string").
u64 value_uint()
Access the Option Value as an unsigned integer ("uint").
Wrapper for coap::ReadOptions that automatically parses options, rejecting any message with unrecogni...
void read_user_option() override
The default implementation simply rejects any unsupported "Critical" Option as defined in RFC 7252,...
Base-class for parsing CoAP message headers and options.
void read_options()
Read all option headers, storing supported option fields.
unsigned m_uri_path_wridx
Index into m_uri_path
satcat5::util::optional< u64 > m_block2
Block2.
satcat5::util::optional< u64 > m_size1
Size1.
char m_uri_path[SATCAT5_COAP_MAX_URI_PATH_LEN+1]
URI path for this request.
void append_uri_path()
Uri-Path string builder.
satcat5::util::optional< u64 > m_block1
Block1.
satcat5::util::optional< u16 > m_format
Content-Format.
Reader(satcat5::io::Readable *src)
Create this object and read the message header.
virtual void read_user_option()=0
Handler called for each option with an unknown ID.
Limited read of next N bytes.
bool read_bytes(unsigned nbytes, void *dst) override
Read 0 or more bytes into a buffer.
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
Abstract API for reading byte-streams and packets.
u8 read_u8()
One of many functions for reading integer/floating point values, see details.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
constexpr Code CODE_BAD_REQUEST(4, 0)
< 2.31 Continue
constexpr u16 OPTION_MAX_AGE
Option: Max-Age.
constexpr Code CODE_BAD_OPTION(4, 2)
< 4.01 Unauthorized
constexpr u8 PAYLOAD_MARKER
CoAP message header VERSION and TYPE fields (Section 3).
constexpr u16 OPTION_BLOCK2
Option: Block transfer (RFC7959)
constexpr u16 OPTION_SIZE1
Option: Size1.
constexpr u16 OPTION_BLOCK1
Option: Block transfer (RFC7959)
constexpr u16 OPTION_URI_PATH
Option: Uri-Path.
constexpr u16 OPTION_FORMAT
Option: Content-Format.
Message parsing for the Constrained Applications Protocol (CoAP)
constexpr bool is_empty() const
Category tests: 0.00 = Empty (may be request or response) 0.01-0.31 = Request 2.00-2....