代码拉取完成,页面将自动刷新
同步操作将从 Process/protocol_extracter 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <iomanip>
#include <iostream>
#include <numeric>
#include "nprotocol_extracter.h"
using namespace std;
class ProtocolUser : public NProtocolBase
{
public:
ProtocolUser();
protected:
bool Verify(const uint8_t *data) override;
void HandleData(const uint8_t *data) override;
};
ProtocolUser::ProtocolUser() : NProtocolBase(true, 5, {0x77}) {}
bool ProtocolUser::Verify(const uint8_t *data)
{
uint8_t sum = 0;
return data[length() - 1] ==
accumulate(data, data + length() - sizeof(sum), sum);
}
void ProtocolUser::HandleData(const uint8_t *data)
{
cout << "Protocol data extract successfully: \n";
for (int i = 0; i < length(); ++i)
{
cout << hex << setfill('0') << setw(2) << (int)data[i] << " ";
}
cout << endl;
}
int main(int, char **)
{
NProtocolExtracter extracter;
/**
* Because NProtocolExtracter will take owner of protocol, so, instantiating
* objects in the heap.
* */
ProtocolUser protocol;
extracter.AddProtocol(&protocol);
// Error data does not affect subsequent parsing
extracter.AddNewData("try error data");
/**
* In practical application, the data received at one time may not be
* complete, but there is no need to worry. Extraction handle will
* automatically splice the data
* */
uint8_t data1[] = {0x77, 0x77, 0x00};
uint8_t data2[] = {0x00, 0x01, 0x78, 0x77};
uint8_t data3[] = {0x00, 0x00, 0x02, 0x79};
cout << "Step 1\n";
extracter.AddNewData(data1, sizeof(data1));
cout << "Step 2\n";
extracter.AddNewData(data2, sizeof(data2));
cout << "Step 3\n";
extracter.AddNewData(data3, sizeof(data3));
cout << "Step 4\n";
return EXIT_SUCCESS;
}
/** output
* Step 1
* Step 2
* Protocol data extract successfully:
* 77 00 01 00 78
* Step 3
* Protocol data extract successfully:
* 77 00 02 00 79
* Step 4
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。