Tiny protocol  0.9.0
Tiny communication protocol for microcontrollers
Public Member Functions | Friends | List of all members
Tiny::IPacket Class Reference

#include <TinyPacket.h>

Inheritance diagram for Tiny::IPacket:
Inheritance graph
[legend]

Public Member Functions

 IPacket (char *buf, size_t size)
 
virtual ~IPacket ()=default
 
void clear ()
 
void put (uint8_t byte)
 
void put (char chr)
 
void put (uint16_t data)
 
void put (uint32_t data)
 
void put (int16_t data)
 
void put (const char *str)
 
void put (const IPacket &pkt)
 
uint8_t getByte ()
 
char getChar ()
 
uint16_t getUint16 ()
 
int16_t getInt16 ()
 
uint32_t getUint32 ()
 
char * getString ()
 
size_t size () const
 
size_t maxSize () const
 
char * data ()
 
uint8_t & operator[] (size_t idx)
 
IPacketoperator= (char chr)
 

Friends

class ProtoHd
 
class IProtoFd
 
class ProtoLight
 

Detailed Description

Describes packet entity and provides API methods to manipulate the packet.

Constructor & Destructor Documentation

◆ IPacket()

Tiny::IPacket::IPacket ( char *  buf,
size_t  size 
)
inline

Creates packet object.

Parameters
buf- pointer to the buffer to store packet data
size- size of the buffer to hold packet data
Note
passed buffer must exist all lifecycle of the Packet object.

◆ ~IPacket()

virtual Tiny::IPacket::~IPacket ( )
virtualdefault

Destroys the object

Member Function Documentation

◆ clear()

void Tiny::IPacket::clear ( )
inline

Clears Packet state. Buffer and its size are preserved.

◆ data()

char* Tiny::IPacket::data ( )
inline

Returns size of payload data in the received packet.

Returns
size of payload data.

◆ getByte()

uint8_t Tiny::IPacket::getByte ( )
inline

Reads next byte from the packet.

Returns
byte from the packet.

◆ getChar()

char Tiny::IPacket::getChar ( )
inline

Reads next character from the packet.

Returns
character from the packet.

◆ getInt16()

int16_t Tiny::IPacket::getInt16 ( )
inline

Reads next signed 16-bit integer from the packet.

Returns
signed 16-bit integer.

◆ getString()

char* Tiny::IPacket::getString ( )
inline

Reads zero-terminated string from the packet.

Returns
zero-terminated string.

◆ getUint16()

uint16_t Tiny::IPacket::getUint16 ( )
inline

Reads next unsigned 16-bit integer from the packet.

Returns
unsigned 16-bit integer.

◆ getUint32()

uint32_t Tiny::IPacket::getUint32 ( )
inline

Reads next unsigned 32-bit integer from the packet.

Returns
unsigned 32-bit integer.

◆ maxSize()

size_t Tiny::IPacket::maxSize ( ) const
inline

Returns maximum size of packet buffer.

Returns
max size of packet buffer.

◆ operator=()

IPacket& Tiny::IPacket::operator= ( char  chr)
inline

Assign operator = puts next char to the packet. Several assign operators put one by one several chars.

◆ operator[]()

uint8_t& Tiny::IPacket::operator[] ( size_t  idx)
inline

You may refer to Packet payload data directly by using operator []

◆ put() [1/7]

void Tiny::IPacket::put ( uint8_t  byte)
inline

Puts next byte to the packet. For example, after calling this method twice: put(5), put(10), - the Packet will contain 5,10.

Parameters
byte- data byte to put.

◆ put() [2/7]

void Tiny::IPacket::put ( char  chr)
inline

Puts next char to the packet. For example, after calling this method twice: put('a'), put('c'), - the Packet will contain 'ac'.

Parameters
chr- character to put.

◆ put() [3/7]

void Tiny::IPacket::put ( uint16_t  data)
inline

Puts next 16-bit unsigned integer to the packet.

Parameters
data- data to put.

◆ put() [4/7]

void Tiny::IPacket::put ( uint32_t  data)
inline

Puts next 32-bit unsigned integer to the packet.

Parameters
data- data to put.

◆ put() [5/7]

void Tiny::IPacket::put ( int16_t  data)
inline

Puts next 16-bit signed integer to the packet.

Parameters
data- data to put.

◆ put() [6/7]

void Tiny::IPacket::put ( const char *  str)
inline

Puts next null-terminated string to the packet.

Parameters
str- string to put.

◆ put() [7/7]

void Tiny::IPacket::put ( const IPacket pkt)
inline

Adds data from packet to the new packet being built.

Parameters
pkt- reference to the Packet to add.

◆ size()

size_t Tiny::IPacket::size ( ) const
inline

Returns size of payload data in the received packet.

Returns
size of payload data.

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