2019-02-12 13:12:11 +03:00
|
|
|
#ifndef CLIENTPROTOCOL_H
|
|
|
|
#define CLIENTPROTOCOL_H
|
|
|
|
|
|
|
|
#include "clientprotocol_global.h"
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
#define DEFAULT_SNAKE_SERVER "127.0.0.1"
|
|
|
|
#define LOCAL_SNAKE_SERVER "127.0.0.1"
|
|
|
|
|
|
|
|
#define DEFAULT_SNAKE_PORT 7777
|
|
|
|
|
2019-02-12 13:12:11 +03:00
|
|
|
namespace ClientProtocol {
|
2019-02-13 13:03:40 +03:00
|
|
|
enum Type: unsigned char {
|
|
|
|
Responke = 0,
|
|
|
|
Request = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Command: unsigned char {
|
|
|
|
undefined = 0x00,
|
|
|
|
ping = 0x01,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The Header struct 1 byte
|
|
|
|
*/
|
|
|
|
struct Header {
|
|
|
|
/**
|
|
|
|
* @brief size - size of package data (not header)
|
|
|
|
*/
|
|
|
|
unsigned char size: 4;
|
|
|
|
/**
|
|
|
|
* @brief type of package see Type
|
|
|
|
*/
|
|
|
|
unsigned char type: 1;
|
|
|
|
/**
|
|
|
|
* @brief command of pacage see Command
|
|
|
|
*/
|
|
|
|
unsigned char command: 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Header default constructor
|
|
|
|
*/
|
|
|
|
Header();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief isValid
|
|
|
|
* @return true if header is valid
|
|
|
|
*/
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief reset - reset all data and set for header invalid status
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The Package struct
|
|
|
|
*/
|
|
|
|
struct Package {
|
|
|
|
/**
|
|
|
|
* @brief hdr - header of package
|
|
|
|
*/
|
|
|
|
Header hdr;
|
|
|
|
/**
|
|
|
|
* @brief data - source data of package
|
|
|
|
*/
|
|
|
|
QByteArray data;
|
|
|
|
|
|
|
|
Package();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief isValid
|
|
|
|
* @return true if package is valid
|
|
|
|
*/
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief parse
|
|
|
|
* @return Qmap of package (default key if "value")
|
|
|
|
*/
|
|
|
|
QVariantMap parse() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief toBytes
|
|
|
|
* @return bytes array of packag
|
|
|
|
*/
|
|
|
|
QByteArray toBytes() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief reset - reset all data and set for package invalid status
|
|
|
|
*/
|
|
|
|
void reset();
|
2019-02-12 13:12:11 +03:00
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
};
|
2019-02-12 13:12:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CLIENTPROTOCOL_H
|