SatCat5
satcat5::coap::Reader Class Referenceabstract

Detailed Description

Base-class for parsing CoAP message headers and options.

See also
coap_reader.h, coap::Option, coap::ReadSimple. This parser reads and stores the most common options, such as Uri-Path, Content-Format, and Size1. To process more options, create a child object that overrides read_user_option. To process only the basic CoAP options, use coap::ReadSimple.

Definition at line 162 of file coap_reader.h.

#include <coap_reader.h>

Inheritance diagram for satcat5::coap::Reader:
[legend]
Collaboration diagram for satcat5::coap::Reader:
[legend]

Public Member Functions

 Reader (satcat5::io::Readable *src)
 Create this object and read the message header. More...
 
 Reader (const Reader &)=delete
 
Readeroperator= (const Reader &)=delete
 
bool next_option ()
 Consume current option and advance to the next one. More...
 
satcat5::io::Readableread_data ()
 Access the message payload. More...
 
void read_finalize ()
 Forward read_finalize() to the inner source.
 
bool error () const
 < Error during parsing?
 
Code error_code () const
 < Code for the error
 
const char * error_msg () const
 < Optional message
 
u8 version () const
 < Version (Ver)
 
u8 type () const
 < Type (T)
 
u8 tkl () const
 < Token length (TKL)
 
Code code () const
 < Response code (CODE)
 
u16 msg_id () const
 < Message ID
 
u64 token () const
 < Token value
 
bool is_request () const
 < CON or NON request?
 
bool is_response () const
 < ACK request?
 
satcat5::coap::Optionoption ()
 
satcat5::util::optional< const char * > uri_path () const
 Accessors for parsed options.
 
satcat5::util::optional< u16 > format () const
 Accessors for parsed options.
 
satcat5::util::optional< u64 > size1 () const
 Accessors for parsed options.
 
satcat5::util::optional< u64 > block () const
 Accessors for parsed options.
 
u16 block_size () const
 Accessors for parsed options.
 
bool block_more () const
 Accessors for parsed options.
 
u32 block_num () const
 Accessors for parsed options.
 
satcat5::util::optional< u64 > block1 () const
 Accessors for parsed options.
 
u16 block1_size () const
 Accessors for parsed options.
 
bool block1_more () const
 Accessors for parsed options.
 
u32 block1_num () const
 Accessors for parsed options.
 
satcat5::util::optional< u64 > block2 ()
 Accessors for parsed options.
 
u16 block2_size () const
 Accessors for parsed options.
 
bool block2_more () const
 Accessors for parsed options.
 
u32 block2_num () const
 Accessors for parsed options.
 

Protected Types

enum class  State { OPTIONS , DATA , ERROR }
 List of possible parser states.
 

Protected Member Functions

void append_uri_path ()
 Uri-Path string builder.
 
void read_options ()
 Read all option headers, storing supported option fields. More...
 
virtual void read_user_option ()=0
 Handler called for each option with an unknown ID. More...
 
u16 read_var_int (u8 nybb)
 Read variable-length integer from Option header.
 
void set_error (Code code, const char *msg="")
 Set error code and stop further parsing.
 

Protected Attributes

char m_uri_path [SATCAT5_COAP_MAX_URI_PATH_LEN+1]
 URI path for this request.
 
unsigned m_uri_path_wridx
 Index into m_uri_path
 
satcat5::util::optional< u16 > m_format
 Content-Format.
 
satcat5::util::optional< u64 > m_block1
 Block1.
 
satcat5::util::optional< u64 > m_block2
 Block2.
 
satcat5::util::optional< u64 > m_size1
 Size1.
 
satcat5::io::Readable *const m_src
 Source buffer of CoAP message.
 
State m_state
 Parser state.
 
Code m_error_code
 Error code, or Empty to Reset.
 
const char * m_error_msg
 Diagnostic Payload for error.
 
const u8 m_type
 Version, type, TKL.
 
satcat5::coap::Code m_code
 Status code x.yy.
 
const u16 m_id
 Message ID.
 
u64 m_token
 Token (0-8 bytes)
 
satcat5::coap::Option m_opt
 Contents of the current option.
 

Constructor & Destructor Documentation

◆ Reader()

Reader::Reader ( satcat5::io::Readable src)
explicit

Create this object and read the message header.

The child class MUST call read_options in its constructor.

Definition at line 107 of file coap_reader.cc.

Member Function Documentation

◆ next_option()

bool ReadHeader::next_option ( )
inherited

Consume current option and advance to the next one.

Returns
True until all options have been read.

Definition at line 59 of file coap_reader.cc.

◆ read_data()

Readable * ReadHeader::read_data ( )
inherited

Access the message payload.

Calling this method discards any unparsed options.

Definition at line 90 of file coap_reader.cc.

◆ read_options()

void Reader::read_options ( )
protected

Read all option headers, storing supported option fields.

For each unrecognized option, call read_user_option. The child class MUST call read_options in its constructor.

Definition at line 116 of file coap_reader.cc.

◆ read_user_option()

virtual void satcat5::coap::Reader::read_user_option ( )
protectedpure virtual

Handler called for each option with an unknown ID.

When this method is called, use member variable m_opt to access the option ID and contents.

See also
coap::Option. The child class MUST define this method.

Implemented in satcat5::coap::ReadSimple.


The documentation for this class was generated from the following files: