SEDNL  .
Simple Event Driven Network Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Friends | List of all members
SedNL::PacketReader Class Reference

A reader (allow reading content from a Packet). More...

#include <Packet.hpp>

Public Member Functions

 PacketReader (const Packet &p)
 Build a reader from a Packet p.
 
template<typename T >
PacketReaderoperator>> (T &dt)
 Read dt from the PacketReader. More...
 
PacketReaderoperator>> (std::vector< char > &dt)
 
PacketReaderoperator>> (std::vector< Int8 > &dt)
 
PacketReaderoperator>> (std::vector< Int16 > &dt)
 
PacketReaderoperator>> (std::vector< Int32 > &dt)
 
PacketReaderoperator>> (std::vector< Int64 > &dt)
 
PacketReaderoperator>> (std::vector< UInt8 > &dt)
 
PacketReaderoperator>> (std::vector< UInt16 > &dt)
 
PacketReaderoperator>> (std::vector< UInt32 > &dt)
 
PacketReaderoperator>> (std::vector< UInt64 > &dt)
 
PacketReaderoperator>> (std::vector< float > &dt)
 
PacketReaderoperator>> (std::vector< double > &dt)
 
 operator bool () const noexcept
 True until the packet was completely read. More...
 
Packet::Type next_type () const noexcept
 Return the type of the next element. More...
 
template<>
PacketReaderoperator>> (char &dt)
 
template<>
PacketReaderoperator>> (Int8 &dt)
 
template<>
PacketReaderoperator>> (Int16 &dt)
 
template<>
PacketReaderoperator>> (Int32 &dt)
 
template<>
PacketReaderoperator>> (Int64 &dt)
 
template<>
PacketReaderoperator>> (UInt8 &dt)
 
template<>
PacketReaderoperator>> (UInt16 &dt)
 
template<>
PacketReaderoperator>> (UInt32 &dt)
 
template<>
PacketReaderoperator>> (UInt64 &dt)
 
template<>
PacketReaderoperator>> (float &dt)
 
template<>
PacketReaderoperator>> (double &dt)
 
template<>
PacketReaderoperator>> (std::string &dt)
 

Friends

template<typename... Args>
void read_as_object (PacketReader &packet_reader, Args &...args)
 Read all the argument as an object of length number_of_args(args). More...
 
std::ostream & operator<< (std::ostream &os, const Packet &p)
 Write a short description of a packet in a JSON like fashion. More...
 

Detailed Description

A reader (allow reading content from a Packet).

Definition at line 206 of file Packet.hpp.

Member Function Documentation

Packet::Type SedNL::PacketReader::next_type ( ) const
inlinenoexcept

Return the type of the next element.

Returns
The type of the next element to read. Unknow if the end was reached.

Definition at line 56 of file Packet.ipp.

SedNL::PacketReader::operator bool ( ) const
inlinenoexcept

True until the packet was completely read.

Returns
True if there is something to read, False otherwise.

Definition at line 51 of file Packet.ipp.

template<typename T >
PacketReader & SedNL::PacketReader::operator>> ( T &  dt)
inline

Read dt from the PacketReader.

This call is ignored if the end of the packet was reached. See PackerReader::operator bool().

If you call >> on types like [unsigned] char, [unsigned] short, [unsigned] long, the matching [U]IntN operator will be called.

In case of type = float, double the library assume that the system have 32, 64 bits types. Otherwise, it will result in undefined behavior. You don't have to worry for most of the systems where this library would actualy compile.

Parameters
[out]dtData
Returns
A reference to this.

Definition at line 141 of file Packet.ipp.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Packet p 
)
friend

Write a short description of a packet in a JSON like fashion.

The output is { data1 : type1, data2 : type2, ..., datan : typen, }.

Parameters
[out]osThe output stream.
[in]pThe packet to show.
Returns
The output stream.
template<typename... Args>
void read_as_object ( PacketReader packet_reader,
Args &...  args 
)
friend

Read all the argument as an object of length number_of_args(args).

Its the same behavior as unserialising a serialisable object containing fields in the same order and same type as args. See SEDNL_SERIALIZABLE in Serializer.hpp.

Parameters
[in]packet_readerReader from wich to read data.
[out]argsVariables to write into.

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