mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-18 23:29:12 +00:00
perf[protocol]: 使用模板生成协议
This commit is contained in:
@@ -6,8 +6,8 @@ set(CMAKE_CXX_STANDARD 20)
|
||||
set(PROJECT_MAIN cpp)
|
||||
|
||||
# main
|
||||
file(GLOB_RECURSE MAIN_SOURCES zfoocpp/*.c**)
|
||||
file(GLOB_RECURSE MAIN_HEADERS zfoocpp/*.h**)
|
||||
file(GLOB_RECURSE MAIN_SOURCES cppProtocol/*.c**)
|
||||
file(GLOB_RECURSE MAIN_HEADERS cppProtocol/*.h**)
|
||||
|
||||
# test
|
||||
file(GLOB_RECURSE TEST_SOURCES test/*.c**)
|
||||
|
||||
+30
-30
@@ -417,7 +417,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeBool(value);
|
||||
}
|
||||
}
|
||||
@@ -439,7 +439,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeBool(value);
|
||||
}
|
||||
}
|
||||
@@ -460,7 +460,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeBool(value);
|
||||
}
|
||||
}
|
||||
@@ -482,7 +482,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeByte(value);
|
||||
}
|
||||
}
|
||||
@@ -504,7 +504,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeByte(value);
|
||||
}
|
||||
}
|
||||
@@ -525,7 +525,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeByte(value);
|
||||
}
|
||||
}
|
||||
@@ -547,7 +547,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeShort(value);
|
||||
}
|
||||
}
|
||||
@@ -568,7 +568,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeShort(value);
|
||||
}
|
||||
}
|
||||
@@ -589,7 +589,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeShort(value);
|
||||
}
|
||||
}
|
||||
@@ -611,7 +611,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeInt(value);
|
||||
}
|
||||
}
|
||||
@@ -632,7 +632,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeInt(value);
|
||||
}
|
||||
}
|
||||
@@ -653,7 +653,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeInt(value);
|
||||
}
|
||||
}
|
||||
@@ -675,7 +675,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeLong(value);
|
||||
}
|
||||
}
|
||||
@@ -696,7 +696,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeLong(value);
|
||||
}
|
||||
}
|
||||
@@ -717,7 +717,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeLong(value);
|
||||
}
|
||||
}
|
||||
@@ -739,7 +739,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeFloat(value);
|
||||
}
|
||||
}
|
||||
@@ -760,7 +760,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeFloat(value);
|
||||
}
|
||||
}
|
||||
@@ -781,7 +781,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeFloat(value);
|
||||
}
|
||||
}
|
||||
@@ -803,7 +803,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeDouble(value);
|
||||
}
|
||||
}
|
||||
@@ -824,7 +824,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeDouble(value);
|
||||
}
|
||||
}
|
||||
@@ -845,7 +845,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeDouble(value);
|
||||
}
|
||||
}
|
||||
@@ -867,7 +867,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeChar(value);
|
||||
}
|
||||
}
|
||||
@@ -888,7 +888,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeChar(value);
|
||||
}
|
||||
}
|
||||
@@ -909,7 +909,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeChar(value);
|
||||
}
|
||||
}
|
||||
@@ -931,7 +931,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writeString(value);
|
||||
}
|
||||
}
|
||||
@@ -952,7 +952,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writeString(value);
|
||||
}
|
||||
}
|
||||
@@ -973,7 +973,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writeString(value);
|
||||
}
|
||||
}
|
||||
@@ -1282,7 +1282,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = array.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : array) {
|
||||
for (auto value : array) {
|
||||
writePacket((IPacket *) &value, protocolId);
|
||||
}
|
||||
}
|
||||
@@ -1307,7 +1307,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = list.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : list) {
|
||||
for (auto value : list) {
|
||||
writePacket((IPacket *) &value, protocolId);
|
||||
}
|
||||
}
|
||||
@@ -1332,7 +1332,7 @@ namespace zfoo {
|
||||
}
|
||||
int32_t length = set.size();
|
||||
writeInt(length);
|
||||
for (const auto &value : set) {
|
||||
for (auto value : set) {
|
||||
writePacket((IPacket *) &value, protocolId);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#ifndef ZFOO_COMPLEXOBJECT_H
|
||||
#define ZFOO_COMPLEXOBJECT_H
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
#include "zfoocpp/ObjectA.h"
|
||||
#include "zfoocpp/ObjectB.h"
|
||||
#include "cppProtocol/ByteBuffer.h"
|
||||
#include "cppProtocol/Packet/ObjectA.h"
|
||||
#include "cppProtocol/Packet/ObjectB.h"
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#ifndef ZFOO_NORMALOBJECT_H
|
||||
#define ZFOO_NORMALOBJECT_H
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
#include "zfoocpp/ObjectA.h"
|
||||
#include "zfoocpp/ObjectB.h"
|
||||
#include "cppProtocol/ByteBuffer.h"
|
||||
#include "cppProtocol/Packet/ObjectA.h"
|
||||
#include "cppProtocol/Packet/ObjectB.h"
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef ZFOO_OBJECTA_H
|
||||
#define ZFOO_OBJECTA_H
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
#include "zfoocpp/ObjectB.h"
|
||||
#include "cppProtocol/ByteBuffer.h"
|
||||
#include "cppProtocol/Packet/ObjectB.h"
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef ZFOO_OBJECTB_H
|
||||
#define ZFOO_OBJECTB_H
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
#include "cppProtocol/ByteBuffer.h"
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef ZFOO_SIMPLEOBJECT_H
|
||||
#define ZFOO_SIMPLEOBJECT_H
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
#include "cppProtocol/ByteBuffer.h"
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
+5
-5
@@ -2,11 +2,11 @@
|
||||
#define ZFOO_PROTOCOLMANAGER_H
|
||||
|
||||
#include "ByteBuffer.h"
|
||||
#include "zfoocpp/ComplexObject.h"
|
||||
#include "zfoocpp/NormalObject.h"
|
||||
#include "zfoocpp/ObjectA.h"
|
||||
#include "zfoocpp/ObjectB.h"
|
||||
#include "zfoocpp/SimpleObject.h"
|
||||
#include "cppProtocol/packet/ComplexObject.h"
|
||||
#include "cppProtocol/packet/NormalObject.h"
|
||||
#include "cppProtocol/packet/ObjectA.h"
|
||||
#include "cppProtocol/packet/ObjectB.h"
|
||||
#include "cppProtocol/packet/SimpleObject.h"
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
@@ -8,11 +8,17 @@ using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
list_test::list_all_test();
|
||||
byte_buffer_test::byte_buffer_all_test();
|
||||
serialization_test::protocol_all_test();
|
||||
try {
|
||||
list_test::list_all_test();
|
||||
byte_buffer_test::byte_buffer_all_test();
|
||||
serialization_test::protocol_all_test();
|
||||
|
||||
speed_test::parseObject();
|
||||
speed_test::singleThreadBenchmarks();
|
||||
speed_test::parseObject();
|
||||
speed_test::singleThreadBenchmarks();
|
||||
} catch (string &e) {
|
||||
cout << e << endl;
|
||||
} catch (...) {
|
||||
cout << "unknown" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
#include "cppProtocol//ByteBuffer.h"
|
||||
|
||||
namespace byte_buffer_test {
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "zfoocpp/ProtocolManager.h"
|
||||
#include "cppProtocol/ProtocolManager.h"
|
||||
|
||||
|
||||
namespace serialization_test {
|
||||
@@ -75,7 +75,7 @@ namespace serialization_test {
|
||||
|
||||
void complexObjectTest() {
|
||||
// 读取二进制文件
|
||||
ifstream file("C:\\zfoo\\protocol\\src\\test\\resources\\ComplexObject.bytes", ios::out | ios::binary);
|
||||
ifstream file("../resources/ComplexObject.bytes", ios::out | ios::binary);
|
||||
unsigned char carray[10000];
|
||||
int length = 0;
|
||||
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "zfoocpp/ProtocolManager.h"
|
||||
#include "cppProtocol/ProtocolManager.h"
|
||||
|
||||
namespace speed_test {
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace speed_test {
|
||||
|
||||
void parseObject() {
|
||||
// 读取二进制文件
|
||||
ifstream file("C:\\zfoo\\protocol\\src\\test\\resources\\ComplexObject.bytes", ios::out | ios::binary);
|
||||
ifstream file("../resources/ComplexObject.bytes", ios::out | ios::binary);
|
||||
unsigned char carray[10000];
|
||||
int length = 0;
|
||||
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
||||
@@ -107,4 +107,4 @@ namespace speed_test {
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user