mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 08:15:34 +00:00
perf[protocol]: 使用模板生成协议
This commit is contained in:
1 parent
eb1f4f9935
commit
07ff2dc004
12 files changed
+64
-58
No files matched your search
@@ -6,8 +6,8 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
set(PROJECT_MAIN cpp)
|
set(PROJECT_MAIN cpp)
|
||||||
|
|
||||||
# main
|
# main
|
||||||
file(GLOB_RECURSE MAIN_SOURCES zfoocpp/*.c**)
|
file(GLOB_RECURSE MAIN_SOURCES cppProtocol/*.c**)
|
||||||
file(GLOB_RECURSE MAIN_HEADERS zfoocpp/*.h**)
|
file(GLOB_RECURSE MAIN_HEADERS cppProtocol/*.h**)
|
||||||
|
|
||||||
# test
|
# test
|
||||||
file(GLOB_RECURSE TEST_SOURCES test/*.c**)
|
file(GLOB_RECURSE TEST_SOURCES test/*.c**)
|
||||||
|
|||||||
+30
-30
@@ -417,7 +417,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeBool(value);
|
writeBool(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -439,7 +439,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeBool(value);
|
writeBool(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -460,7 +460,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeBool(value);
|
writeBool(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,7 +482,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeByte(value);
|
writeByte(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -504,7 +504,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeByte(value);
|
writeByte(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeByte(value);
|
writeByte(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,7 +547,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeShort(value);
|
writeShort(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -568,7 +568,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeShort(value);
|
writeShort(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -589,7 +589,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeShort(value);
|
writeShort(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -611,7 +611,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeInt(value);
|
writeInt(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -632,7 +632,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeInt(value);
|
writeInt(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -653,7 +653,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeInt(value);
|
writeInt(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,7 +675,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeLong(value);
|
writeLong(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -696,7 +696,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeLong(value);
|
writeLong(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -717,7 +717,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeLong(value);
|
writeLong(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -739,7 +739,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeFloat(value);
|
writeFloat(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -760,7 +760,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeFloat(value);
|
writeFloat(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -781,7 +781,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeFloat(value);
|
writeFloat(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -803,7 +803,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeDouble(value);
|
writeDouble(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -824,7 +824,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeDouble(value);
|
writeDouble(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -845,7 +845,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeDouble(value);
|
writeDouble(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -867,7 +867,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeChar(value);
|
writeChar(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -888,7 +888,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeChar(value);
|
writeChar(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -909,7 +909,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeChar(value);
|
writeChar(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -931,7 +931,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writeString(value);
|
writeString(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -952,7 +952,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writeString(value);
|
writeString(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -973,7 +973,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writeString(value);
|
writeString(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1282,7 +1282,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = array.size();
|
int32_t length = array.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : array) {
|
for (auto value : array) {
|
||||||
writePacket((IPacket *) &value, protocolId);
|
writePacket((IPacket *) &value, protocolId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1307,7 +1307,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = list.size();
|
int32_t length = list.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : list) {
|
for (auto value : list) {
|
||||||
writePacket((IPacket *) &value, protocolId);
|
writePacket((IPacket *) &value, protocolId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1332,7 +1332,7 @@ namespace zfoo {
|
|||||||
}
|
}
|
||||||
int32_t length = set.size();
|
int32_t length = set.size();
|
||||||
writeInt(length);
|
writeInt(length);
|
||||||
for (const auto &value : set) {
|
for (auto value : set) {
|
||||||
writePacket((IPacket *) &value, protocolId);
|
writePacket((IPacket *) &value, protocolId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
#ifndef ZFOO_COMPLEXOBJECT_H
|
#ifndef ZFOO_COMPLEXOBJECT_H
|
||||||
#define ZFOO_COMPLEXOBJECT_H
|
#define ZFOO_COMPLEXOBJECT_H
|
||||||
|
|
||||||
#include "zfoocpp/ByteBuffer.h"
|
#include "cppProtocol/ByteBuffer.h"
|
||||||
#include "zfoocpp/ObjectA.h"
|
#include "cppProtocol/Packet/ObjectA.h"
|
||||||
#include "zfoocpp/ObjectB.h"
|
#include "cppProtocol/Packet/ObjectB.h"
|
||||||
|
|
||||||
namespace zfoo {
|
namespace zfoo {
|
||||||
|
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
#ifndef ZFOO_NORMALOBJECT_H
|
#ifndef ZFOO_NORMALOBJECT_H
|
||||||
#define ZFOO_NORMALOBJECT_H
|
#define ZFOO_NORMALOBJECT_H
|
||||||
|
|
||||||
#include "zfoocpp/ByteBuffer.h"
|
#include "cppProtocol/ByteBuffer.h"
|
||||||
#include "zfoocpp/ObjectA.h"
|
#include "cppProtocol/Packet/ObjectA.h"
|
||||||
#include "zfoocpp/ObjectB.h"
|
#include "cppProtocol/Packet/ObjectB.h"
|
||||||
|
|
||||||
namespace zfoo {
|
namespace zfoo {
|
||||||
|
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
#ifndef ZFOO_OBJECTA_H
|
#ifndef ZFOO_OBJECTA_H
|
||||||
#define ZFOO_OBJECTA_H
|
#define ZFOO_OBJECTA_H
|
||||||
|
|
||||||
#include "zfoocpp/ByteBuffer.h"
|
#include "cppProtocol/ByteBuffer.h"
|
||||||
#include "zfoocpp/ObjectB.h"
|
#include "cppProtocol/Packet/ObjectB.h"
|
||||||
|
|
||||||
namespace zfoo {
|
namespace zfoo {
|
||||||
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ZFOO_OBJECTB_H
|
#ifndef ZFOO_OBJECTB_H
|
||||||
#define ZFOO_OBJECTB_H
|
#define ZFOO_OBJECTB_H
|
||||||
|
|
||||||
#include "zfoocpp/ByteBuffer.h"
|
#include "cppProtocol/ByteBuffer.h"
|
||||||
|
|
||||||
namespace zfoo {
|
namespace zfoo {
|
||||||
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ZFOO_SIMPLEOBJECT_H
|
#ifndef ZFOO_SIMPLEOBJECT_H
|
||||||
#define ZFOO_SIMPLEOBJECT_H
|
#define ZFOO_SIMPLEOBJECT_H
|
||||||
|
|
||||||
#include "zfoocpp/ByteBuffer.h"
|
#include "cppProtocol/ByteBuffer.h"
|
||||||
|
|
||||||
namespace zfoo {
|
namespace zfoo {
|
||||||
|
|
||||||
+5
-5
@@ -2,11 +2,11 @@
|
|||||||
#define ZFOO_PROTOCOLMANAGER_H
|
#define ZFOO_PROTOCOLMANAGER_H
|
||||||
|
|
||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
#include "zfoocpp/ComplexObject.h"
|
#include "cppProtocol/packet/ComplexObject.h"
|
||||||
#include "zfoocpp/NormalObject.h"
|
#include "cppProtocol/packet/NormalObject.h"
|
||||||
#include "zfoocpp/ObjectA.h"
|
#include "cppProtocol/packet/ObjectA.h"
|
||||||
#include "zfoocpp/ObjectB.h"
|
#include "cppProtocol/packet/ObjectB.h"
|
||||||
#include "zfoocpp/SimpleObject.h"
|
#include "cppProtocol/packet/SimpleObject.h"
|
||||||
|
|
||||||
namespace zfoo {
|
namespace zfoo {
|
||||||
|
|
||||||
@@ -8,11 +8,17 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
list_test::list_all_test();
|
try {
|
||||||
byte_buffer_test::byte_buffer_all_test();
|
list_test::list_all_test();
|
||||||
serialization_test::protocol_all_test();
|
byte_buffer_test::byte_buffer_all_test();
|
||||||
|
serialization_test::protocol_all_test();
|
||||||
|
|
||||||
speed_test::parseObject();
|
speed_test::parseObject();
|
||||||
speed_test::singleThreadBenchmarks();
|
speed_test::singleThreadBenchmarks();
|
||||||
|
} catch (string &e) {
|
||||||
|
cout << e << endl;
|
||||||
|
} catch (...) {
|
||||||
|
cout << "unknown" << endl;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "zfoocpp/ByteBuffer.h"
|
#include "cppProtocol//ByteBuffer.h"
|
||||||
|
|
||||||
namespace byte_buffer_test {
|
namespace byte_buffer_test {
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "zfoocpp/ProtocolManager.h"
|
#include "cppProtocol/ProtocolManager.h"
|
||||||
|
|
||||||
|
|
||||||
namespace serialization_test {
|
namespace serialization_test {
|
||||||
@@ -75,7 +75,7 @@ namespace serialization_test {
|
|||||||
|
|
||||||
void complexObjectTest() {
|
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];
|
unsigned char carray[10000];
|
||||||
int length = 0;
|
int length = 0;
|
||||||
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "zfoocpp/ProtocolManager.h"
|
#include "cppProtocol/ProtocolManager.h"
|
||||||
|
|
||||||
namespace speed_test {
|
namespace speed_test {
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ namespace speed_test {
|
|||||||
|
|
||||||
void parseObject() {
|
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];
|
unsigned char carray[10000];
|
||||||
int length = 0;
|
int length = 0;
|
||||||
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
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