EmBencode
Implementation of the Bencode serialisation format for embedded microcontrollers.
 All Classes Files Functions Pages
EmBdecode Class Reference

Decoder class, needs an external buffer to collect the incoming data. More...

#include <EmBencode.h>

Public Types

enum  {
  T_STRING = 0, T_NUMBER = 251, T_DICT, T_LIST,
  T_POP, T_END
}
 Types of tokens, as returned by nextToken().
 

Public Member Functions

 EmBdecode (char *buf, uint8_t len)
 Initialize a decoder instance with the specified buffer space. More...
 
uint8_t reset ()
 Reset the decoder - can be called to prepare for a new round of decoding.
 
uint8_t process (char ch)
 Process a single incoming caharacter. More...
 
uint8_t nextToken ()
 Call this after process() is done, to extract each of the data tokens. More...
 
const char * asString (uint8_t *plen=0)
 Extract the last token as string (works for T_STRING and T_NUMBER). More...
 
long asNumber ()
 Extract the last token as number (also works for strings if numeric). More...
 

Protected Member Functions

void AddToBuf (char ch)
 

Protected Attributes

char level
 
char * bufPtr
 
uint8_t bufLen
 
uint8_t count
 
uint8_t next
 
uint8_t last
 
uint8_t state
 

Detailed Description

Decoder class, needs an external buffer to collect the incoming data.

Constructor & Destructor Documentation

EmBdecode::EmBdecode ( char *  buf,
uint8_t  len 
)
inline

Initialize a decoder instance with the specified buffer space.

Parameters
bufPointer to the buffer which will be used by the decoder.
lenSize of the buffer, must be in the range 50 to 255.

Member Function Documentation

long EmBdecode::asNumber ( )

Extract the last token as number (also works for strings if numeric).

Returns
Returns the decoded integer, max 32-bit signed in this version.
const char * EmBdecode::asString ( uint8_t *  plen = 0)

Extract the last token as string (works for T_STRING and T_NUMBER).

Parameters
plenThis variable will receive the size, if present.
Returns
Returns pointer to a zero-terminated string in the decode buffer.
uint8_t EmBdecode::nextToken ( )

Call this after process() is done, to extract each of the data tokens.

Returns
Returns one of the T_STRING .. T_END enumeration codes.
uint8_t EmBdecode::process ( char  ch)

Process a single incoming caharacter.

Returns
Returns a count > 0 when the buffer contains a complete packet.

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