1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/examples/qqtnetworkexample/qqtlanprotocol.h

65 lines
1.3 KiB
C
Raw Normal View History

2017-10-17 22:00:45 +08:00
#ifndef QQTLANPROTOCOL_H
#define QQTLANPROTOCOL_H
#include "qqtprotocol.h"
2018-04-18 20:34:40 +08:00
#include "qqtmessage.h"
2018-04-22 13:03:28 +08:00
#include "qqttcpserver.h"
2017-10-17 22:00:45 +08:00
2018-04-18 20:34:40 +08:00
class QQtLanMessage : public QQtMessage
{
Q_OBJECT
public:
explicit QQtLanMessage ( QObject* parent = 0 ) {
mSize = 0x03;//3个字节 定长
}
~QQtLanMessage() {
}
quint8& size() { return mSize; }
const quint8& size() const { return mSize; }
private:
//一条报文格式
//|quint8 size| quint8 cmd|quint8 data|
quint8 mSize;
quint8 mCmd;
quint8 mData;
// QQtMessage interface
public:
virtual void parser ( const QByteArray& l ) override {
QByteArray _l = l;
_l >> mSize;
_l >> mCmd;
_l >> mData;
}
virtual void packer ( QByteArray& l ) const override {
l << mSize;
l << mCmd;
l << mData;
}
};
2017-10-29 21:38:30 +08:00
class QQTLanProtocol : public QQtProtocol
2017-10-17 22:00:45 +08:00
{
2018-04-18 20:34:40 +08:00
Q_OBJECT
2017-10-17 22:00:45 +08:00
public:
2018-04-18 20:34:40 +08:00
explicit QQTLanProtocol ( QObject* parent = 0 );
//void recvUserACommand ( const& data );
2017-10-17 22:00:45 +08:00
2017-10-29 21:38:30 +08:00
// QQtProtocol interface
2017-10-17 22:00:45 +08:00
public:
quint16 minlength() override;
quint16 maxlength() override;
2018-04-18 20:34:40 +08:00
quint16 splitter ( const QByteArray& s ) override;
bool dispatcher ( const QByteArray& m ) override;
2017-10-17 22:00:45 +08:00
};
2018-04-22 13:03:28 +08:00
QQtTcpServer* QQTSingleServer ( QObject* parent );
2018-04-18 20:34:40 +08:00
//new
QQTLanProtocol* QQtLanServer ( QObject* parent = 0 );
2017-10-17 22:00:45 +08:00
#endif // QQTLANPROTOCOL_H