test[cpp]: compatible field of inside protocol class

This commit is contained in:
godotg
2023-10-15 18:00:42 +08:00
parent 98504cb124
commit aa8e269a16
15 changed files with 2190 additions and 4628 deletions
+2 -2
View File
@@ -6,8 +6,8 @@ set(CMAKE_CXX_STANDARD 20)
set(PROJECT_MAIN cpp)
# main
file(GLOB_RECURSE MAIN_SOURCES cppProtocol/*.c**)
file(GLOB_RECURSE MAIN_HEADERS cppProtocol/*.h**)
file(GLOB_RECURSE MAIN_SOURCES zfoocpp/*.c**)
file(GLOB_RECURSE MAIN_HEADERS zfoocpp/*.h**)
# test
file(GLOB_RECURSE TEST_SOURCES test/*.c**)
+6 -13
View File
@@ -6,19 +6,12 @@
using namespace zfoo;
using namespace std;
int main() {
try {
list_test::list_all_test();
byte_buffer_test::byte_buffer_all_test();
serialization_test::protocol_all_test();
list_test::list_all_test();
byte_buffer_test::byte_buffer_all_test();
serialization_test::protocol_all_test();
speed_test::parseObject();
speed_test::singleThreadBenchmarks();
} catch (string &e) {
cout << e << endl;
} catch (...) {
cout << "unknown" << endl;
}
speed_test::parseObject();
speed_test::singleThreadBenchmarks();
return 0;
}
}
@@ -3,7 +3,7 @@
#include <string>
#include "cppProtocol/ByteBuffer.h"
#include "zfoocpp/ByteBuffer.h"
namespace byte_buffer_test {
+8 -14
View File
@@ -105,20 +105,14 @@ namespace list_test {
void list_all_test() {
using namespace std;
try {
listCopyTest();
cout << "----------------------------------------------------------------------" << endl;
listOperatorTest();
cout << "----------------------------------------------------------------------" << endl;
listIntTest();
cout << "----------------------------------------------------------------------" << endl;
listRemoveTest();
cout << "----------------------------------------------------------------------" << endl;
} catch (string &e) {
cout << e << endl;
} catch (...) {
cout << "unknown" << endl;
}
listCopyTest();
cout << "----------------------------------------------------------------------" << endl;
listOperatorTest();
cout << "----------------------------------------------------------------------" << endl;
listIntTest();
cout << "----------------------------------------------------------------------" << endl;
listRemoveTest();
cout << "----------------------------------------------------------------------" << endl;
}
}
#endif
+37 -23
View File
@@ -6,7 +6,7 @@
#include <string>
#include <map>
#include "cppProtocol/ProtocolManager.h"
#include "zfoocpp/ProtocolManager.h"
namespace serialization_test {
@@ -21,7 +21,7 @@ namespace serialization_test {
write(buffer, &objectB);
ObjectB obj = *((ObjectB *) read(buffer));
cout << "Hello, World!" << endl;
cout << "objectBTest" << endl;
}
void objectATest() {
@@ -43,7 +43,7 @@ namespace serialization_test {
write(buffer, &objectA);
ObjectA obj = *((ObjectA *) read(buffer));
cout << "Hello, World!" << endl;
cout << "objectATest" << endl;
}
@@ -69,13 +69,13 @@ namespace serialization_test {
write(buffer, &normalObject);
NormalObject *p = (NormalObject *) read(buffer);
cout << "Hello, World!" << endl;
cout << "normalObjectTest" << endl;
}
void complexObjectTest() {
// 读取二进制文件
ifstream file("../../resources/ComplexObject.bytes", ios::out | ios::binary);
ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\complexObject.bytes", ios::out | ios::binary);
unsigned char carray[10000];
int length = 0;
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
@@ -90,30 +90,44 @@ namespace serialization_test {
ByteBuffer newBuffer;
write(newBuffer, &obj);
obj = *((ComplexObject *) read(newBuffer));
cout << "Hello, World!" << endl;
cout << "complexObjectTest" << endl;
}
for (int i = 0; i < 3000; ++i) {
auto a = buffer.getByte(i);
auto b = newBuffer.getByte(i);
if (a != b) {
cout << i << endl;
}
void compatibleTest() {
// 读取二进制文件
// ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-no-compatible.bytes", ios::out | ios::binary);
// ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-compatible.bytes", ios::out | ios::binary);
// ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-inner-compatible.bytes", ios::out | ios::binary);
// ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-compatible.bytes", ios::out | ios::binary);
ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-inner-compatible.bytes", ios::out | ios::binary);
unsigned char carray[10000];
int length = 0;
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
length++;
}
file.close();
ByteBuffer buffer;
buffer.writeBytes(reinterpret_cast<const int8_t *>(carray), length);
NormalObject obj = *((NormalObject *) read(buffer));
ByteBuffer newBuffer;
write(newBuffer, &obj);
obj = *((NormalObject *) read(newBuffer));
cout << "source size " << length << endl;
cout << "target size " << newBuffer.writerIndex() << endl;
cout << "compatible test" << endl;
}
void protocol_all_test() {
try {
initProtocol();
objectBTest();
objectATest();
normalObjectTest();
complexObjectTest();
} catch (string &e) {
cout << e << endl;
} catch (...) {
cout << "unknown" << endl;
}
initProtocol();
objectBTest();
objectATest();
normalObjectTest();
complexObjectTest();
compatibleTest();
}
}
+2 -2
View File
@@ -5,7 +5,7 @@
#include <fstream>
#include <string>
#include "cppProtocol/ProtocolManager.h"
#include "zfoocpp//ProtocolManager.h"
namespace speed_test {
@@ -20,7 +20,7 @@ namespace speed_test {
void parseObject() {
// 读取二进制文件
ifstream file("../../resources/ComplexObject.bytes", ios::out | ios::binary);
ifstream file("D:\\github\\zfoo\\protocol\\src\\test\\resources\\complexObject.bytes", ios::out | ios::binary);
unsigned char carray[10000];
int length = 0;
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
@@ -77,6 +77,29 @@ namespace zfoo {
ByteBuffer &operator=(const ByteBuffer &buffer) = delete;
void adjustPadding(int32_t predictionLength, int32_t beforeWriteIndex) {
int32_t currentWriteIndex = writerIndex();
int32_t predictionCount = writeIntCount(predictionLength);
int32_t length = currentWriteIndex - beforeWriteIndex - predictionCount;
int32_t lengthCount = writeIntCount(length);
int32_t padding = lengthCount - predictionCount;
if (padding == 0) {
writerIndex(beforeWriteIndex);
writeInt(length);
writerIndex(currentWriteIndex);
} else {
int8_t *targetPtr = (int8_t *) calloc(length, sizeof(int8_t));
memcpy(targetPtr, &m_buffer[currentWriteIndex - length], length);
writerIndex(beforeWriteIndex);
writeInt(length);
writeBytes(targetPtr, length);
free(targetPtr);
}
}
bool compatibleRead(int32_t beforeReadIndex, int32_t length) {
return length != -1 && readerIndex() < length + beforeReadIndex;
}
void clear() {
m_writerIndex = 0;
@@ -228,6 +251,23 @@ namespace zfoo {
writerIndex(writeIndex);
}
inline int32_t writeIntCount(const int32_t &intValue) {
uint32_t value = (uint32_t) ((intValue << 1) ^ (intValue >> 31));
if (value >> 7 == 0) {
return 1;
}
if (value >> 14 == 0) {
return 2;
}
if (value >> 21 == 0) {
return 3;
}
if (value >> 28 == 0) {
return 4;
}
return 5;
}
inline int32_t readInt() {
int32_t readIndex = m_readerIndex;
@@ -384,23 +424,6 @@ namespace zfoo {
return str;
}
// 很多脚本语言没有char,所以这里使用string代替
inline void writeChar(const char &value) {
string str;
str.push_back(value);
writeString(str);
}
inline char readChar() {
return readString()[0];
}
inline bool writePacketFlag(const IProtocol *packet) {
bool flag = packet == nullptr;
writeBool(!flag);
return flag;
}
inline void writePacket(IProtocol *packet, const int16_t &protocolId) {
IProtocolRegistration *protocolRegistration = getProtocol(protocolId);
protocolRegistration->write(*this, packet);
@@ -863,70 +886,6 @@ namespace zfoo {
return set;
}
//---------------------------------char--------------------------------------
inline void writeCharArray(const vector<char> &array) {
if (array.empty()) {
writeByte(0);
return;
}
int32_t length = array.size();
writeInt(length);
for (auto value : array) {
writeChar(value);
}
}
inline vector<char> readCharArray() {
int32_t length = readInt();
vector<char> array;
for (auto i = 0; i < length; i++) {
array.emplace_back(readChar());
}
return array;
}
inline void writeCharList(const list<char> &list) {
if (list.empty()) {
writeByte(0);
return;
}
int32_t length = list.size();
writeInt(length);
for (auto value : list) {
writeChar(value);
}
}
inline list<char> readCharList() {
int32_t length = readInt();
list<char> list;
for (auto i = 0; i < length; i++) {
list.emplace_back(readChar());
}
return list;
}
inline void writeCharSet(const set<char> &set) {
if (set.empty()) {
writeByte(0);
return;
}
int32_t length = set.size();
writeInt(length);
for (auto value : set) {
writeChar(value);
}
}
inline set<char> readCharSet() {
int32_t length = readInt();
set<char> set;
for (auto i = 0; i < length; i++) {
set.emplace(readChar());
}
return set;
}
//---------------------------------string--------------------------------------
inline void writeStringArray(const vector<string> &array) {
if (array.empty()) {
@@ -2,13 +2,13 @@
#define ZFOO_PROTOCOLMANAGER_H
#include "ByteBuffer.h"
#include "cppProtocol/packet/EmptyObject.h"
#include "cppProtocol/packet/VeryBigObject.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"
#include "zfoocpp/packet/EmptyObject.h"
#include "zfoocpp/packet/VeryBigObject.h"
#include "zfoocpp/packet/ComplexObject.h"
#include "zfoocpp/packet/NormalObject.h"
#include "zfoocpp/packet/ObjectA.h"
#include "zfoocpp/packet/ObjectB.h"
#include "zfoocpp/packet/SimpleObject.h"
namespace zfoo {
@@ -1,9 +1,9 @@
#ifndef ZFOO_COMPLEXOBJECT_H
#define ZFOO_COMPLEXOBJECT_H
#include "cppProtocol/ByteBuffer.h"
#include "cppProtocol/Packet/ObjectA.h"
#include "cppProtocol/Packet/ObjectB.h"
#include "zfoocpp/ByteBuffer.h"
#include "zfoocpp/Packet/ObjectA.h"
#include "zfoocpp/Packet/ObjectB.h"
namespace zfoo {
@@ -41,10 +41,6 @@ namespace zfoo {
bool gg;
vector<bool> ggg;
vector<bool> gggg;
char h;
char hh;
vector<char> hhh;
vector<char> hhhh;
string jj;
vector<string> jjj;
ObjectA kk;
@@ -70,7 +66,7 @@ namespace zfoo {
~ComplexObject() override = default;
static ComplexObject valueOf(int8_t a, int8_t aa, vector<int8_t> aaa, vector<int8_t> aaaa, int16_t b, int16_t bb, vector<int16_t> bbb, vector<int16_t> bbbb, int32_t c, int32_t cc, vector<int32_t> ccc, vector<int32_t> cccc, int64_t d, int64_t dd, vector<int64_t> ddd, vector<int64_t> dddd, float e, float ee, vector<float> eee, vector<float> eeee, double f, double ff, vector<double> fff, vector<double> ffff, bool g, bool gg, vector<bool> ggg, vector<bool> gggg, char h, char hh, vector<char> hhh, vector<char> hhhh, string jj, vector<string> jjj, ObjectA kk, vector<ObjectA> kkk, list<int32_t> l, list<list<list<int32_t>>> ll, list<list<ObjectA>> lll, list<string> llll, list<map<int32_t, string>> lllll, map<int32_t, string> m, map<int32_t, ObjectA> mm, map<ObjectA, list<int32_t>> mmm, map<list<list<ObjectA>>, list<list<list<int32_t>>>> mmmm, map<list<map<int32_t, string>>, set<map<int32_t, string>>> mmmmm, set<int32_t> s, set<set<list<int32_t>>> ss, set<set<ObjectA>> sss, set<string> ssss, set<map<int32_t, string>> sssss, int32_t myCompatible, ObjectA myObject) {
static ComplexObject valueOf(int8_t a, int8_t aa, vector<int8_t> aaa, vector<int8_t> aaaa, int16_t b, int16_t bb, vector<int16_t> bbb, vector<int16_t> bbbb, int32_t c, int32_t cc, vector<int32_t> ccc, vector<int32_t> cccc, int64_t d, int64_t dd, vector<int64_t> ddd, vector<int64_t> dddd, float e, float ee, vector<float> eee, vector<float> eeee, double f, double ff, vector<double> fff, vector<double> ffff, bool g, bool gg, vector<bool> ggg, vector<bool> gggg, string jj, vector<string> jjj, ObjectA kk, vector<ObjectA> kkk, list<int32_t> l, list<list<list<int32_t>>> ll, list<list<ObjectA>> lll, list<string> llll, list<map<int32_t, string>> lllll, map<int32_t, string> m, map<int32_t, ObjectA> mm, map<ObjectA, list<int32_t>> mmm, map<list<list<ObjectA>>, list<list<list<int32_t>>>> mmmm, map<list<map<int32_t, string>>, set<map<int32_t, string>>> mmmmm, set<int32_t> s, set<set<list<int32_t>>> ss, set<set<ObjectA>> sss, set<string> ssss, set<map<int32_t, string>> sssss, int32_t myCompatible, ObjectA myObject) {
auto packet = ComplexObject();
packet.a = a;
packet.aa = aa;
@@ -100,10 +96,6 @@ namespace zfoo {
packet.gg = gg;
packet.ggg = ggg;
packet.gggg = gggg;
packet.h = h;
packet.hh = hh;
packet.hhh = hhh;
packet.hhhh = hhhh;
packet.jj = jj;
packet.jjj = jjj;
packet.kk = kk;
@@ -189,14 +181,6 @@ namespace zfoo {
if (_.ggg < ggg) { return false; }
if (gggg < _.gggg) { return true; }
if (_.gggg < gggg) { return false; }
if (h < _.h) { return true; }
if (_.h < h) { return false; }
if (hh < _.hh) { return true; }
if (_.hh < hh) { return false; }
if (hhh < _.hhh) { return true; }
if (_.hhh < hhh) { return false; }
if (hhhh < _.hhhh) { return true; }
if (_.hhhh < hhhh) { return false; }
if (jj < _.jj) { return true; }
if (_.jj < jj) { return false; }
if (jjj < _.jjj) { return true; }
@@ -251,10 +235,13 @@ namespace zfoo {
}
void write(ByteBuffer &buffer, IProtocol *packet) override {
if (buffer.writePacketFlag(packet)) {
if (packet == nullptr) {
buffer.writeInt(0);
return;
}
auto *message = (ComplexObject *) packet;
auto beforeWriteIndex = buffer.writerIndex();
buffer.writeInt(36962);
buffer.writeByte(message->a);
buffer.writeByte(message->aa);
buffer.writeByteArray(message->aaa);
@@ -283,10 +270,6 @@ namespace zfoo {
buffer.writeBool(message->gg);
buffer.writeBooleanArray(message->ggg);
buffer.writeBooleanArray(message->gggg);
buffer.writeChar(message->h);
buffer.writeChar(message->hh);
buffer.writeCharArray(message->hhh);
buffer.writeCharArray(message->hhhh);
buffer.writeString(message->jj);
buffer.writeStringArray(message->jjj);
buffer.writePacket(&message->kk, 102);
@@ -359,13 +342,16 @@ namespace zfoo {
}
buffer.writeInt(message->myCompatible);
buffer.writePacket(&message->myObject, 102);
buffer.adjustPadding(36962, beforeWriteIndex);
}
IProtocol *read(ByteBuffer &buffer) override {
auto *packet = new ComplexObject();
if (!buffer.readBool()) {
auto length = buffer.readInt();
if (length == 0) {
return packet;
}
auto beforeReadIndex = buffer.readerIndex();
int8_t result19 = buffer.readByte();
packet->a = result19;
int8_t result20 = buffer.readByte();
@@ -422,144 +408,141 @@ namespace zfoo {
packet->ggg = array45;
auto array46 = buffer.readBooleanArray();
packet->gggg = array46;
char result47 = buffer.readChar();
packet->h = result47;
char result48 = buffer.readChar();
packet->hh = result48;
auto array49 = buffer.readCharArray();
packet->hhh = array49;
auto array50 = buffer.readCharArray();
packet->hhhh = array50;
auto result51 = buffer.readString();
packet->jj = result51;
auto array52 = buffer.readStringArray();
packet->jjj = array52;
auto result53 = buffer.readPacket(102);
auto *result54 = (ObjectA *) result53.get();
packet->kk = *result54;
auto array55 = buffer.readPacketArray<ObjectA>(102);
packet->kkk = array55;
auto list56 = buffer.readIntList();
packet->l = list56;
int32_t size59 = buffer.readInt();
list<list<list<int32_t>>> result57;
for (int index58 = 0; index58 < size59; index58++) {
int32_t size62 = buffer.readInt();
list<list<int32_t>> result60;
for (int index61 = 0; index61 < size62; index61++) {
auto list63 = buffer.readIntList();
result60.emplace_back(list63);
auto result47 = buffer.readString();
packet->jj = result47;
auto array48 = buffer.readStringArray();
packet->jjj = array48;
auto result49 = buffer.readPacket(102);
auto *result50 = (ObjectA *) result49.get();
packet->kk = *result50;
auto array51 = buffer.readPacketArray<ObjectA>(102);
packet->kkk = array51;
auto list52 = buffer.readIntList();
packet->l = list52;
int32_t size55 = buffer.readInt();
list<list<list<int32_t>>> result53;
for (int index54 = 0; index54 < size55; index54++) {
int32_t size58 = buffer.readInt();
list<list<int32_t>> result56;
for (int index57 = 0; index57 < size58; index57++) {
auto list59 = buffer.readIntList();
result56.emplace_back(list59);
}
result57.emplace_back(result60);
result53.emplace_back(result56);
}
packet->ll = result57;
int32_t size66 = buffer.readInt();
list<list<ObjectA>> result64;
for (int index65 = 0; index65 < size66; index65++) {
auto list67 = buffer.readPacketList<ObjectA>(102);
result64.emplace_back(list67);
packet->ll = result53;
int32_t size62 = buffer.readInt();
list<list<ObjectA>> result60;
for (int index61 = 0; index61 < size62; index61++) {
auto list63 = buffer.readPacketList<ObjectA>(102);
result60.emplace_back(list63);
}
packet->lll = result64;
auto list68 = buffer.readStringList();
packet->llll = list68;
int32_t size71 = buffer.readInt();
list<map<int32_t, string>> result69;
for (int index70 = 0; index70 < size71; index70++) {
auto map72 = buffer.readIntStringMap();
result69.emplace_back(map72);
packet->lll = result60;
auto list64 = buffer.readStringList();
packet->llll = list64;
int32_t size67 = buffer.readInt();
list<map<int32_t, string>> result65;
for (int index66 = 0; index66 < size67; index66++) {
auto map68 = buffer.readIntStringMap();
result65.emplace_back(map68);
}
packet->lllll = result69;
auto map73 = buffer.readIntStringMap();
packet->m = map73;
auto map74 = buffer.readIntPacketMap<ObjectA>(102);
packet->mm = map74;
int32_t size76 = buffer.readInt();
map<ObjectA, list<int32_t>> result75;
for (auto index77 = 0; index77 < size76; index77++) {
auto result78 = buffer.readPacket(102);
auto *result79 = (ObjectA *) result78.get();
auto list80 = buffer.readIntList();
result75.insert(make_pair(*result79, list80));
packet->lllll = result65;
auto map69 = buffer.readIntStringMap();
packet->m = map69;
auto map70 = buffer.readIntPacketMap<ObjectA>(102);
packet->mm = map70;
int32_t size72 = buffer.readInt();
map<ObjectA, list<int32_t>> result71;
for (auto index73 = 0; index73 < size72; index73++) {
auto result74 = buffer.readPacket(102);
auto *result75 = (ObjectA *) result74.get();
auto list76 = buffer.readIntList();
result71.insert(make_pair(*result75, list76));
}
packet->mmm = result75;
int32_t size82 = buffer.readInt();
map<list<list<ObjectA>>, list<list<list<int32_t>>>> result81;
for (auto index83 = 0; index83 < size82; index83++) {
packet->mmm = result71;
int32_t size78 = buffer.readInt();
map<list<list<ObjectA>>, list<list<list<int32_t>>>> result77;
for (auto index79 = 0; index79 < size78; index79++) {
int32_t size82 = buffer.readInt();
list<list<ObjectA>> result80;
for (int index81 = 0; index81 < size82; index81++) {
auto list83 = buffer.readPacketList<ObjectA>(102);
result80.emplace_back(list83);
}
int32_t size86 = buffer.readInt();
list<list<ObjectA>> result84;
list<list<list<int32_t>>> result84;
for (int index85 = 0; index85 < size86; index85++) {
auto list87 = buffer.readPacketList<ObjectA>(102);
result84.emplace_back(list87);
}
int32_t size90 = buffer.readInt();
list<list<list<int32_t>>> result88;
for (int index89 = 0; index89 < size90; index89++) {
int32_t size93 = buffer.readInt();
list<list<int32_t>> result91;
for (int index92 = 0; index92 < size93; index92++) {
auto list94 = buffer.readIntList();
result91.emplace_back(list94);
int32_t size89 = buffer.readInt();
list<list<int32_t>> result87;
for (int index88 = 0; index88 < size89; index88++) {
auto list90 = buffer.readIntList();
result87.emplace_back(list90);
}
result88.emplace_back(result91);
result84.emplace_back(result87);
}
result81.insert(make_pair(result84, result88));
result77.insert(make_pair(result80, result84));
}
packet->mmmm = result81;
int32_t size96 = buffer.readInt();
map<list<map<int32_t, string>>, set<map<int32_t, string>>> result95;
for (auto index97 = 0; index97 < size96; index97++) {
packet->mmmm = result77;
int32_t size92 = buffer.readInt();
map<list<map<int32_t, string>>, set<map<int32_t, string>>> result91;
for (auto index93 = 0; index93 < size92; index93++) {
int32_t size96 = buffer.readInt();
list<map<int32_t, string>> result94;
for (int index95 = 0; index95 < size96; index95++) {
auto map97 = buffer.readIntStringMap();
result94.emplace_back(map97);
}
int32_t size100 = buffer.readInt();
list<map<int32_t, string>> result98;
set<map<int32_t, string>> result98;
for (int index99 = 0; index99 < size100; index99++) {
auto map101 = buffer.readIntStringMap();
result98.emplace_back(map101);
result98.emplace(map101);
}
int32_t size104 = buffer.readInt();
set<map<int32_t, string>> result102;
for (int index103 = 0; index103 < size104; index103++) {
auto map105 = buffer.readIntStringMap();
result102.emplace(map105);
result91.insert(make_pair(result94, result98));
}
packet->mmmmm = result91;
auto set102 = buffer.readIntSet();
packet->s = set102;
int32_t size105 = buffer.readInt();
set<set<list<int32_t>>> result103;
for (int index104 = 0; index104 < size105; index104++) {
int32_t size108 = buffer.readInt();
set<list<int32_t>> result106;
for (int index107 = 0; index107 < size108; index107++) {
auto list109 = buffer.readIntList();
result106.emplace(list109);
}
result95.insert(make_pair(result98, result102));
result103.emplace(result106);
}
packet->mmmmm = result95;
auto set106 = buffer.readIntSet();
packet->s = set106;
int32_t size109 = buffer.readInt();
set<set<list<int32_t>>> result107;
for (int index108 = 0; index108 < size109; index108++) {
int32_t size112 = buffer.readInt();
set<list<int32_t>> result110;
for (int index111 = 0; index111 < size112; index111++) {
auto list113 = buffer.readIntList();
result110.emplace(list113);
}
result107.emplace(result110);
packet->ss = result103;
int32_t size112 = buffer.readInt();
set<set<ObjectA>> result110;
for (int index111 = 0; index111 < size112; index111++) {
auto set113 = buffer.readPacketSet<ObjectA>(102);
result110.emplace(set113);
}
packet->ss = result107;
int32_t size116 = buffer.readInt();
set<set<ObjectA>> result114;
for (int index115 = 0; index115 < size116; index115++) {
auto set117 = buffer.readPacketSet<ObjectA>(102);
result114.emplace(set117);
packet->sss = result110;
auto set114 = buffer.readStringSet();
packet->ssss = set114;
int32_t size117 = buffer.readInt();
set<map<int32_t, string>> result115;
for (int index116 = 0; index116 < size117; index116++) {
auto map118 = buffer.readIntStringMap();
result115.emplace(map118);
}
packet->sss = result114;
auto set118 = buffer.readStringSet();
packet->ssss = set118;
int32_t size121 = buffer.readInt();
set<map<int32_t, string>> result119;
for (int index120 = 0; index120 < size121; index120++) {
auto map122 = buffer.readIntStringMap();
result119.emplace(map122);
packet->sssss = result115;
if (buffer.compatibleRead(beforeReadIndex, length)) {
int32_t result119 = buffer.readInt();
packet->myCompatible = result119;
}
if (buffer.compatibleRead(beforeReadIndex, length)) {
auto result120 = buffer.readPacket(102);
auto *result121 = (ObjectA *) result120.get();
packet->myObject = *result121;
}
if (length > 0) {
buffer.readerIndex(beforeReadIndex + length);
}
packet->sssss = result119;
if (!buffer.isReadable()) { return packet; }
int32_t result123 = buffer.readInt();
packet->myCompatible = result123;
if (!buffer.isReadable()) { return packet; }
auto result124 = buffer.readPacket(102);
auto *result125 = (ObjectA *) result124.get();
packet->myObject = *result125;
return packet;
}
};
@@ -1,7 +1,7 @@
#ifndef ZFOO_EMPTYOBJECT_H
#define ZFOO_EMPTYOBJECT_H
#include "cppProtocol/ByteBuffer.h"
#include "zfoocpp/ByteBuffer.h"
namespace zfoo {
@@ -36,19 +36,25 @@ namespace zfoo {
}
void write(ByteBuffer &buffer, IProtocol *packet) override {
if (buffer.writePacketFlag(packet)) {
if (packet == nullptr) {
buffer.writeInt(0);
return;
}
auto *message = (EmptyObject *) packet;
buffer.writeInt(-1);
}
IProtocol *read(ByteBuffer &buffer) override {
auto *packet = new EmptyObject();
if (!buffer.readBool()) {
auto length = buffer.readInt();
if (length == 0) {
return packet;
}
auto beforeReadIndex = buffer.readerIndex();
if (length > 0) {
buffer.readerIndex(beforeReadIndex + length);
}
return packet;
}
};
@@ -1,9 +1,9 @@
#ifndef ZFOO_NORMALOBJECT_H
#define ZFOO_NORMALOBJECT_H
#include "cppProtocol/ByteBuffer.h"
#include "cppProtocol/Packet/ObjectA.h"
#include "cppProtocol/Packet/ObjectB.h"
#include "zfoocpp/ByteBuffer.h"
#include "zfoocpp/Packet/ObjectA.h"
#include "zfoocpp/Packet/ObjectB.h"
namespace zfoo {
@@ -28,10 +28,12 @@ namespace zfoo {
map<int32_t, ObjectA> mm;
set<int32_t> s;
set<string> ssss;
int32_t outCompatibleValue;
int32_t outCompatibleValue2;
~NormalObject() override = default;
static NormalObject valueOf(int8_t a, vector<int8_t> aaa, int16_t b, int32_t c, int64_t d, float e, double f, bool g, string jj, ObjectA kk, list<int32_t> l, list<int64_t> ll, list<ObjectA> lll, list<string> llll, map<int32_t, string> m, map<int32_t, ObjectA> mm, set<int32_t> s, set<string> ssss) {
static NormalObject valueOf(int8_t a, vector<int8_t> aaa, int16_t b, int32_t c, int64_t d, float e, double f, bool g, string jj, ObjectA kk, list<int32_t> l, list<int64_t> ll, list<ObjectA> lll, list<string> llll, map<int32_t, string> m, map<int32_t, ObjectA> mm, set<int32_t> s, set<string> ssss, int32_t outCompatibleValue, int32_t outCompatibleValue2) {
auto packet = NormalObject();
packet.a = a;
packet.aaa = aaa;
@@ -51,6 +53,8 @@ namespace zfoo {
packet.mm = mm;
packet.s = s;
packet.ssss = ssss;
packet.outCompatibleValue = outCompatibleValue;
packet.outCompatibleValue2 = outCompatibleValue2;
return packet;
}
@@ -95,6 +99,10 @@ namespace zfoo {
if (_.s < s) { return false; }
if (ssss < _.ssss) { return true; }
if (_.ssss < ssss) { return false; }
if (outCompatibleValue < _.outCompatibleValue) { return true; }
if (_.outCompatibleValue < outCompatibleValue) { return false; }
if (outCompatibleValue2 < _.outCompatibleValue2) { return true; }
if (_.outCompatibleValue2 < outCompatibleValue2) { return false; }
return false;
}
};
@@ -107,10 +115,13 @@ namespace zfoo {
}
void write(ByteBuffer &buffer, IProtocol *packet) override {
if (buffer.writePacketFlag(packet)) {
if (packet == nullptr) {
buffer.writeInt(0);
return;
}
auto *message = (NormalObject *) packet;
auto beforeWriteIndex = buffer.writerIndex();
buffer.writeInt(857);
buffer.writeByte(message->a);
buffer.writeByteArray(message->aaa);
buffer.writeShort(message->b);
@@ -129,13 +140,18 @@ namespace zfoo {
buffer.writeIntPacketMap(message->mm, 102);
buffer.writeIntSet(message->s);
buffer.writeStringSet(message->ssss);
buffer.writeInt(message->outCompatibleValue);
buffer.writeInt(message->outCompatibleValue2);
buffer.adjustPadding(857, beforeWriteIndex);
}
IProtocol *read(ByteBuffer &buffer) override {
auto *packet = new NormalObject();
if (!buffer.readBool()) {
auto length = buffer.readInt();
if (length == 0) {
return packet;
}
auto beforeReadIndex = buffer.readerIndex();
int8_t result0 = buffer.readByte();
packet->a = result0;
auto array1 = buffer.readByteArray();
@@ -173,6 +189,17 @@ namespace zfoo {
packet->s = set17;
auto set18 = buffer.readStringSet();
packet->ssss = set18;
if (buffer.compatibleRead(beforeReadIndex, length)) {
int32_t result19 = buffer.readInt();
packet->outCompatibleValue = result19;
}
if (buffer.compatibleRead(beforeReadIndex, length)) {
int32_t result20 = buffer.readInt();
packet->outCompatibleValue2 = result20;
}
if (length > 0) {
buffer.readerIndex(beforeReadIndex + length);
}
return packet;
}
};
@@ -1,8 +1,8 @@
#ifndef ZFOO_OBJECTA_H
#define ZFOO_OBJECTA_H
#include "cppProtocol/ByteBuffer.h"
#include "cppProtocol/Packet/ObjectB.h"
#include "zfoocpp/ByteBuffer.h"
#include "zfoocpp/Packet/ObjectB.h"
namespace zfoo {
@@ -12,14 +12,16 @@ namespace zfoo {
int32_t a;
map<int32_t, string> m;
ObjectB objectB;
int32_t innerCompatibleValue;
~ObjectA() override = default;
static ObjectA valueOf(int32_t a, map<int32_t, string> m, ObjectB objectB) {
static ObjectA valueOf(int32_t a, map<int32_t, string> m, ObjectB objectB, int32_t innerCompatibleValue) {
auto packet = ObjectA();
packet.a = a;
packet.m = m;
packet.objectB = objectB;
packet.innerCompatibleValue = innerCompatibleValue;
return packet;
}
@@ -34,6 +36,8 @@ namespace zfoo {
if (_.m < m) { return false; }
if (objectB < _.objectB) { return true; }
if (_.objectB < objectB) { return false; }
if (innerCompatibleValue < _.innerCompatibleValue) { return true; }
if (_.innerCompatibleValue < innerCompatibleValue) { return false; }
return false;
}
};
@@ -46,20 +50,27 @@ namespace zfoo {
}
void write(ByteBuffer &buffer, IProtocol *packet) override {
if (buffer.writePacketFlag(packet)) {
if (packet == nullptr) {
buffer.writeInt(0);
return;
}
auto *message = (ObjectA *) packet;
auto beforeWriteIndex = buffer.writerIndex();
buffer.writeInt(201);
buffer.writeInt(message->a);
buffer.writeIntStringMap(message->m);
buffer.writePacket(&message->objectB, 103);
buffer.writeInt(message->innerCompatibleValue);
buffer.adjustPadding(201, beforeWriteIndex);
}
IProtocol *read(ByteBuffer &buffer) override {
auto *packet = new ObjectA();
if (!buffer.readBool()) {
auto length = buffer.readInt();
if (length == 0) {
return packet;
}
auto beforeReadIndex = buffer.readerIndex();
int32_t result0 = buffer.readInt();
packet->a = result0;
auto map1 = buffer.readIntStringMap();
@@ -67,6 +78,13 @@ namespace zfoo {
auto result2 = buffer.readPacket(103);
auto *result3 = (ObjectB *) result2.get();
packet->objectB = *result3;
if (buffer.compatibleRead(beforeReadIndex, length)) {
int32_t result4 = buffer.readInt();
packet->innerCompatibleValue = result4;
}
if (length > 0) {
buffer.readerIndex(beforeReadIndex + length);
}
return packet;
}
};
@@ -1,7 +1,7 @@
#ifndef ZFOO_OBJECTB_H
#define ZFOO_OBJECTB_H
#include "cppProtocol/ByteBuffer.h"
#include "zfoocpp/ByteBuffer.h"
namespace zfoo {
@@ -9,12 +9,14 @@ namespace zfoo {
class ObjectB : public IProtocol {
public:
bool flag;
int32_t innerCompatibleValue;
~ObjectB() override = default;
static ObjectB valueOf(bool flag) {
static ObjectB valueOf(bool flag, int32_t innerCompatibleValue) {
auto packet = ObjectB();
packet.flag = flag;
packet.innerCompatibleValue = innerCompatibleValue;
return packet;
}
@@ -25,6 +27,8 @@ namespace zfoo {
bool operator<(const ObjectB &_) const {
if (flag < _.flag) { return true; }
if (_.flag < flag) { return false; }
if (innerCompatibleValue < _.innerCompatibleValue) { return true; }
if (_.innerCompatibleValue < innerCompatibleValue) { return false; }
return false;
}
};
@@ -37,20 +41,34 @@ namespace zfoo {
}
void write(ByteBuffer &buffer, IProtocol *packet) override {
if (buffer.writePacketFlag(packet)) {
if (packet == nullptr) {
buffer.writeInt(0);
return;
}
auto *message = (ObjectB *) packet;
auto beforeWriteIndex = buffer.writerIndex();
buffer.writeInt(4);
buffer.writeBool(message->flag);
buffer.writeInt(message->innerCompatibleValue);
buffer.adjustPadding(4, beforeWriteIndex);
}
IProtocol *read(ByteBuffer &buffer) override {
auto *packet = new ObjectB();
if (!buffer.readBool()) {
auto length = buffer.readInt();
if (length == 0) {
return packet;
}
auto beforeReadIndex = buffer.readerIndex();
bool result0 = buffer.readBool();
packet->flag = result0;
if (buffer.compatibleRead(beforeReadIndex, length)) {
int32_t result1 = buffer.readInt();
packet->innerCompatibleValue = result1;
}
if (length > 0) {
buffer.readerIndex(beforeReadIndex + length);
}
return packet;
}
};
@@ -1,7 +1,7 @@
#ifndef ZFOO_SIMPLEOBJECT_H
#define ZFOO_SIMPLEOBJECT_H
#include "cppProtocol/ByteBuffer.h"
#include "zfoocpp/ByteBuffer.h"
namespace zfoo {
@@ -41,23 +41,30 @@ namespace zfoo {
}
void write(ByteBuffer &buffer, IProtocol *packet) override {
if (buffer.writePacketFlag(packet)) {
if (packet == nullptr) {
buffer.writeInt(0);
return;
}
auto *message = (SimpleObject *) packet;
buffer.writeInt(-1);
buffer.writeInt(message->c);
buffer.writeBool(message->g);
}
IProtocol *read(ByteBuffer &buffer) override {
auto *packet = new SimpleObject();
if (!buffer.readBool()) {
auto length = buffer.readInt();
if (length == 0) {
return packet;
}
auto beforeReadIndex = buffer.readerIndex();
int32_t result0 = buffer.readInt();
packet->c = result0;
bool result1 = buffer.readBool();
packet->g = result1;
if (length > 0) {
buffer.readerIndex(beforeReadIndex + length);
}
return packet;
}
};
File diff suppressed because one or more lines are too long