SatCat5
satcat5::coap::ReadSimple Class Referencefinal

Detailed Description

Wrapper for coap::ReadOptions that automatically parses options, rejecting any message with unrecognized Critical options.

See also
coap_reader.h, coap::Option, coap::ReadOptions.

Definition at line 234 of file coap_reader.h.

#include <coap_reader.h>

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

Public Member Functions

 ReadSimple (satcat5::io::Readable *src)
 Wrapper object automatically reads header and options.
 
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 read_user_option () override
 The default implementation simply rejects any unsupported "Critical" Option as defined in RFC 7252, Section 5.4.1.
 
void append_uri_path ()
 Uri-Path string builder.
 
void read_options ()
 Read all option headers, storing supported option fields. 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.
 

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 ( )
protectedinherited

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.


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