mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-08 22:26:17 +00:00
feat[protocol]: 支持C++序列化协议
This commit is contained in:
@@ -17,6 +17,7 @@ import com.zfoo.protocol.registration.IProtocolRegistration;
|
||||
import com.zfoo.protocol.registration.ProtocolAnalysis;
|
||||
import com.zfoo.protocol.registration.ProtocolRegistration;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.cpp.GenerateCppUtils;
|
||||
import com.zfoo.protocol.serializer.cs.GenerateCsUtils;
|
||||
import com.zfoo.protocol.serializer.gd.GenerateGdUtils;
|
||||
import com.zfoo.protocol.serializer.js.GenerateJsUtils;
|
||||
@@ -96,8 +97,16 @@ public abstract class GenerateProtocolFile {
|
||||
GenerateProtocolPath.initProtocolPath(allSortedGenerateProtocols);
|
||||
}
|
||||
|
||||
// 生成C#协议
|
||||
// 生成C++协议
|
||||
var generateLanguages = generateOperation.getGenerateLanguages();
|
||||
if (generateLanguages.contains(CodeLanguage.Cpp)) {
|
||||
GenerateCppUtils.init(generateOperation);
|
||||
GenerateCppUtils.createProtocolManager(allSortedGenerateProtocols);
|
||||
for (var protocolRegistration : allSortedGenerateProtocols) {
|
||||
GenerateCppUtils.createCppProtocolFile((ProtocolRegistration) protocolRegistration);
|
||||
}
|
||||
}
|
||||
|
||||
if (generateLanguages.contains(CodeLanguage.CSharp)) {
|
||||
GenerateCsUtils.init(generateOperation);
|
||||
GenerateCsUtils.createProtocolManager();
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.zfoo.protocol.generate.GenerateProtocolDocument;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolPath;
|
||||
import com.zfoo.protocol.registration.field.*;
|
||||
import com.zfoo.protocol.serializer.cpp.GenerateCppUtils;
|
||||
import com.zfoo.protocol.serializer.cs.GenerateCsUtils;
|
||||
import com.zfoo.protocol.serializer.gd.GenerateGdUtils;
|
||||
import com.zfoo.protocol.serializer.js.GenerateJsUtils;
|
||||
@@ -112,7 +113,7 @@ public class ProtocolAnalysis {
|
||||
// 通过指定类注册的协议,全部使用字节码增强
|
||||
enhanceProtocolRegistration(Arrays.stream(protocols).filter(it -> Objects.nonNull(it)).collect(Collectors.toList()));
|
||||
|
||||
enhanceProtocolAfter();
|
||||
enhanceProtocolAfter(generateOperation);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -176,7 +177,7 @@ public class ProtocolAnalysis {
|
||||
|
||||
enhanceProtocolRegistration(enhanceList);
|
||||
|
||||
enhanceProtocolAfter();
|
||||
enhanceProtocolAfter(generateOperation);
|
||||
} catch (Exception e) {
|
||||
throw new UnknownException(e);
|
||||
}
|
||||
@@ -211,7 +212,7 @@ public class ProtocolAnalysis {
|
||||
GenerateProtocolFile.generate(generateOperation);
|
||||
}
|
||||
|
||||
private static void enhanceProtocolAfter() {
|
||||
private static void enhanceProtocolAfter(GenerateOperation generateOperation) {
|
||||
subProtocolIdMap.clear();
|
||||
subProtocolIdMap = null;
|
||||
|
||||
@@ -220,16 +221,21 @@ public class ProtocolAnalysis {
|
||||
baseSerializerMap.clear();
|
||||
baseSerializerMap = null;
|
||||
|
||||
EnhanceUtils.clear();
|
||||
|
||||
if (generateOperation.getGenerateLanguages().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateProtocolDocument.clear();
|
||||
GenerateProtocolPath.clear();
|
||||
GenerateProtocolFile.clear();
|
||||
GenerateCppUtils.clear();
|
||||
GenerateCsUtils.clear();
|
||||
GenerateJsUtils.clear();
|
||||
GenerateLuaUtils.clear();
|
||||
GenerateGdUtils.clear();
|
||||
GenerateProtobufUtils.clear();
|
||||
|
||||
EnhanceUtils.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ public enum CodeLanguage {
|
||||
*/
|
||||
Enhance,
|
||||
|
||||
Cpp,
|
||||
|
||||
JavaScript,
|
||||
|
||||
Lua,
|
||||
|
||||
@@ -51,9 +51,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeBooleanArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -63,6 +60,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -72,9 +73,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeBooleanBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -84,6 +82,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -93,9 +95,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeByteArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -105,6 +104,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -114,9 +117,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeByteBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -126,6 +126,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -135,9 +139,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeShortArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -147,6 +148,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -156,9 +161,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeShortBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -168,6 +170,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -177,9 +183,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -189,6 +192,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -198,9 +205,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -210,6 +214,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -219,9 +227,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -231,6 +236,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -240,9 +249,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -252,6 +258,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -261,9 +271,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeFloatArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -273,6 +280,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -282,9 +293,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeFloatBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -294,6 +302,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -303,9 +315,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeDoubleArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -315,6 +324,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -324,9 +337,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeDoubleBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -336,6 +346,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -345,9 +359,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -357,6 +368,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -366,9 +381,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeCharArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeCharArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeCharArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -378,6 +390,10 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteCharArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeCharArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -387,9 +403,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeCharBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeCharArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeCharArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -399,28 +412,35 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteCharArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeCharArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (arrayField.getArrayElementRegistration() instanceof ObjectProtocolField) {
|
||||
var objectProtocolField = (ObjectProtocolField) arrayField.getArrayElementRegistration();
|
||||
var protocolId = ((ObjectProtocolField) arrayField.getArrayElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writePacketArray($1, {}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(objectProtocolField.getProtocolId())));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("{}.writePacketArray($1, {}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WritePacketArray<{}>({}, {});", EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()), objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer.WritePacketArray<{}>({}, {});", EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray<{}>({}, {});", EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
@@ -447,9 +467,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readBooleanArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -459,6 +476,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -468,9 +491,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readBooleanBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -480,6 +500,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -489,9 +515,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readByteArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readByteArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -501,6 +524,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadByteArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readByteArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -510,9 +539,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readByteBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readByteArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -522,6 +548,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadByteArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readByteArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -531,9 +563,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readShortArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readShortArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -543,6 +572,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadShortArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readShortArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -552,9 +587,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readShortBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readShortArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -564,6 +596,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadShortArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readShortArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -573,9 +611,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readIntArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -585,6 +620,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -594,9 +635,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readIntBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -606,6 +644,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -615,9 +659,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readLongArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -627,6 +668,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -636,9 +683,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readLongBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -648,6 +692,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -657,9 +707,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readFloatArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -669,6 +716,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadFloatArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readFloatArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -678,9 +731,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readFloatBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -690,6 +740,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadFloatArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readFloatArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -699,9 +755,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readDoubleArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -711,6 +764,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -720,9 +779,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readDoubleBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -732,6 +788,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -741,9 +803,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readStringArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -753,6 +812,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -762,9 +827,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readCharArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readCharArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readCharArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -774,6 +836,12 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadCharArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readCharArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readCharArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -783,9 +851,6 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}[] {} = {}.readCharBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readCharArray();", array)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readCharArray()", array)).append(LS);
|
||||
break;
|
||||
@@ -795,26 +860,35 @@ public class CutDownArraySerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadCharArray();", array)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readCharArray();", array)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readCharArray();", array)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (arrayField.getArrayElementRegistration() instanceof ObjectProtocolField) {
|
||||
var objectProtocolField = (ObjectProtocolField) arrayField.getArrayElementRegistration();
|
||||
var protocolId = ((ObjectProtocolField) arrayField.getArrayElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
// Java不支持泛型的数组初始化,这里不做任何操作
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", array, objectProtocolField.getProtocolId())).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", array, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", array, protocolId)).append(LS);
|
||||
break;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", array, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", array, protocolId)).append(LS);
|
||||
break;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadPacketArray<{}>({});", array, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()), objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadPacketArray<{}>({});", array, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readPacketArray<{}>({});", array, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", array, protocolId)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
|
||||
@@ -50,9 +50,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeBooleanList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -62,6 +59,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteBooleanList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -71,9 +74,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeByteList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -83,6 +83,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteByteList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeByteList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -92,9 +98,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeShortList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -104,6 +107,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteShortList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeShortList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -113,9 +122,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -125,6 +131,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeIntList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -134,9 +146,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -146,6 +155,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeLongList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -156,9 +171,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeFloatList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -168,6 +180,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteFloatList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeFloatList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -178,9 +196,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeDoubleList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -190,6 +205,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteDoubleList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -200,9 +221,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -212,6 +230,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeStringList({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -219,22 +243,25 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
default:
|
||||
// List<IPacket>
|
||||
if (listField.getListElementRegistration() instanceof ObjectProtocolField) {
|
||||
var objectProtocolField = (ObjectProtocolField) listField.getListElementRegistration();
|
||||
var protocolId = ((ObjectProtocolField) listField.getListElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writePacketList($1, (List){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(objectProtocolField.getProtocolId())));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("{}.writePacketList($1, (List){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WritePacketList({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer.WritePacketList({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writePacketList({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
@@ -260,9 +287,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readBooleanList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -272,6 +296,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadBooleanList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readBooleanList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -281,9 +311,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readByteList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readByteArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -293,6 +320,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadByteList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readByteList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -302,9 +335,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readShortList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readShortArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -314,6 +344,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadShortList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readShortList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -323,9 +359,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readIntList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -335,6 +368,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -344,9 +383,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readLongList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -356,6 +392,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -365,9 +407,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readFloatList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -377,6 +416,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadFloatList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readFloatList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -386,9 +431,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readDoubleList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -398,6 +440,12 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadDoubleList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readDoubleList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -407,9 +455,6 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readStringList($1);", list, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringArray();", list)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringArray()", list)).append(LS);
|
||||
break;
|
||||
@@ -419,28 +464,37 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringList();", list)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringList();", list)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringArray();", list)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (listField.getListElementRegistration() instanceof ObjectProtocolField) {
|
||||
var objectProtocolField = (ObjectProtocolField) listField.getListElementRegistration();
|
||||
var protocolId = ((ObjectProtocolField) listField.getListElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("List {} = {}.readPacketList($1, {});", list, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(objectProtocolField.getProtocolId())));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", list, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("List {} = {}.readPacketList($1, {});", list, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", list, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", list, protocolId)).append(LS);
|
||||
break;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", list, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", list, protocolId)).append(LS);
|
||||
break;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadPacketList<{}>({});", list, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()), objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadPacketList<{}>({});", list, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readPacketList<{}>({});", list, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", list, protocolId)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
|
||||
@@ -57,9 +57,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntIntMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -69,15 +66,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == LongSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntLongMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntLongMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -87,12 +85,19 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntLongMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntLongMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == StringSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeIntStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -111,9 +116,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(((ObjectProtocolField) valueRegistration).getProtocolId())));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntPacketMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
@@ -123,6 +125,10 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (keySerializer == LongSerializer.INSTANCE) {
|
||||
@@ -131,9 +137,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongIntMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -143,15 +146,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == LongSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongLongMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongLongMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
@@ -161,15 +165,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongLongMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongLongMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == StringSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongStringMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -179,15 +184,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == ObjectProtocolSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(((ObjectProtocolField) valueRegistration).getProtocolId())));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongPacketMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
@@ -197,6 +203,10 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (keySerializer == StringSerializer.INSTANCE) {
|
||||
@@ -205,9 +215,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringIntMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -217,15 +224,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringIntMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == LongSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringLongMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringLongMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -235,15 +243,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringLongMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringLongMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == StringSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringStringMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -253,15 +262,16 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringStringMap({});", objectStr)).append(LS);
|
||||
return true;
|
||||
}
|
||||
} else if (valueSerializer == ObjectProtocolSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(((ObjectProtocolField) valueRegistration).getProtocolId())));
|
||||
return true;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringPacketMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
@@ -271,6 +281,10 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
case Cpp:
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,9 +309,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntIntMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -307,15 +318,18 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntIntMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == LongSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntLongMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -325,15 +339,18 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntLongMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == StringSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntStringMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -343,6 +360,12 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntStringMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == ObjectProtocolSerializer.INSTANCE) {
|
||||
var protocolId = ((ObjectProtocolField) valueRegistration).getProtocolId();
|
||||
@@ -350,18 +373,21 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(((ObjectProtocolField) valueRegistration).getProtocolId())));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntPacketMap({});", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntPacketMap({})", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readIntPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("local {} = buffer:readIntPacketMap({})", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntPacketMap({});", map, protocolId)).append(LS);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
} else if (keySerializer == LongSerializer.INSTANCE) {
|
||||
@@ -370,9 +396,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongIntMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -382,15 +405,18 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongIntMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == LongSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongLongMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -400,14 +426,20 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongLongMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == StringSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongStringMap();", map)).append(LS);
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongStringMap()", map)).append(LS);
|
||||
return map;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readLongStringMap()", map)).append(LS);
|
||||
@@ -415,25 +447,34 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongStringMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == ObjectProtocolSerializer.INSTANCE) {
|
||||
var protocolId = ((ObjectProtocolField) valueRegistration).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(((ObjectProtocolField) valueRegistration).getProtocolId())));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongPacketMap({});", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongPacketMap({})", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readLongPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("local {} = buffer:readLongPacketMap({})", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongPacketMap({});", map, protocolId)).append(LS);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
} else if (keySerializer == StringSerializer.INSTANCE) {
|
||||
@@ -442,9 +483,6 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringIntMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -454,15 +492,18 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringIntMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == LongSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringLongMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -472,15 +513,18 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringLongMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == StringSerializer.INSTANCE) {
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringStringMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -490,25 +534,34 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringStringMap();", map)).append(LS);
|
||||
return map;
|
||||
}
|
||||
} else if (valueSerializer == ObjectProtocolSerializer.INSTANCE) {
|
||||
var protocolId = ((ObjectProtocolField) valueRegistration).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(((ObjectProtocolField) valueRegistration).getProtocolId())));
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringPacketMap({});", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringPacketMap({})", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readStringPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("local {} = buffer:readStringPacketMap({})", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
return map;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
return map;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringPacketMap({});", map, protocolId)).append(LS);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeBooleanSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -63,6 +60,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteBooleanSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -72,9 +75,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeByteSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -84,6 +84,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteByteSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeByteSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -93,9 +99,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeShortSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -105,6 +108,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteShortSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeShortSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -114,9 +123,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -126,6 +132,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteIntSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeIntSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -135,9 +147,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -147,6 +156,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteLongSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeLongSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -156,9 +171,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeFloatSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -168,6 +180,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteFloatSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeFloatSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -177,9 +195,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeDoubleSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -189,6 +204,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteDoubleSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -198,9 +219,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS);
|
||||
break;
|
||||
@@ -210,6 +228,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WriteStringSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writeStringSet({});", objectStr)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -217,22 +241,25 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
default:
|
||||
// Set<IPacket>
|
||||
if (setField.getSetElementRegistration() instanceof ObjectProtocolField) {
|
||||
var objectProtocolField = (ObjectProtocolField) setField.getSetElementRegistration();
|
||||
var protocolId = ((ObjectProtocolField) setField.getSetElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writePacketSet($1, (Set){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(objectProtocolField.getProtocolId())));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("{}.writePacketSet($1, (Set){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("buffer.WritePacketSet({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("buffer.WritePacketSet({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("buffer.writePacketSet({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, protocolId)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
@@ -258,9 +285,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readBooleanSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -270,6 +294,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadBooleanSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readBooleanSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -279,9 +309,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readByteSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readByteArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -291,6 +318,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadByteSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readByteSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readByteArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -300,9 +333,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readShortSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readShortArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -312,6 +342,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadShortSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readShortSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readShortArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -321,9 +357,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readIntSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -333,6 +366,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadIntSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readIntSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -342,9 +381,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readLongSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -354,6 +390,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadLongSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLongSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -363,9 +405,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readFloatSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -375,6 +414,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadFloatSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readFloatSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readFloatArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -384,9 +429,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readDoubleSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -396,6 +438,12 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadDoubleSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readDoubleSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
@@ -405,9 +453,6 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readStringSet($1);", set, EnhanceUtils.byteBufUtils));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringArray();", set)).append(LS);
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringArray()", set)).append(LS);
|
||||
break;
|
||||
@@ -417,28 +462,37 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadStringSet();", set)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readStringSet();", set)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringArray();", set)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (setField.getSetElementRegistration() instanceof ObjectProtocolField) {
|
||||
var objectProtocolField = (ObjectProtocolField) setField.getSetElementRegistration();
|
||||
var protocolId = ((ObjectProtocolField) setField.getSetElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Set {} = {}.readPacketSet($1, {});", set, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(objectProtocolField.getProtocolId())));
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", set, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("Set {} = {}.readPacketSet($1, {});", set, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
|
||||
break;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", set, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", set, protocolId)).append(LS);
|
||||
break;
|
||||
case Lua:
|
||||
builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", set, objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", set, protocolId)).append(LS);
|
||||
break;
|
||||
case CSharp:
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadPacketSet<{}>({});", set, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()), objectProtocolField.getProtocolId())).append(LS);
|
||||
builder.append(StringUtils.format("var {} = buffer.ReadPacketSet<{}>({});", set, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
break;
|
||||
case Cpp:
|
||||
builder.append(StringUtils.format("auto {} = buffer.readPacketSet<{}>({});", set, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS);
|
||||
break;
|
||||
case JavaScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", set, protocolId)).append(LS);
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.ArrayField;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.CutDownArraySerializer;
|
||||
import com.zfoo.protocol.serializer.reflect.ObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppArraySerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = GenerateCppUtils.toCppClassName(field.getType().getComponentType().getSimpleName());
|
||||
return new Pair<>(StringUtils.format("vector<{}>", type), field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
if (CutDownArraySerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.Cpp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayField arrayField = (ArrayField) fieldRegistration;
|
||||
|
||||
String length = "length" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("int32_t {} = {}.size();", length, objectStr)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeInt({});", length)).append(LS);
|
||||
|
||||
String i = "i" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (auto {} = 0; {} < {}; {}++) {", i, i, length, i)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
String element = "element" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("{} {} = {}[{}];", GenerateCppUtils.toCppClassName(arrayField.getType().getSimpleName()), element, objectStr, i)).append(LS);
|
||||
|
||||
GenerateCppUtils.cppSerializer(arrayField.getArrayElementRegistration().serializer())
|
||||
.writeObject(builder, element, deep + 1, field, arrayField.getArrayElementRegistration());
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
var cutDown = CutDownArraySerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.Cpp);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
}
|
||||
|
||||
|
||||
var arrayField = (ArrayField) fieldRegistration;
|
||||
var result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
var typeName = GenerateCppUtils.toCppClassName(arrayField.getType().getSimpleName());
|
||||
|
||||
var i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
var size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("int32_t {} = buffer.readInt();", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("vector<{}> {};", typeName, result)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (int {} = 0; {} < {}; {}++) {", i, i, size, i)).append(LS);
|
||||
var readObject = GenerateCppUtils.cppSerializer(arrayField.getArrayElementRegistration().serializer())
|
||||
.readObject(builder, deep + 2, field, arrayField.getArrayElementRegistration());
|
||||
|
||||
var point = StringUtils.EMPTY;
|
||||
if (arrayField.getArrayElementRegistration().serializer() == ObjectProtocolSerializer.INSTANCE) {
|
||||
point = "*";
|
||||
}
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep + 2);
|
||||
builder.append(StringUtils.format("{}.emplace_back({});", result, point, readObject));
|
||||
builder.append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppBooleanSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("bool", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeBool({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("bool {} = buffer.readBool();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppByteSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int8_t", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeByte({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("int8_t {} = buffer.readByte();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppCharSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("char", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeChar({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("char {} = buffer.readChar();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppDoubleSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("double", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeDouble({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("double {} = buffer.readDouble();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppFloatSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("float", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeFloat({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("float {} = buffer.readFloat();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppIntSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int32_t", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeInt({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("int32_t {} = buffer.readInt();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.registration.field.ListField;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.CutDownListSerializer;
|
||||
import com.zfoo.protocol.serializer.reflect.ObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppListSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = GenerateCppUtils.toCppClassName(field.getGenericType().toString());
|
||||
var name = StringUtils.format("{}", field.getName());
|
||||
return new Pair<>(type, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
if (CutDownListSerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.Cpp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ListField listField = (ListField) fieldRegistration;
|
||||
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size());", objectStr)).append(LS);
|
||||
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
String i = "i" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("for (auto {} : {}) {", i, objectStr)).append(LS);
|
||||
|
||||
GenerateCppUtils.cppSerializer(listField.getListElementRegistration().serializer())
|
||||
.writeObject(builder, i, deep + 1, field, listField.getListElementRegistration());
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
var cutDown = CutDownListSerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.Cpp);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
}
|
||||
|
||||
var listField = (ListField) fieldRegistration;
|
||||
|
||||
var result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
var typeName = GenerateCppUtils.toCppClassName(listField.getType().toString());
|
||||
|
||||
var i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
var size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
builder.append(StringUtils.format("int32_t {} = buffer.readInt();", size)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("{} {};", typeName, result)).append(LS);
|
||||
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (int {} = 0; {} < {}; {}++) {", i, i, size, i)).append(LS);
|
||||
var readObject = GenerateCppUtils.cppSerializer(listField.getListElementRegistration().serializer())
|
||||
.readObject(builder, deep + 1, field, listField.getListElementRegistration());
|
||||
|
||||
var point = StringUtils.EMPTY;
|
||||
if (listField.getListElementRegistration().serializer() == ObjectProtocolSerializer.INSTANCE) {
|
||||
point = "*";
|
||||
}
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("{}.emplace_back({}{});", result, point, readObject)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppLongSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int64_t", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeLong({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("auto {} = buffer.readLong();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.registration.field.MapField;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.CutDownMapSerializer;
|
||||
import com.zfoo.protocol.serializer.reflect.ObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppMapSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = GenerateCppUtils.toCppClassName(field.getGenericType().toString());
|
||||
var name = StringUtils.format("{}", field.getName());
|
||||
return new Pair<>(type, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
if (CutDownMapSerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.Cpp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MapField mapField = (MapField) fieldRegistration;
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size());", objectStr)).append(LS);
|
||||
|
||||
String key = "keyElement" + GenerateProtocolFile.index.getAndIncrement();
|
||||
String value = "valueElement" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (auto&[{}, {}] : {}) {", key, value, objectStr)).append(LS);
|
||||
|
||||
var mapKeyRegistration = mapField.getMapKeyRegistration();
|
||||
var mapValueRegistration = mapField.getMapValueRegistration();
|
||||
GenerateCppUtils.cppSerializer(mapField.getMapKeyRegistration().serializer())
|
||||
.writeObject(builder, key, deep + 1, field, mapField.getMapKeyRegistration());
|
||||
GenerateCppUtils.cppSerializer(mapField.getMapValueRegistration().serializer())
|
||||
.writeObject(builder, value, deep + 1, field, mapField.getMapValueRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
var cutDown = CutDownMapSerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.Cpp);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
}
|
||||
|
||||
MapField mapField = (MapField) fieldRegistration;
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
var typeName = GenerateCppUtils.toCppClassName(mapField.getType().toString());
|
||||
|
||||
String size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("int32_t {} = buffer.readInt();", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("{} {};", typeName, result)).append(LS);
|
||||
|
||||
|
||||
String i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (auto {} = 0; {} < {}; {}++) {", i, i, size, i)).append(LS);
|
||||
|
||||
String keyObject = GenerateCppUtils.cppSerializer(mapField.getMapKeyRegistration().serializer())
|
||||
.readObject(builder, deep + 1, field, mapField.getMapKeyRegistration());
|
||||
|
||||
String valueObject = GenerateCppUtils.cppSerializer(mapField.getMapValueRegistration().serializer())
|
||||
.readObject(builder, deep + 1, field, mapField.getMapValueRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
|
||||
var keyPoint = StringUtils.EMPTY;
|
||||
var valuePoint = StringUtils.EMPTY;
|
||||
if (mapField.getMapKeyRegistration().serializer() == ObjectProtocolSerializer.INSTANCE) {
|
||||
keyPoint = "*";
|
||||
}
|
||||
if (mapField.getMapValueRegistration().serializer() == ObjectProtocolSerializer.INSTANCE) {
|
||||
valuePoint = "*";
|
||||
}
|
||||
|
||||
builder.append(StringUtils.format("{}.insert(make_pair({}{}, {}{}));", result, keyPoint, keyObject, valuePoint, valueObject)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.registration.field.ObjectProtocolField;
|
||||
import com.zfoo.protocol.serializer.enhance.EnhanceObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppObjectProtocolSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId());
|
||||
var type = StringUtils.format("{}", protocolSimpleName);
|
||||
var name = field.getName();
|
||||
return new Pair<>(type, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
if (IPacket.class.isAssignableFrom(field.getType())) {
|
||||
builder.append(StringUtils.format("buffer.writePacket({}, {});", objectStr, objectProtocolField.getProtocolId()))
|
||||
.append(LS);
|
||||
} else {
|
||||
builder.append(StringUtils.format("buffer.writePacket((IPacket *) &{}, {});", objectStr, objectProtocolField.getProtocolId()))
|
||||
.append(LS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
String uniquePtr = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
String ptr = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId());
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("auto {} = buffer.readPacket({});", uniquePtr, objectProtocolField.getProtocolId())).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("auto *{} = ({} *) {}.get();", ptr, protocolSimpleName, uniquePtr)).append(LS);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.registration.field.SetField;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.CutDownSetSerializer;
|
||||
import com.zfoo.protocol.serializer.reflect.ObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppSetSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = GenerateCppUtils.toCppClassName(field.getGenericType().toString());
|
||||
var name = StringUtils.format("{}", field.getName());
|
||||
return new Pair<>(type, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
if (CutDownSetSerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.Cpp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetField setField = (SetField) fieldRegistration;
|
||||
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size());", objectStr)).append(LS);
|
||||
|
||||
String element = "i" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (auto {} : {}) {", element, objectStr)).append(LS);
|
||||
|
||||
GenerateCppUtils.cppSerializer(setField.getSetElementRegistration().serializer())
|
||||
.writeObject(builder, element, deep + 1, field, setField.getSetElementRegistration());
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
var cutDown = CutDownSetSerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.Cpp);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
}
|
||||
|
||||
SetField setField = (SetField) fieldRegistration;
|
||||
var result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
var typeName = GenerateCppUtils.toCppClassName(setField.getType().toString());
|
||||
|
||||
var i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
var size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("int32_t {} = buffer.readInt();", size)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
// unity里不支持HashSet的初始化大小
|
||||
// builder.append("var " + result + " = new " + typeName + "(" + size + ");" + LS);
|
||||
builder.append(StringUtils.format("{} {};", typeName, result)).append(LS);
|
||||
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("for (int {} = 0; {} < {}; {}++) {", i, i, size, i)).append(LS);
|
||||
|
||||
var point = StringUtils.EMPTY;
|
||||
if (setField.getSetElementRegistration().serializer() == ObjectProtocolSerializer.INSTANCE) {
|
||||
point = "*";
|
||||
}
|
||||
|
||||
var readObject = GenerateCppUtils.cppSerializer(setField.getSetElementRegistration().serializer())
|
||||
.readObject(builder, deep + 1, field, setField.getSetElementRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("{}.emplace({}{});", result, point, readObject)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append("}").append(LS);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppShortSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int16_t", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeShort({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("auto {} = buffer.readShort();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class CppStringSerializer implements ICppSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("string", field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeString({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("auto {} = buffer.readString();", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.protocol.collection.CollectionUtils;
|
||||
import com.zfoo.protocol.generate.GenerateOperation;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolDocument;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolPath;
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.IProtocolRegistration;
|
||||
import com.zfoo.protocol.registration.ProtocolAnalysis;
|
||||
import com.zfoo.protocol.registration.ProtocolRegistration;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.serializer.enhance.EnhanceObjectProtocolSerializer;
|
||||
import com.zfoo.protocol.serializer.reflect.*;
|
||||
import com.zfoo.protocol.util.ClassUtils;
|
||||
import com.zfoo.protocol.util.FileUtils;
|
||||
import com.zfoo.protocol.util.IOUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
import static com.zfoo.protocol.util.StringUtils.TAB;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public abstract class GenerateCppUtils {
|
||||
|
||||
private static String protocolOutputRootPath = "zfoocpp";
|
||||
private static String protocolOutputPath = StringUtils.EMPTY;
|
||||
|
||||
private static Map<ISerializer, ICppSerializer> cppSerializerMap;
|
||||
|
||||
public static ICppSerializer cppSerializer(ISerializer serializer) {
|
||||
return cppSerializerMap.get(serializer);
|
||||
}
|
||||
|
||||
public static void init(GenerateOperation generateOperation) {
|
||||
protocolOutputPath = FileUtils.joinPath(generateOperation.getProtocolPath(), protocolOutputRootPath);
|
||||
|
||||
FileUtils.deleteFile(new File(protocolOutputPath));
|
||||
FileUtils.createDirectory(protocolOutputPath);
|
||||
|
||||
cppSerializerMap = new HashMap<>();
|
||||
cppSerializerMap.put(BooleanSerializer.INSTANCE, new CppBooleanSerializer());
|
||||
cppSerializerMap.put(ByteSerializer.INSTANCE, new CppByteSerializer());
|
||||
cppSerializerMap.put(ShortSerializer.INSTANCE, new CppShortSerializer());
|
||||
cppSerializerMap.put(IntSerializer.INSTANCE, new CppIntSerializer());
|
||||
cppSerializerMap.put(LongSerializer.INSTANCE, new CppLongSerializer());
|
||||
cppSerializerMap.put(FloatSerializer.INSTANCE, new CppFloatSerializer());
|
||||
cppSerializerMap.put(DoubleSerializer.INSTANCE, new CppDoubleSerializer());
|
||||
cppSerializerMap.put(CharSerializer.INSTANCE, new CppCharSerializer());
|
||||
cppSerializerMap.put(StringSerializer.INSTANCE, new CppStringSerializer());
|
||||
cppSerializerMap.put(ArraySerializer.INSTANCE, new CppArraySerializer());
|
||||
cppSerializerMap.put(ListSerializer.INSTANCE, new CppListSerializer());
|
||||
cppSerializerMap.put(SetSerializer.INSTANCE, new CppSetSerializer());
|
||||
cppSerializerMap.put(MapSerializer.INSTANCE, new CppMapSerializer());
|
||||
cppSerializerMap.put(ObjectProtocolSerializer.INSTANCE, new CppObjectProtocolSerializer());
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
cppSerializerMap = null;
|
||||
protocolOutputRootPath = null;
|
||||
protocolOutputPath = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成协议依赖的工具类
|
||||
*/
|
||||
public static void createProtocolManager(List<IProtocolRegistration> protocolList) throws IOException {
|
||||
var list = List.of("cpp/ByteBuffer.h");
|
||||
|
||||
for (var fileName : list) {
|
||||
var fileInputStream = ClassUtils.getFileFromClassPath(fileName);
|
||||
var createFile = new File(StringUtils.format("{}/{}", protocolOutputPath, StringUtils.substringAfterFirst(fileName, "cpp/")));
|
||||
FileUtils.writeInputStreamToFile(createFile, fileInputStream);
|
||||
}
|
||||
|
||||
var protocolManagerTemplate = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("cpp/ProtocolManagerTemplate.h")));
|
||||
|
||||
// 生成ProtocolManager.gd文件
|
||||
var headerBuilder = new StringBuilder();
|
||||
protocolList.stream()
|
||||
.filter(it -> Objects.nonNull(it))
|
||||
.forEach(it -> {
|
||||
var name = it.protocolConstructor().getDeclaringClass().getSimpleName();
|
||||
var path = StringUtils.format("#include \"{}/{}/{}.h\"", protocolOutputRootPath, GenerateProtocolPath.getProtocolPath(it.protocolId()), name);
|
||||
path = path.replaceAll("//", StringUtils.SLASH);
|
||||
headerBuilder.append(path).append(LS);
|
||||
});
|
||||
|
||||
var initProtocolBuilder = new StringBuilder();
|
||||
protocolList.stream()
|
||||
.filter(it -> Objects.nonNull(it))
|
||||
.forEach(it -> initProtocolBuilder.append(TAB).append(TAB).append(StringUtils.format("protocols[{}] = new {}Registration();", it.protocolId(), it.protocolConstructor().getDeclaringClass().getSimpleName())).append(LS));
|
||||
|
||||
protocolManagerTemplate = StringUtils.format(protocolManagerTemplate, headerBuilder.toString(), initProtocolBuilder.toString().trim());
|
||||
FileUtils.writeStringToFile(new File(StringUtils.format("{}/{}", protocolOutputRootPath, "ProtocolManager.h")), protocolManagerTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成协议类
|
||||
*/
|
||||
public static void createCppProtocolFile(ProtocolRegistration registration) throws IOException {
|
||||
GenerateProtocolFile.index.set(0);
|
||||
|
||||
var protocolId = registration.protocolId();
|
||||
var registrationConstructor = registration.getConstructor();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var protocolClazzName = registrationConstructor.getDeclaringClass().getSimpleName();
|
||||
|
||||
var protocolTemplate = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("cpp/PacketTemplate.h")));
|
||||
|
||||
// protocol object
|
||||
var defineProtocolName = protocolClazzName.toUpperCase();
|
||||
var includeHeaders = includeSubProtocol(registration);
|
||||
var docTitle = docTitle(registration);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var valueOfMethod = valueOfMethod(registration);
|
||||
var operator = operator(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
|
||||
protocolTemplate = StringUtils.format(protocolTemplate, defineProtocolName, defineProtocolName, includeHeaders, docTitle
|
||||
, protocolClazzName, fieldDefinition, protocolClazzName, protocolClazzName, valueOfMethod.getKey(), protocolClazzName
|
||||
, valueOfMethod.getValue().trim(), protocolId, protocolClazzName, operator.trim(),
|
||||
protocolClazzName, protocolId, protocolClazzName, writeObject.trim(), protocolClazzName, readObject.trim());
|
||||
|
||||
var protocolOutputPath = StringUtils.format("{}/{}/{}.h"
|
||||
, GenerateCppUtils.protocolOutputPath
|
||||
, GenerateProtocolPath.getCapitalizeProtocolPath(protocolId)
|
||||
, protocolClazzName);
|
||||
FileUtils.writeStringToFile(new File(protocolOutputPath), protocolTemplate);
|
||||
}
|
||||
|
||||
|
||||
private static String includeSubProtocol(ProtocolRegistration registration) {
|
||||
short protocolId = registration.getId();
|
||||
var subProtocols = ProtocolAnalysis.getAllSubProtocolIds(protocolId);
|
||||
|
||||
if (CollectionUtils.isEmpty(subProtocols)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
var cppBuilder = new StringBuilder();
|
||||
for (var subProtocolId : subProtocols) {
|
||||
var protocolClassName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(subProtocolId);
|
||||
var subProtocolPath = StringUtils.format("#include \"{}/{}/{}.h\""
|
||||
, protocolOutputRootPath
|
||||
, GenerateProtocolPath.getCapitalizeProtocolPath(protocolId)
|
||||
, protocolClassName);
|
||||
subProtocolPath = subProtocolPath.replaceAll("//", StringUtils.SLASH);
|
||||
cppBuilder.append(subProtocolPath).append(LS);
|
||||
}
|
||||
|
||||
return cppBuilder.toString();
|
||||
}
|
||||
|
||||
private static String docTitle(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var protocolDocument = GenerateProtocolDocument.getProtocolDocument(protocolId);
|
||||
var docTitle = protocolDocument.getKey();
|
||||
|
||||
var cppBuilder = new StringBuilder();
|
||||
if (StringUtils.isNotBlank(docTitle)) {
|
||||
Arrays.stream(docTitle.split(LS)).forEach(it -> cppBuilder.append(TAB).append(it).append(LS));
|
||||
}
|
||||
return cppBuilder.toString().trim();
|
||||
}
|
||||
|
||||
private static String fieldDefinition(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var protocolDocument = GenerateProtocolDocument.getProtocolDocument(protocolId);
|
||||
var docFieldMap = protocolDocument.getValue();
|
||||
|
||||
var cppBuilder = new StringBuilder();
|
||||
// 协议的属性生成
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
Field field = fields[i];
|
||||
IFieldRegistration fieldRegistration = fieldRegistrations[i];
|
||||
|
||||
var propertyTypeAndName = cppSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
var propertyType = propertyTypeAndName.getKey();
|
||||
var propertyName = propertyTypeAndName.getValue();
|
||||
|
||||
var propertyFullName = StringUtils.format("{} {};", propertyType, propertyName);
|
||||
// 生成注释
|
||||
var doc = docFieldMap.get(propertyName);
|
||||
if (StringUtils.isNotBlank(doc)) {
|
||||
Arrays.stream(doc.split(LS)).forEach(it -> cppBuilder.append(TAB + TAB).append(it).append(LS));
|
||||
}
|
||||
cppBuilder.append(TAB + TAB).append(propertyFullName).append(LS);
|
||||
}
|
||||
|
||||
return cppBuilder.toString().trim();
|
||||
}
|
||||
|
||||
private static Pair<String, String> valueOfMethod(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var filedList = new ArrayList<Pair<String, String>>();
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
var propertyTypeAndName = cppSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
filedList.add(propertyTypeAndName);
|
||||
}
|
||||
|
||||
|
||||
// ValueOf()方法
|
||||
var valueOfParams = filedList.stream()
|
||||
.map(it -> StringUtils.format("{} {}", it.getKey(), it.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
var valueOfParamsStr = StringUtils.joinWith(StringUtils.COMMA + " ", valueOfParams.toArray());
|
||||
|
||||
var cppBuilder = new StringBuilder();
|
||||
filedList.forEach(it -> cppBuilder.append(TAB + TAB + TAB).append(StringUtils.format("packet.{} = {};", it.getValue(), it.getValue())).append(LS));
|
||||
|
||||
return new Pair<>(valueOfParamsStr, cppBuilder.toString());
|
||||
}
|
||||
|
||||
private static String operator(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var filedList = new ArrayList<Pair<String, String>>();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
var propertyTypeAndName = cppSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
filedList.add(propertyTypeAndName);
|
||||
}
|
||||
|
||||
// bool operator<
|
||||
var cppBuilder = new StringBuilder();
|
||||
for (var fieldPair : filedList) {
|
||||
cppBuilder.append(TAB + TAB + TAB).append(StringUtils.format("if ({} < _.{}) { return true; }", fieldPair.getValue(), fieldPair.getValue())).append(LS);
|
||||
cppBuilder.append(TAB + TAB + TAB).append(StringUtils.format("if (_.{} < {}) { return false; }", fieldPair.getValue(), fieldPair.getValue())).append(LS);
|
||||
}
|
||||
return cppBuilder.toString();
|
||||
}
|
||||
|
||||
private static String writeObject(ProtocolRegistration registration) {
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var csBuilder = new StringBuilder();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
var serializer = cppSerializer(fieldRegistration.serializer());
|
||||
if (IPacket.class.isAssignableFrom(field.getType())) {
|
||||
serializer.writeObject(csBuilder, "&message->" + field.getName(), 3, field, fieldRegistration);
|
||||
} else {
|
||||
serializer.writeObject(csBuilder, "message->" + field.getName(), 3, field, fieldRegistration);
|
||||
}
|
||||
}
|
||||
return csBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String readObject(ProtocolRegistration registration) {
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var csBuilder = new StringBuilder();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
var readObject = cppSerializer(fieldRegistration.serializer()).readObject(csBuilder, 3, field, fieldRegistration);
|
||||
csBuilder.append(TAB + TAB + TAB);
|
||||
if (IPacket.class.isAssignableFrom(field.getType())) {
|
||||
csBuilder.append(StringUtils.format("packet->{} = *{};", field.getName(), readObject));
|
||||
} else {
|
||||
csBuilder.append(StringUtils.format("packet->{} = {};", field.getName(), readObject));
|
||||
}
|
||||
|
||||
csBuilder.append(LS);
|
||||
}
|
||||
return csBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String toCppClassName(String typeName) {
|
||||
typeName = typeName.replaceAll("java.util.|java.lang.", StringUtils.EMPTY);
|
||||
typeName = typeName.replaceAll("com\\.[a-zA-Z0-9_.]*\\.", StringUtils.EMPTY);
|
||||
|
||||
// CSharp不适用基础类型的泛型,会影响性能
|
||||
switch (typeName) {
|
||||
case "boolean":
|
||||
case "Boolean":
|
||||
typeName = "bool";
|
||||
return typeName;
|
||||
case "byte":
|
||||
case "Byte":
|
||||
typeName = "int8_t";
|
||||
return typeName;
|
||||
case "short":
|
||||
case "Short":
|
||||
typeName = "int16_t";
|
||||
return typeName;
|
||||
case "int":
|
||||
case "Integer":
|
||||
typeName = "int32_t";
|
||||
return typeName;
|
||||
case "long":
|
||||
case "Long":
|
||||
typeName = "int64_t";
|
||||
return typeName;
|
||||
case "Float":
|
||||
typeName = "float";
|
||||
return typeName;
|
||||
case "Double":
|
||||
typeName = "double";
|
||||
return typeName;
|
||||
case "Character":
|
||||
typeName = "char";
|
||||
return typeName;
|
||||
case "String":
|
||||
typeName = "string";
|
||||
return typeName;
|
||||
default:
|
||||
}
|
||||
|
||||
// 将boolean转为bool
|
||||
typeName = typeName.replaceAll("[B|b]oolean\\[", "bool");
|
||||
typeName = typeName.replace("<Boolean", "<bool");
|
||||
typeName = typeName.replace("Boolean>", "bool>");
|
||||
|
||||
// 将Byte转为byte
|
||||
typeName = typeName.replace("Byte[", "int8_t");
|
||||
typeName = typeName.replace("Byte>", "int8_t>");
|
||||
typeName = typeName.replace("<Byte", "<int8_t");
|
||||
|
||||
// 将Short转为short
|
||||
typeName = typeName.replace("Short[", "int16_t");
|
||||
typeName = typeName.replace("Short>", "int16_t>");
|
||||
typeName = typeName.replace("<Short", "<int16_t");
|
||||
|
||||
// 将Integer转为int
|
||||
typeName = typeName.replace("Integer[", "int32_t");
|
||||
typeName = typeName.replace("Integer>", "int32_t>");
|
||||
typeName = typeName.replace("<Integer", "<int32_t");
|
||||
|
||||
|
||||
// 将Long转为long
|
||||
typeName = typeName.replace("Long[", "int64_t");
|
||||
typeName = typeName.replace("Long>", "int64_t>");
|
||||
typeName = typeName.replace("<Long", "<int64_t");
|
||||
|
||||
// 将Float转为float
|
||||
typeName = typeName.replace("Float[", "float");
|
||||
typeName = typeName.replace("Float>", "float>");
|
||||
typeName = typeName.replace("<Float", "<float");
|
||||
|
||||
// 将Double转为double
|
||||
typeName = typeName.replace("Double[", "double");
|
||||
typeName = typeName.replace("Double>", "double>");
|
||||
typeName = typeName.replace("<Double", "<double");
|
||||
|
||||
// 将Character转为Char
|
||||
typeName = typeName.replace("Character[", "char");
|
||||
typeName = typeName.replace("Character>", "char>");
|
||||
typeName = typeName.replace("<Character", "<char");
|
||||
|
||||
// 将String转为string
|
||||
typeName = typeName.replace("String[", "string");
|
||||
typeName = typeName.replace("String>", "string>");
|
||||
typeName = typeName.replace("<String", "<string");
|
||||
|
||||
// 将Map转为map
|
||||
typeName = typeName.replace("Map<", "map<");
|
||||
|
||||
// 将Set转为set
|
||||
typeName = typeName.replace("Set<", "set<");
|
||||
|
||||
// 将List转为vector
|
||||
typeName = typeName.replace("List<", "list<");
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.cpp;
|
||||
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public interface ICppSerializer {
|
||||
|
||||
/**
|
||||
* 获取属性的类型和名称
|
||||
*/
|
||||
Pair<String, String> field(Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
#ifndef ZFOO_{}_H
|
||||
#define ZFOO_{}_H
|
||||
|
||||
#include "zfoocpp/ByteBuffer.h"
|
||||
{}
|
||||
namespace zfoo {
|
||||
|
||||
{}
|
||||
class {} : public IPacket {
|
||||
public:
|
||||
{}
|
||||
|
||||
~{}() override = default;
|
||||
|
||||
static {} valueOf({}) {
|
||||
auto packet = {}();
|
||||
{}
|
||||
return packet;
|
||||
}
|
||||
|
||||
int16_t protocolId() override {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool operator<(const {} &_) const {
|
||||
{}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class {}Registration : public IProtocolRegistration {
|
||||
public:
|
||||
int16_t protocolId() override {
|
||||
return {};
|
||||
}
|
||||
|
||||
void write(ByteBuffer &buffer, IPacket *packet) override {
|
||||
if (buffer.writePacketFlag(packet)) {
|
||||
return;
|
||||
}
|
||||
auto *message = ({} *) packet;
|
||||
{}
|
||||
}
|
||||
|
||||
IPacket *read(ByteBuffer &buffer) override {
|
||||
auto *packet = new {}();
|
||||
if (!buffer.readBool()) {
|
||||
return packet;
|
||||
}
|
||||
{}
|
||||
return packet;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef ZFOO_PROTOCOLMANAGER_H
|
||||
#define ZFOO_PROTOCOLMANAGER_H
|
||||
|
||||
#include "ByteBuffer.h"
|
||||
{}
|
||||
namespace zfoo {
|
||||
|
||||
const int16_t MAX_PROTOCOL_NUM = 32767;
|
||||
const IProtocolRegistration *protocols[MAX_PROTOCOL_NUM];
|
||||
|
||||
void initProtocol() {
|
||||
{}
|
||||
}
|
||||
|
||||
inline IProtocolRegistration *getProtocol(int16_t protocolId) {
|
||||
return const_cast<IProtocolRegistration *>(protocols[protocolId]);
|
||||
}
|
||||
|
||||
void write(ByteBuffer &buffer, IPacket *packet) {
|
||||
auto protocolId = packet->protocolId();
|
||||
// 写入协议号
|
||||
buffer.writeShort(protocolId);
|
||||
// 写入包体
|
||||
getProtocol(protocolId)->write(buffer, packet);
|
||||
}
|
||||
|
||||
IPacket *read(ByteBuffer &buffer) {
|
||||
auto protocolId = buffer.readShort();
|
||||
return getProtocol(protocolId)->read(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user