src.dualinventive.com/jjacobs/dinetrpcll-sniffer/include/server/LowLevel.h

61 lines
1.8 KiB
C++

/**
* @file include/protocol/LowLevel.h
* @brief Low level DI-Net protocol handling
* @date April 30, 2015
* @author R.W.A. van der Heijden
* @copyright 2015 Dual Inventive Technology Centre B.V.
*
* Generic low level DI-Net layer handler, it can handle incoming packets
* and create them
*/
#ifndef INCLUDE_SERVER_LOWLEVEL_H_
#define INCLUDE_SERVER_LOWLEVEL_H_
#include <memory>
#include <di/Buffer.h>
/**
* @class LowLevel
* Low level protocol handling
*/
class LowLevel {
public:
struct LowLevelMessage {
unsigned char type; /**< Message type @ref DinetMessageTypes */
size_t length; /**< length of unpacked data is stored here */
Di::Buffer data; /**< Unpacked data is stored here */
};
/**
* Parse incoming data, this function erases all unwanted data from the
* stream, but not buffer the rest elsewhere
* @param stream incoming data which must get parsed
* @return dinet errno or @ref DinetMessageTypes
*/
std::shared_ptr<LowLevelMessage> decode(std::shared_ptr<Di::Buffer> stream);
/**
* Wrap a packet into the generic message format
* this functions modifies the packet in place
* @param stream incoming data, wrapped in the lowlevel format
* @return size of total data in stream
*/
static int createMessage(std::shared_ptr<Di::Buffer> stream);
/**
* Wrap a device_uid into a generic handshake
* this functions modifies the packet in place
* @param device_uid which must be wrapped in a handshake
* @return size of total data in stream
*/
int createReply(std::shared_ptr<Di::Buffer> obuf, bool positive);
/**
* Fill dinet time string pack
* this functions modifies the packet in place
* @param time which is filled with getDinetNow
* @return size of total data in stream
*/
int createTime(std::shared_ptr<Di::Buffer> time);
};
#endif // INCLUDE_SERVER_LOWLEVEL_H_