mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-31 14:17:45 +00:00
feat[cpp]: compatible field of inside protocol class
This commit is contained in:
@@ -228,6 +228,23 @@ namespace zfoo {
|
||||
writerIndex(writeIndex);
|
||||
}
|
||||
|
||||
inline int32_t writeIntCount(const int32_t &intValue) {
|
||||
uint32_t v = (uint32_t) ((intValue << 1) ^ (intValue >> 31));
|
||||
if (v >> 7 == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (v >> 14 == 0) {
|
||||
return 2;
|
||||
}
|
||||
if (v >> 21 == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (v >> 28 == 0) {
|
||||
return 4;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
inline int32_t readInt() {
|
||||
int32_t readIndex = m_readerIndex;
|
||||
|
||||
@@ -384,17 +401,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);
|
||||
@@ -863,70 +869,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()) {
|
||||
|
||||
Reference in New Issue
Block a user