2025-05-08 08:21:42 +08:00
|
|
|
#include <InfoDirFile.hpp>
|
2025-05-06 23:21:10 +08:00
|
|
|
#include <iostream>
|
2025-05-11 21:27:59 +08:00
|
|
|
#include <Communicate.h>
|
2025-05-06 23:21:10 +08:00
|
|
|
|
2025-05-08 12:46:49 +08:00
|
|
|
void test1()
|
2025-05-06 23:21:10 +08:00
|
|
|
{
|
|
|
|
DirFileInfo info;
|
|
|
|
DirFileInfo info2;
|
|
|
|
info.fullPath = "C:\\Users\\Administrator\\Desktop\\test.txt";
|
|
|
|
|
|
|
|
info.name.resize(1024);
|
|
|
|
info.name[0] = 'a';
|
|
|
|
info.name[10] = 'd';
|
|
|
|
info.name[11] = '\0';
|
|
|
|
info.name[12] = 'c';
|
|
|
|
|
|
|
|
info.lastModifyTime = 1610995200;
|
|
|
|
info.size = 1024;
|
|
|
|
info.permission = 0777;
|
|
|
|
info.type = FileType::File;
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
{
|
|
|
|
cereal::BinaryOutputArchive archive(ss);
|
|
|
|
archive(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ret = ss.str();
|
|
|
|
std::cout << "Serialized size: " << ret.size() << " bytes\n";
|
|
|
|
|
|
|
|
{
|
|
|
|
std::stringstream inputSs(ret);
|
|
|
|
cereal::BinaryInputArchive inputArchive(inputSs);
|
|
|
|
inputArchive(info2);
|
|
|
|
}
|
2025-05-08 12:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test2()
|
|
|
|
{
|
|
|
|
DirFileInfoVec v;
|
|
|
|
DirFileInfoVec v2;
|
|
|
|
DirFileInfo d1;
|
|
|
|
d1.fullPath = "Java";
|
|
|
|
DirFileInfo d2;
|
|
|
|
d2.fullPath = "CPP";
|
|
|
|
v.vec.push_back(d1);
|
|
|
|
v.vec.push_back(d2);
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
{
|
|
|
|
cereal::BinaryOutputArchive archive(ss);
|
|
|
|
archive(v);
|
|
|
|
}
|
2025-05-06 23:21:10 +08:00
|
|
|
|
2025-05-08 12:46:49 +08:00
|
|
|
std::string ret = ss.str();
|
|
|
|
std::cout << "Serialized size: " << ret.size() << " bytes\n";
|
|
|
|
|
|
|
|
{
|
|
|
|
std::stringstream inputSs(ret);
|
|
|
|
cereal::BinaryInputArchive inputArchive(inputSs);
|
|
|
|
inputArchive(v2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-11 21:27:59 +08:00
|
|
|
void test3()
|
|
|
|
{
|
|
|
|
auto* f = new FrameBuffer();
|
|
|
|
f->fid = "127.0.0.1:9898";
|
|
|
|
f->tid = "127.0.0.1:9899";
|
|
|
|
f->dataType = FBT_CLI_BIN_FILEDATA;
|
|
|
|
|
|
|
|
char* d = nullptr;
|
|
|
|
int len = 0;
|
|
|
|
if (Communicate::PackBuffer(f, &d, len)) {
|
|
|
|
MutBuffer buffer;
|
|
|
|
buffer.Push(d, len);
|
|
|
|
auto c = Communicate::ParseBuffer(buffer);
|
|
|
|
if (c != nullptr) {
|
|
|
|
std::cout << "Parse success\n";
|
|
|
|
} else {
|
|
|
|
std::cout << "Parse failed\n";
|
|
|
|
}
|
|
|
|
delete[] d;
|
|
|
|
}
|
2025-05-12 12:53:16 +08:00
|
|
|
delete f;
|
2025-05-11 21:27:59 +08:00
|
|
|
}
|
|
|
|
|
2025-05-08 12:46:49 +08:00
|
|
|
int main()
|
|
|
|
{
|
2025-05-11 21:27:59 +08:00
|
|
|
test3();
|
2025-05-06 23:21:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|