mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-08 20:20:40 +00:00
perf[protocol]: 使用模板生成协议
This commit is contained in:
@@ -19,7 +19,7 @@ import com.zfoo.protocol.registration.ProtocolRegistration;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.cpp.GenerateCppUtils;
|
||||
import com.zfoo.protocol.serializer.csharp.GenerateCsUtils;
|
||||
import com.zfoo.protocol.serializer.gd.GenerateGdUtils;
|
||||
import com.zfoo.protocol.serializer.gdscript.GenerateGdUtils;
|
||||
import com.zfoo.protocol.serializer.javascript.GenerateJsUtils;
|
||||
import com.zfoo.protocol.serializer.lua.GenerateLuaUtils;
|
||||
import com.zfoo.protocol.serializer.protobuf.GenerateProtobufUtils;
|
||||
@@ -137,7 +137,9 @@ public abstract class GenerateProtocolFile {
|
||||
if (generateLanguages.contains(CodeLanguage.GdScript)) {
|
||||
GenerateGdUtils.init(generateOperation);
|
||||
GenerateGdUtils.createProtocolManager(allSortedGenerateProtocols);
|
||||
allSortedGenerateProtocols.forEach(it -> GenerateGdUtils.createGdProtocolFile((ProtocolRegistration) it));
|
||||
for (var protocolRegistration : allSortedGenerateProtocols) {
|
||||
GenerateGdUtils.createGdProtocolFile((ProtocolRegistration) protocolRegistration);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成Protobuf协议
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.zfoo.protocol.generate.GenerateProtocolPath;
|
||||
import com.zfoo.protocol.registration.field.*;
|
||||
import com.zfoo.protocol.serializer.cpp.GenerateCppUtils;
|
||||
import com.zfoo.protocol.serializer.csharp.GenerateCsUtils;
|
||||
import com.zfoo.protocol.serializer.gd.GenerateGdUtils;
|
||||
import com.zfoo.protocol.serializer.gdscript.GenerateGdUtils;
|
||||
import com.zfoo.protocol.serializer.javascript.GenerateJsUtils;
|
||||
import com.zfoo.protocol.serializer.lua.GenerateLuaUtils;
|
||||
import com.zfoo.protocol.serializer.protobuf.GenerateProtobufUtils;
|
||||
|
||||
+11
-11
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.ArrayField;
|
||||
@@ -33,7 +33,7 @@ public class GdArraySerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
if (CutDownArraySerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.GdScript)) {
|
||||
return;
|
||||
}
|
||||
@@ -41,16 +41,16 @@ public class GdArraySerializer implements IGdSerializer {
|
||||
ArrayField arrayField = (ArrayField) fieldRegistration;
|
||||
|
||||
builder.append(StringUtils.format("if ({} == null):", objectStr)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append("buffer.writeInt(0)").append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
|
||||
builder.append("else:").append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size())", objectStr)).append(LS);
|
||||
|
||||
String element = "element" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in {}:", element, objectStr)).append(LS);
|
||||
GenerateGdUtils.gdSerializer(arrayField.getArrayElementRegistration().serializer())
|
||||
.writeObject(builder, element, deep + 2, field, arrayField.getArrayElementRegistration());
|
||||
@@ -58,7 +58,7 @@ public class GdArraySerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
var cutDown = CutDownArraySerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.GdScript);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
@@ -72,16 +72,16 @@ public class GdArraySerializer implements IGdSerializer {
|
||||
String i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
String size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readInt()", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("if ({} > 0):", size)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in range({}):", i, size)).append(LS);
|
||||
String readObject = GenerateGdUtils.gdSerializer(arrayField.getArrayElementRegistration().serializer())
|
||||
.readObject(builder, deep + 2, field, arrayField.getArrayElementRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep + 2);
|
||||
GenerateGdUtils.addTab(builder, deep + 2);
|
||||
builder.append(StringUtils.format("{}.append({})", result, readObject)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -30,7 +30,7 @@ public class GdBooleanSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeBool({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GdBooleanSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readBool() ", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -30,7 +30,7 @@ public class GdByteSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeByte({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GdByteSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readByte()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -29,14 +29,14 @@ public class GdCharSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.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);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readChar()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -30,7 +30,7 @@ public class GdDoubleSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeDouble({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GdDoubleSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readDouble()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -30,7 +30,7 @@ public class GdFloatSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeFloat({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GdFloatSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readFloat()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -29,7 +29,7 @@ public class GdIntSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeInt({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GdIntSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readInt()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+11
-11
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -32,7 +32,7 @@ public class GdListSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
if (CutDownListSerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.GdScript)) {
|
||||
return;
|
||||
}
|
||||
@@ -40,16 +40,16 @@ public class GdListSerializer implements IGdSerializer {
|
||||
ListField listField = (ListField) fieldRegistration;
|
||||
|
||||
builder.append(StringUtils.format("if ({} == null):", objectStr)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append("buffer.writeInt(0)").append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
|
||||
builder.append("else:").append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size())", objectStr)).append(LS);
|
||||
|
||||
String element = "element" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in {}:", element, objectStr)).append(LS);
|
||||
GenerateGdUtils.gdSerializer(listField.getListElementRegistration().serializer())
|
||||
.writeObject(builder, element, deep + 2, field, listField.getListElementRegistration());
|
||||
@@ -57,7 +57,7 @@ public class GdListSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
var cutDown = CutDownListSerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.GdScript);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
@@ -71,16 +71,16 @@ public class GdListSerializer implements IGdSerializer {
|
||||
String i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
String size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readInt()", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("if ({} > 0):", size)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in range({}):", i, size)).append(LS);
|
||||
String readObject = GenerateGdUtils.gdSerializer(listField.getListElementRegistration().serializer())
|
||||
.readObject(builder, deep + 2, field, listField.getListElementRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep + 2);
|
||||
GenerateGdUtils.addTab(builder, deep + 2);
|
||||
builder.append(StringUtils.format("{}.append({})", result, readObject)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -29,7 +29,7 @@ public class GdLongSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeLong({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GdLongSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readLong()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+12
-12
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -32,28 +32,28 @@ public class GdMapSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
if (CutDownMapSerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.GdScript)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MapField mapField = (MapField) fieldRegistration;
|
||||
builder.append(StringUtils.format("if ({} == null):", objectStr)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append("buffer.writeInt(0)").append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append("else:").append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size())", objectStr)).append(LS);
|
||||
|
||||
String key = "key" + GenerateProtocolFile.index.getAndIncrement();
|
||||
String value = "value" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in {}:", key, objectStr)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 2);
|
||||
GenerateGdUtils.addTab(builder, deep + 2);
|
||||
builder.append(StringUtils.format("var {} = {}[{}]", value, objectStr, key)).append(LS);
|
||||
GenerateGdUtils.gdSerializer(mapField.getMapKeyRegistration().serializer())
|
||||
.writeObject(builder, key, deep + 2, field, mapField.getMapKeyRegistration());
|
||||
@@ -63,7 +63,7 @@ public class GdMapSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
var cutDown = CutDownMapSerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.GdScript);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
@@ -74,15 +74,15 @@ public class GdMapSerializer implements IGdSerializer {
|
||||
|
||||
builder.append(StringUtils.format("var {} = {}", result)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
String size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
builder.append(StringUtils.format("var {} = buffer.readInt()", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("if ({} > 0):", size)).append(LS);
|
||||
|
||||
String i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in range({}):", i, size)).append(LS);
|
||||
|
||||
String keyObject = GenerateGdUtils.gdSerializer(mapField.getMapKeyRegistration().serializer())
|
||||
@@ -91,7 +91,7 @@ public class GdMapSerializer implements IGdSerializer {
|
||||
|
||||
String valueObject = GenerateGdUtils.gdSerializer(mapField.getMapValueRegistration().serializer())
|
||||
.readObject(builder, deep + 2, field, mapField.getMapValueRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep + 2);
|
||||
GenerateGdUtils.addTab(builder, deep + 2);
|
||||
|
||||
builder.append(StringUtils.format("{}[{}] = {}", result, keyObject, valueObject)).append(LS);
|
||||
return result;
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -31,7 +31,7 @@ public class GdObjectProtocolSerializer implements IGdSerializer {
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writePacket({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class GdObjectProtocolSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
var result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readPacket({})", result, objectProtocolField.getProtocolId())).append(LS);
|
||||
return result;
|
||||
}
|
||||
+11
-11
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -32,7 +32,7 @@ public class GdSetSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
if (CutDownSetSerializer.getInstance().writeObject(builder, objectStr, field, fieldRegistration, CodeLanguage.GdScript)) {
|
||||
return;
|
||||
}
|
||||
@@ -40,16 +40,16 @@ public class GdSetSerializer implements IGdSerializer {
|
||||
SetField setField = (SetField) fieldRegistration;
|
||||
|
||||
builder.append(StringUtils.format("if ({} == null):", objectStr)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append("buffer.writeInt(0)").append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
|
||||
builder.append("else:").append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("buffer.writeInt({}.size())", objectStr)).append(LS);
|
||||
|
||||
String element = "element" + GenerateProtocolFile.index.getAndIncrement();
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in {}:", element, objectStr)).append(LS);
|
||||
GenerateGdUtils.gdSerializer(setField.getSetElementRegistration().serializer())
|
||||
.writeObject(builder, element, deep + 2, field, setField.getSetElementRegistration());
|
||||
@@ -57,7 +57,7 @@ public class GdSetSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
var cutDown = CutDownSetSerializer.getInstance().readObject(builder, field, fieldRegistration, CodeLanguage.GdScript);
|
||||
if (cutDown != null) {
|
||||
return cutDown;
|
||||
@@ -71,16 +71,16 @@ public class GdSetSerializer implements IGdSerializer {
|
||||
String i = "index" + GenerateProtocolFile.index.getAndIncrement();
|
||||
String size = "size" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readInt()", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("if ({} > 0):", size)).append(LS);
|
||||
GenerateProtocolFile.addTab(builder, deep + 1);
|
||||
GenerateGdUtils.addTab(builder, deep + 1);
|
||||
builder.append(StringUtils.format("for {} in range({}):", i, size)).append(LS);
|
||||
String readObject = GenerateGdUtils.gdSerializer(setField.getSetElementRegistration().serializer())
|
||||
.readObject(builder, deep + 2, field, setField.getSetElementRegistration());
|
||||
GenerateProtocolFile.addTab(builder, deep + 2);
|
||||
GenerateGdUtils.addTab(builder, deep + 2);
|
||||
builder.append(StringUtils.format("{}.append({})", result, readObject)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -30,7 +30,7 @@ public class GdShortSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeShort({})", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GdShortSerializer implements IGdSerializer {
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readShort()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
@@ -29,14 +29,14 @@ public class GdStringSerializer implements IGdSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
GenerateGdUtils.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);
|
||||
GenerateGdUtils.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("var {} = buffer.readString()", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
+52
-103
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.generate.GenerateOperation;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolDocument;
|
||||
@@ -19,7 +19,6 @@ import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolPath;
|
||||
import com.zfoo.protocol.registration.IProtocolRegistration;
|
||||
import com.zfoo.protocol.registration.ProtocolRegistration;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
import com.zfoo.protocol.serializer.reflect.*;
|
||||
import com.zfoo.protocol.util.ClassUtils;
|
||||
import com.zfoo.protocol.util.FileUtils;
|
||||
@@ -28,11 +27,13 @@ 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.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
import static com.zfoo.protocol.util.StringUtils.TAB;
|
||||
import static com.zfoo.protocol.util.StringUtils.TAB_ASCII;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
@@ -77,161 +78,109 @@ public abstract class GenerateGdUtils {
|
||||
}
|
||||
|
||||
public static void createProtocolManager(List<IProtocolRegistration> protocolList) throws IOException {
|
||||
var list = List.of("gd/buffer/ByteBuffer.gd");
|
||||
|
||||
var list = List.of("gdscript/buffer/ByteBuffer.gd");
|
||||
for (var fileName : list) {
|
||||
var fileInputStream = ClassUtils.getFileFromClassPath(fileName);
|
||||
var createFile = new File(StringUtils.format("{}/{}", protocolOutputRootPath, StringUtils.substringAfterFirst(fileName, "gd/")));
|
||||
var createFile = new File(StringUtils.format("{}/{}", protocolOutputRootPath, StringUtils.substringAfterFirst(fileName, "gdscript/")));
|
||||
FileUtils.writeInputStreamToFile(createFile, fileInputStream);
|
||||
}
|
||||
|
||||
|
||||
var protocolManagerTemplate = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("gdscript/ProtocolManagerTemplate.gd")));
|
||||
// 生成ProtocolManager.gd文件
|
||||
var gdBuilder = new StringBuilder();
|
||||
|
||||
protocolList.stream()
|
||||
.filter(it -> Objects.nonNull(it))
|
||||
.forEach(it -> {
|
||||
var name = it.protocolConstructor().getDeclaringClass().getSimpleName();
|
||||
var path = GenerateProtocolPath.getProtocolPath(it.protocolId());
|
||||
gdBuilder.append(StringUtils.format("const {} = preload(\"res://gdProtocol/{}/{}.gd\")", name, path, name)).append(LS);
|
||||
});
|
||||
|
||||
|
||||
gdBuilder.append(LS);
|
||||
|
||||
var protocolManagerStr = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("gd/ProtocolManager.gd")));
|
||||
gdBuilder.append(protocolManagerStr);
|
||||
|
||||
gdBuilder.append("static func initProtocol():").append(LS);
|
||||
protocolList.stream()
|
||||
.filter(it -> Objects.nonNull(it))
|
||||
.forEach(it -> gdBuilder.append(TAB).append(StringUtils.format("protocols[{}] = {}", it.protocolId(), it.protocolConstructor().getDeclaringClass().getSimpleName())).append(LS));
|
||||
|
||||
FileUtils.writeStringToFile(new File(StringUtils.format("{}/{}", protocolOutputRootPath, "ProtocolManager.gd")), gdBuilder.toString());
|
||||
var importBuilder = new StringBuilder();
|
||||
var initBuilder = new StringBuilder();
|
||||
for (var protocol : protocolList) {
|
||||
var protocolId = protocol.protocolId();
|
||||
var name = protocol.protocolConstructor().getDeclaringClass().getSimpleName();
|
||||
var path = GenerateProtocolPath.getProtocolPath(protocolId);
|
||||
importBuilder.append(StringUtils.format("const {} = preload(\"res://gdProtocol/{}/{}.gd\")", name, path, name)).append(LS);
|
||||
initBuilder.append(TAB_ASCII).append(StringUtils.format("protocols[{}] = {}", protocolId, name)).append(LS);
|
||||
}
|
||||
protocolManagerTemplate = StringUtils.format(protocolManagerTemplate, importBuilder.toString().trim(), StringUtils.EMPTY_JSON, initBuilder.toString().trim());
|
||||
FileUtils.writeStringToFile(new File(StringUtils.format("{}/{}", protocolOutputRootPath, "ProtocolManager.gd")), protocolManagerTemplate);
|
||||
}
|
||||
|
||||
public static void createGdProtocolFile(ProtocolRegistration registration) {
|
||||
public static void createGdProtocolFile(ProtocolRegistration registration) throws IOException {
|
||||
// 初始化index
|
||||
GenerateProtocolFile.index.set(0);
|
||||
|
||||
var protocolId = registration.protocolId();
|
||||
var registrationConstructor = registration.getConstructor();
|
||||
|
||||
var protocolClazzName = registrationConstructor.getDeclaringClass().getSimpleName();
|
||||
|
||||
var gdBuilder = new StringBuilder();
|
||||
var docTitle = docTitle(registration);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
|
||||
// 协议的属性生成
|
||||
gdBuilder.append(protocolClass(registration));
|
||||
var protocolTemplate = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("gdscript/ProtocolTemplate.gd")));
|
||||
protocolTemplate = StringUtils.format(protocolTemplate, docTitle, fieldDefinition.trim(), protocolId, writeObject.trim(), readObject.trim());
|
||||
|
||||
// protocolId
|
||||
gdBuilder.append(protocolIdField(registration));
|
||||
|
||||
// writeObject method
|
||||
gdBuilder.append(writeObject(registration));
|
||||
|
||||
// readObject method
|
||||
gdBuilder.append(readObject(registration));
|
||||
|
||||
var protocolOutputPath = StringUtils.format("{}/{}/{}.gd"
|
||||
, protocolOutputRootPath
|
||||
, GenerateProtocolPath.getProtocolPath(protocolId)
|
||||
, protocolClazzName);
|
||||
FileUtils.writeStringToFile(new File(protocolOutputPath), gdBuilder.toString());
|
||||
var protocolOutputPath = StringUtils.format("{}/{}/{}.gd", protocolOutputRootPath, GenerateProtocolPath.getProtocolPath(protocolId), protocolClazzName);
|
||||
FileUtils.writeStringToFile(new File(protocolOutputPath), protocolTemplate);
|
||||
}
|
||||
|
||||
private static String protocolClass(ProtocolRegistration registration) {
|
||||
private static String docTitle(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
var protocolClazzName = registration.getConstructor().getDeclaringClass().getSimpleName();
|
||||
|
||||
var protocolDocument = GenerateProtocolDocument.getProtocolDocument(protocolId);
|
||||
var docTitle = protocolDocument.getKey();
|
||||
var docFieldMap = protocolDocument.getValue();
|
||||
|
||||
var gdBuilder = new StringBuilder();
|
||||
|
||||
if (StringUtils.isNotBlank(docTitle)) {
|
||||
gdBuilder.append(gdDocument(docTitle)).append(LS);
|
||||
gdBuilder.append(gdDocument(docTitle));
|
||||
}
|
||||
return gdBuilder.toString();
|
||||
}
|
||||
|
||||
private static String fieldDefinition(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
var protocolDocument = GenerateProtocolDocument.getProtocolDocument(protocolId);
|
||||
var docFieldMap = protocolDocument.getValue();
|
||||
var gdBuilder = new StringBuilder();
|
||||
for (var field : fields) {
|
||||
var propertyName = field.getName();
|
||||
|
||||
// 生成注释
|
||||
var doc = docFieldMap.get(propertyName);
|
||||
if (StringUtils.isNotBlank(doc)) {
|
||||
Arrays.stream(doc.split(LS)).forEach(it -> gdBuilder.append(gdDocument(it)).append(LS));
|
||||
}
|
||||
|
||||
gdBuilder.append(StringUtils.format("var {}", propertyName))
|
||||
.append(" # ").append(field.getGenericType().getTypeName()) // 生成类型的注释
|
||||
.append(LS);
|
||||
// 生成类型的注释
|
||||
gdBuilder.append(StringUtils.format("var {} # ", propertyName)).append(field.getGenericType().getTypeName()).append(LS);
|
||||
}
|
||||
|
||||
gdBuilder.append(LS);
|
||||
return gdBuilder.toString();
|
||||
}
|
||||
|
||||
private static String protocolIdField(ProtocolRegistration registration) {
|
||||
var protocolId = registration.getId();
|
||||
var gdBuilder = new StringBuilder();
|
||||
gdBuilder.append(StringUtils.format("const PROTOCOL_ID = {}", protocolId)).append(LS).append(LS);
|
||||
return gdBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String writeObject(ProtocolRegistration registration) {
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
|
||||
var gdBuilder = new StringBuilder();
|
||||
gdBuilder.append(StringUtils.format("static func write(buffer, packet):")).append(LS);
|
||||
|
||||
gdBuilder.append(TAB).append("if (buffer.writePacketFlag(packet)):").append(LS);
|
||||
gdBuilder.append(TAB + TAB).append("return").append(LS);
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
Field field = fields[i];
|
||||
IFieldRegistration fieldRegistration = fieldRegistrations[i];
|
||||
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
gdSerializer(fieldRegistration.serializer()).writeObject(gdBuilder, "packet." + field.getName(), 1, field, fieldRegistration);
|
||||
}
|
||||
|
||||
gdBuilder.append(LS).append(LS);
|
||||
return gdBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String readObject(ProtocolRegistration registration) {
|
||||
var fields = registration.getFields();
|
||||
var fieldRegistrations = registration.getFieldRegistrations();
|
||||
var protocolClazzName = registration.getConstructor().getDeclaringClass().getSimpleName();
|
||||
|
||||
var jsBuilder = new StringBuilder();
|
||||
jsBuilder.append(StringUtils.format("static func read(buffer):")).append(LS);
|
||||
jsBuilder.append(TAB).append("if (!buffer.readBool()):").append(LS);
|
||||
jsBuilder.append(TAB + TAB).append("return null").append(LS);
|
||||
|
||||
|
||||
jsBuilder.append(TAB).append(StringUtils.format("var packet = buffer.newInstance({})", registration.protocolId())).append(LS);
|
||||
|
||||
|
||||
var gdBuilder = new StringBuilder();
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
|
||||
var readObject = gdSerializer(fieldRegistration.serializer()).readObject(jsBuilder, 1, field, fieldRegistration);
|
||||
jsBuilder.append(TAB).append(StringUtils.format("packet.{} = {}", field.getName(), readObject)).append(LS);
|
||||
var readObject = gdSerializer(fieldRegistration.serializer()).readObject(gdBuilder, 1, field, fieldRegistration);
|
||||
gdBuilder.append(TAB_ASCII).append(StringUtils.format("packet.{} = {}", field.getName(), readObject)).append(LS);
|
||||
}
|
||||
|
||||
jsBuilder.append(TAB).append("return packet").append(LS);
|
||||
return jsBuilder.toString();
|
||||
return gdBuilder.toString();
|
||||
}
|
||||
|
||||
private static String gdDocument(String doc) {
|
||||
return doc.replaceAll("//", "#");
|
||||
}
|
||||
|
||||
public static StringBuilder addTab(StringBuilder builder, int deep) {
|
||||
builder.append(TAB_ASCII.repeat(Math.max(0, deep)));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.serializer.gd;
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
|
||||
@@ -104,7 +104,7 @@ public abstract class GenerateLuaUtils {
|
||||
|
||||
protocolBuilder.append(TAB).append(StringUtils.format("protocols[{}] = {}", protocolId, name)).append(LS);
|
||||
}
|
||||
protocolManagerTemplate = StringUtils.format(protocolManagerTemplate, "{}", "{}", fieldBuilder.toString().trim(), protocolBuilder.toString().trim());
|
||||
protocolManagerTemplate = StringUtils.format(protocolManagerTemplate, StringUtils.EMPTY_JSON, StringUtils.EMPTY_JSON, fieldBuilder.toString().trim(), protocolBuilder.toString().trim());
|
||||
FileUtils.writeStringToFile(new File(StringUtils.format("{}/{}", protocolOutputRootPath, "ProtocolManager.lua")), protocolManagerTemplate);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public abstract class GenerateLuaUtils {
|
||||
var writePacket = writePacket(registration);
|
||||
var readPacket = readPacket(registration);
|
||||
|
||||
protocolTemplate = StringUtils.format(protocolTemplate, docTitle, protocolClazzName, "{}", protocolClazzName
|
||||
protocolTemplate = StringUtils.format(protocolTemplate, docTitle, protocolClazzName, StringUtils.EMPTY_JSON, protocolClazzName
|
||||
, valueOfMethod.getKey().trim(), valueOfMethod.getValue().trim(), protocolClazzName, protocolId
|
||||
, protocolClazzName, writePacket.trim(), protocolClazzName, protocolClazzName, readPacket.trim(), protocolClazzName);
|
||||
|
||||
|
||||
+4
@@ -1,3 +1,5 @@
|
||||
{}
|
||||
|
||||
const protocols = {}
|
||||
|
||||
static func getProtocol(protocolId: int):
|
||||
@@ -19,3 +21,5 @@ static func read(buffer):
|
||||
var packet = protocol.read(buffer);
|
||||
return packet;
|
||||
|
||||
static func initProtocol():
|
||||
{}
|
||||
@@ -0,0 +1,18 @@
|
||||
{}
|
||||
|
||||
{}
|
||||
|
||||
const PROTOCOL_ID = {}
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
{}
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
{}
|
||||
return packet
|
||||
+22
-22
@@ -259,7 +259,7 @@ func newInstance(protocolId: int):
|
||||
return ProtocolManager.newInstance(protocolId)
|
||||
|
||||
func writeBooleanArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -275,7 +275,7 @@ func readBooleanArray():
|
||||
return array
|
||||
|
||||
func writeByteArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -291,7 +291,7 @@ func readByteArray():
|
||||
return array
|
||||
|
||||
func writeShortArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -307,7 +307,7 @@ func readShortArray():
|
||||
return array
|
||||
|
||||
func writeIntArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -323,7 +323,7 @@ func readIntArray():
|
||||
return array
|
||||
|
||||
func writeLongArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -339,7 +339,7 @@ func readLongArray():
|
||||
return array
|
||||
|
||||
func writeFloatArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -355,7 +355,7 @@ func readFloatArray():
|
||||
return array
|
||||
|
||||
func writeDoubleArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -371,7 +371,7 @@ func readDoubleArray():
|
||||
return array
|
||||
|
||||
func writeCharArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -387,7 +387,7 @@ func readCharArray():
|
||||
return array
|
||||
|
||||
func writeStringArray(array):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(array.size());
|
||||
@@ -404,7 +404,7 @@ func readStringArray():
|
||||
|
||||
|
||||
func writePacketArray(array, protocolId):
|
||||
if (value == null):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
@@ -422,7 +422,7 @@ func readPacketArray(protocolId):
|
||||
return array
|
||||
|
||||
func writeIntIntMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -441,7 +441,7 @@ func readIntIntMap():
|
||||
return map
|
||||
|
||||
func writeIntLongMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -460,7 +460,7 @@ func readIntLongMap():
|
||||
return map
|
||||
|
||||
func writeIntStringMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -480,7 +480,7 @@ func readIntStringMap():
|
||||
|
||||
|
||||
func writeIntPacketMap(map, protocolId):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
@@ -502,7 +502,7 @@ func readIntPacketMap(protocolId):
|
||||
|
||||
|
||||
func writeLongIntMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -521,7 +521,7 @@ func readLongIntMap():
|
||||
return map
|
||||
|
||||
func writeLongLongMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -540,7 +540,7 @@ func readLongLongMap():
|
||||
return map
|
||||
|
||||
func writeLongStringMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -560,7 +560,7 @@ func readLongStringMap():
|
||||
|
||||
|
||||
func writeLongPacketMap(map, protocolId):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
@@ -582,7 +582,7 @@ func readLongPacketMap(protocolId):
|
||||
|
||||
|
||||
func writeStringIntMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -601,7 +601,7 @@ func readStringIntMap():
|
||||
return map
|
||||
|
||||
func writeStringLongMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -620,7 +620,7 @@ func readStringLongMap():
|
||||
return map
|
||||
|
||||
func writeStringStringMap(map):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(map.size())
|
||||
@@ -640,7 +640,7 @@ func readStringStringMap():
|
||||
|
||||
|
||||
func writeStringPacketMap(map, protocolId):
|
||||
if (value == null):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
+1
@@ -92,6 +92,7 @@ func test():
|
||||
|
||||
var newByteBuffer = ByteBuffer.new()
|
||||
ProtocolManager.write(newByteBuffer, packet);
|
||||
print(newByteBuffer.getWriteOffset())
|
||||
|
||||
var newPacket = ProtocolManager.read(newByteBuffer);
|
||||
print(newPacket)
|
||||
+5
-5
@@ -26,8 +26,8 @@ static func read(buffer):
|
||||
return packet;
|
||||
|
||||
static func initProtocol():
|
||||
protocols[100] = ComplexObject
|
||||
protocols[101] = NormalObject
|
||||
protocols[102] = ObjectA
|
||||
protocols[103] = ObjectB
|
||||
protocols[104] = SimpleObject
|
||||
protocols[100] = ComplexObject
|
||||
protocols[101] = NormalObject
|
||||
protocols[102] = ObjectA
|
||||
protocols[103] = ObjectB
|
||||
protocols[104] = SimpleObject
|
||||
+101
-101
@@ -258,12 +258,12 @@ func readPacket(protocolId):
|
||||
func newInstance(protocolId: int):
|
||||
return ProtocolManager.newInstance(protocolId)
|
||||
|
||||
func writeBooleanArray(value):
|
||||
if (value == null):
|
||||
func writeBooleanArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeBool(element)
|
||||
|
||||
func readBooleanArray():
|
||||
@@ -274,12 +274,12 @@ func readBooleanArray():
|
||||
array.append(readBool())
|
||||
return array
|
||||
|
||||
func writeByteArray(value):
|
||||
if (value == null):
|
||||
func writeByteArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeByte(element)
|
||||
|
||||
func readByteArray():
|
||||
@@ -290,12 +290,12 @@ func readByteArray():
|
||||
array.append(readByte())
|
||||
return array
|
||||
|
||||
func writeShortArray(value):
|
||||
if (value == null):
|
||||
func writeShortArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeShort(element)
|
||||
|
||||
func readShortArray():
|
||||
@@ -306,12 +306,12 @@ func readShortArray():
|
||||
array.append(readShort())
|
||||
return array
|
||||
|
||||
func writeIntArray(value):
|
||||
if (value == null):
|
||||
func writeIntArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeInt(element)
|
||||
|
||||
func readIntArray():
|
||||
@@ -322,12 +322,12 @@ func readIntArray():
|
||||
array.append(readInt())
|
||||
return array
|
||||
|
||||
func writeLongArray(value):
|
||||
if (value == null):
|
||||
func writeLongArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeLong(element)
|
||||
|
||||
func readLongArray():
|
||||
@@ -338,12 +338,12 @@ func readLongArray():
|
||||
array.append(readLong())
|
||||
return array
|
||||
|
||||
func writeFloatArray(value):
|
||||
if (value == null):
|
||||
func writeFloatArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeFloat(element)
|
||||
|
||||
func readFloatArray():
|
||||
@@ -354,12 +354,12 @@ func readFloatArray():
|
||||
array.append(readFloat())
|
||||
return array
|
||||
|
||||
func writeDoubleArray(value):
|
||||
if (value == null):
|
||||
func writeDoubleArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeDouble(element)
|
||||
|
||||
func readDoubleArray():
|
||||
@@ -370,12 +370,12 @@ func readDoubleArray():
|
||||
array.append(readDouble())
|
||||
return array
|
||||
|
||||
func writeCharArray(value):
|
||||
if (value == null):
|
||||
func writeCharArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeChar(element)
|
||||
|
||||
func readCharArray():
|
||||
@@ -386,12 +386,12 @@ func readCharArray():
|
||||
array.append(readChar())
|
||||
return array
|
||||
|
||||
func writeStringArray(value):
|
||||
if (value == null):
|
||||
func writeStringArray(array):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
writeString(element)
|
||||
|
||||
func readStringArray():
|
||||
@@ -403,13 +403,13 @@ func readStringArray():
|
||||
return array
|
||||
|
||||
|
||||
func writePacketArray(value, protocolId):
|
||||
if (value == null):
|
||||
func writePacketArray(array, protocolId):
|
||||
if (array == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
writeInt(value.size());
|
||||
for element in value:
|
||||
writeInt(array.size());
|
||||
for element in array:
|
||||
protocolRegistration.write(self, element)
|
||||
|
||||
func readPacketArray(protocolId):
|
||||
@@ -421,14 +421,14 @@ func readPacketArray(protocolId):
|
||||
array.append(protocolRegistration.read(self))
|
||||
return array
|
||||
|
||||
func writeIntIntMap(value):
|
||||
if (value == null):
|
||||
func writeIntIntMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeInt(key)
|
||||
writeInt(value[key])
|
||||
writeInt(map[key])
|
||||
|
||||
func readIntIntMap():
|
||||
var map = {}
|
||||
@@ -440,14 +440,14 @@ func readIntIntMap():
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
func writeIntLongMap(value):
|
||||
if (value == null):
|
||||
func writeIntLongMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(key)
|
||||
writeLong(value[key])
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeInt(map)
|
||||
writeLong(map[key])
|
||||
|
||||
func readIntLongMap():
|
||||
var map = {}
|
||||
@@ -459,14 +459,14 @@ func readIntLongMap():
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
func writeIntStringMap(value):
|
||||
if (value == null):
|
||||
func writeIntStringMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeInt(key)
|
||||
writeString(value[key])
|
||||
writeString(map[key])
|
||||
|
||||
func readIntStringMap():
|
||||
var map = {}
|
||||
@@ -479,15 +479,15 @@ func readIntStringMap():
|
||||
return map
|
||||
|
||||
|
||||
func writeIntPacketMap(value, protocolId):
|
||||
if (value == null):
|
||||
func writeIntPacketMap(map, protocolId):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeInt(key)
|
||||
protocolRegistration.write(self, value[key])
|
||||
protocolRegistration.write(self, map[key])
|
||||
|
||||
func readIntPacketMap(protocolId):
|
||||
var map = {}
|
||||
@@ -501,14 +501,14 @@ func readIntPacketMap(protocolId):
|
||||
return map
|
||||
|
||||
|
||||
func writeLongIntMap(value):
|
||||
if (value == null):
|
||||
func writeLongIntMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeLong(key)
|
||||
writeInt(value[key])
|
||||
writeInt(map[key])
|
||||
|
||||
func readLongIntMap():
|
||||
var map = {}
|
||||
@@ -520,14 +520,14 @@ func readLongIntMap():
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
func writeLongLongMap(value):
|
||||
if (value == null):
|
||||
func writeLongLongMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeLong(key)
|
||||
writeLong(value[key])
|
||||
writeLong(map[key])
|
||||
|
||||
func readLongLongMap():
|
||||
var map = {}
|
||||
@@ -539,14 +539,14 @@ func readLongLongMap():
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
func writeLongStringMap(value):
|
||||
if (value == null):
|
||||
func writeLongStringMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeLong(key)
|
||||
writeString(value[key])
|
||||
writeString(map[key])
|
||||
|
||||
func readLongStringMap():
|
||||
var map = {}
|
||||
@@ -559,15 +559,15 @@ func readLongStringMap():
|
||||
return map
|
||||
|
||||
|
||||
func writeLongPacketMap(value, protocolId):
|
||||
if (value == null):
|
||||
func writeLongPacketMap(map, protocolId):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeLong(key)
|
||||
protocolRegistration.write(self, value[key])
|
||||
protocolRegistration.write(self, map[key])
|
||||
|
||||
func readLongPacketMap(protocolId):
|
||||
var map = {}
|
||||
@@ -581,14 +581,14 @@ func readLongPacketMap(protocolId):
|
||||
return map
|
||||
|
||||
|
||||
func writeStringIntMap(value):
|
||||
if (value == null):
|
||||
func writeStringIntMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeString(key)
|
||||
writeInt(value[key])
|
||||
writeInt(map[key])
|
||||
|
||||
func readStringIntMap():
|
||||
var map = {}
|
||||
@@ -600,14 +600,14 @@ func readStringIntMap():
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
func writeStringLongMap(value):
|
||||
if (value == null):
|
||||
func writeStringLongMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeString(key)
|
||||
writeLong(value[key])
|
||||
writeLong(map[key])
|
||||
|
||||
func readStringLongMap():
|
||||
var map = {}
|
||||
@@ -619,14 +619,14 @@ func readStringLongMap():
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
func writeStringStringMap(value):
|
||||
if (value == null):
|
||||
func writeStringStringMap(map):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeString(key)
|
||||
writeString(value[key])
|
||||
writeString(map[key])
|
||||
|
||||
func readStringStringMap():
|
||||
var map = {}
|
||||
@@ -639,15 +639,15 @@ func readStringStringMap():
|
||||
return map
|
||||
|
||||
|
||||
func writeStringPacketMap(value, protocolId):
|
||||
if (value == null):
|
||||
func writeStringPacketMap(map, protocolId):
|
||||
if (map == null):
|
||||
writeInt(0)
|
||||
else:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
writeInt(value.size())
|
||||
for key in value:
|
||||
writeInt(map.size())
|
||||
for key in map:
|
||||
writeString(key)
|
||||
protocolRegistration.write(self, value[key])
|
||||
protocolRegistration.write(self, map[key])
|
||||
|
||||
func readStringPacketMap(protocolId):
|
||||
var map = {}
|
||||
@@ -0,0 +1,396 @@
|
||||
# 复杂的对象
|
||||
# 包括了各种复杂的结构,数组,List,Set,Map
|
||||
#
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
|
||||
# byte类型,最简单的整形
|
||||
var a # byte
|
||||
# byte的包装类型
|
||||
# 优先使用基础类型,包装类型会有装箱拆箱
|
||||
var aa # java.lang.Byte
|
||||
# 数组类型
|
||||
var aaa # byte[]
|
||||
var aaaa # java.lang.Byte[]
|
||||
var b # short
|
||||
var bb # java.lang.Short
|
||||
var bbb # short[]
|
||||
var bbbb # java.lang.Short[]
|
||||
var c # int
|
||||
var cc # java.lang.Integer
|
||||
var ccc # int[]
|
||||
var cccc # java.lang.Integer[]
|
||||
var d # long
|
||||
var dd # java.lang.Long
|
||||
var ddd # long[]
|
||||
var dddd # java.lang.Long[]
|
||||
var e # float
|
||||
var ee # java.lang.Float
|
||||
var eee # float[]
|
||||
var eeee # java.lang.Float[]
|
||||
var f # double
|
||||
var ff # java.lang.Double
|
||||
var fff # double[]
|
||||
var ffff # java.lang.Double[]
|
||||
var g # boolean
|
||||
var gg # java.lang.Boolean
|
||||
var ggg # boolean[]
|
||||
var gggg # java.lang.Boolean[]
|
||||
var h # char
|
||||
var hh # java.lang.Character
|
||||
var hhh # char[]
|
||||
var hhhh # java.lang.Character[]
|
||||
var jj # java.lang.String
|
||||
var jjj # java.lang.String[]
|
||||
var kk # com.zfoo.protocol.packet.ObjectA
|
||||
var kkk # com.zfoo.protocol.packet.ObjectA[]
|
||||
var l # java.util.List<java.lang.Integer>
|
||||
var ll # java.util.List<java.util.List<java.util.List<java.lang.Integer>>>
|
||||
var lll # java.util.List<java.util.List<com.zfoo.protocol.packet.ObjectA>>
|
||||
var llll # java.util.List<java.lang.String>
|
||||
var lllll # java.util.List<java.util.Map<java.lang.Integer, java.lang.String>>
|
||||
var m # java.util.Map<java.lang.Integer, java.lang.String>
|
||||
var mm # java.util.Map<java.lang.Integer, com.zfoo.protocol.packet.ObjectA>
|
||||
var mmm # java.util.Map<com.zfoo.protocol.packet.ObjectA, java.util.List<java.lang.Integer>>
|
||||
var mmmm # java.util.Map<java.util.List<java.util.List<com.zfoo.protocol.packet.ObjectA>>, java.util.List<java.util.List<java.util.List<java.lang.Integer>>>>
|
||||
var mmmmm # java.util.Map<java.util.List<java.util.Map<java.lang.Integer, java.lang.String>>, java.util.Set<java.util.Map<java.lang.Integer, java.lang.String>>>
|
||||
var s # java.util.Set<java.lang.Integer>
|
||||
var ss # java.util.Set<java.util.Set<java.util.List<java.lang.Integer>>>
|
||||
var sss # java.util.Set<java.util.Set<com.zfoo.protocol.packet.ObjectA>>
|
||||
var ssss # java.util.Set<java.lang.String>
|
||||
var sssss # java.util.Set<java.util.Map<java.lang.Integer, java.lang.String>>
|
||||
|
||||
const PROTOCOL_ID = 100
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeByte(packet.a)
|
||||
buffer.writeByte(packet.aa)
|
||||
buffer.writeByteArray(packet.aaa)
|
||||
buffer.writeByteArray(packet.aaaa)
|
||||
buffer.writeShort(packet.b)
|
||||
buffer.writeShort(packet.bb)
|
||||
buffer.writeShortArray(packet.bbb)
|
||||
buffer.writeShortArray(packet.bbbb)
|
||||
buffer.writeInt(packet.c)
|
||||
buffer.writeInt(packet.cc)
|
||||
buffer.writeIntArray(packet.ccc)
|
||||
buffer.writeIntArray(packet.cccc)
|
||||
buffer.writeLong(packet.d)
|
||||
buffer.writeLong(packet.dd)
|
||||
buffer.writeLongArray(packet.ddd)
|
||||
buffer.writeLongArray(packet.dddd)
|
||||
buffer.writeFloat(packet.e)
|
||||
buffer.writeFloat(packet.ee)
|
||||
buffer.writeFloatArray(packet.eee)
|
||||
buffer.writeFloatArray(packet.eeee)
|
||||
buffer.writeDouble(packet.f)
|
||||
buffer.writeDouble(packet.ff)
|
||||
buffer.writeDoubleArray(packet.fff)
|
||||
buffer.writeDoubleArray(packet.ffff)
|
||||
buffer.writeBool(packet.g)
|
||||
buffer.writeBool(packet.gg)
|
||||
buffer.writeBooleanArray(packet.ggg)
|
||||
buffer.writeBooleanArray(packet.gggg)
|
||||
buffer.writeChar(packet.h)
|
||||
buffer.writeChar(packet.hh)
|
||||
buffer.writeCharArray(packet.hhh)
|
||||
buffer.writeCharArray(packet.hhhh)
|
||||
buffer.writeString(packet.jj)
|
||||
buffer.writeStringArray(packet.jjj)
|
||||
buffer.writePacket(packet.kk, 102)
|
||||
buffer.writePacketArray(packet.kkk, 102)
|
||||
buffer.writeIntArray(packet.l)
|
||||
if (packet.ll == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.ll.size())
|
||||
for element0 in packet.ll:
|
||||
if (element0 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(element0.size())
|
||||
for element1 in element0:
|
||||
buffer.writeIntArray(element1)
|
||||
if (packet.lll == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.lll.size())
|
||||
for element2 in packet.lll:
|
||||
buffer.writePacketArray(element2, 102)
|
||||
buffer.writeStringArray(packet.llll)
|
||||
if (packet.lllll == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.lllll.size())
|
||||
for element3 in packet.lllll:
|
||||
buffer.writeIntStringMap(element3)
|
||||
buffer.writeIntStringMap(packet.m)
|
||||
buffer.writeIntPacketMap(packet.mm, 102)
|
||||
if (packet.mmm == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.mmm.size())
|
||||
for key4 in packet.mmm:
|
||||
var value5 = packet.mmm[key4]
|
||||
buffer.writePacket(key4, 102)
|
||||
buffer.writeIntArray(value5)
|
||||
if (packet.mmmm == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.mmmm.size())
|
||||
for key6 in packet.mmmm:
|
||||
var value7 = packet.mmmm[key6]
|
||||
if (key6 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(key6.size())
|
||||
for element8 in key6:
|
||||
buffer.writePacketArray(element8, 102)
|
||||
if (value7 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(value7.size())
|
||||
for element9 in value7:
|
||||
if (element9 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(element9.size())
|
||||
for element10 in element9:
|
||||
buffer.writeIntArray(element10)
|
||||
if (packet.mmmmm == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.mmmmm.size())
|
||||
for key11 in packet.mmmmm:
|
||||
var value12 = packet.mmmmm[key11]
|
||||
if (key11 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(key11.size())
|
||||
for element13 in key11:
|
||||
buffer.writeIntStringMap(element13)
|
||||
if (value12 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(value12.size())
|
||||
for element14 in value12:
|
||||
buffer.writeIntStringMap(element14)
|
||||
buffer.writeIntArray(packet.s)
|
||||
if (packet.ss == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.ss.size())
|
||||
for element15 in packet.ss:
|
||||
if (element15 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(element15.size())
|
||||
for element16 in element15:
|
||||
buffer.writeIntArray(element16)
|
||||
if (packet.sss == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.sss.size())
|
||||
for element17 in packet.sss:
|
||||
buffer.writePacketArray(element17, 102)
|
||||
buffer.writeStringArray(packet.ssss)
|
||||
if (packet.sssss == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.sssss.size())
|
||||
for element18 in packet.sssss:
|
||||
buffer.writeIntStringMap(element18)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
var result19 = buffer.readByte()
|
||||
packet.a = result19
|
||||
var result20 = buffer.readByte()
|
||||
packet.aa = result20
|
||||
var array21 = buffer.readByteArray()
|
||||
packet.aaa = array21
|
||||
var array22 = buffer.readByteArray()
|
||||
packet.aaaa = array22
|
||||
var result23 = buffer.readShort()
|
||||
packet.b = result23
|
||||
var result24 = buffer.readShort()
|
||||
packet.bb = result24
|
||||
var array25 = buffer.readShortArray()
|
||||
packet.bbb = array25
|
||||
var array26 = buffer.readShortArray()
|
||||
packet.bbbb = array26
|
||||
var result27 = buffer.readInt()
|
||||
packet.c = result27
|
||||
var result28 = buffer.readInt()
|
||||
packet.cc = result28
|
||||
var array29 = buffer.readIntArray()
|
||||
packet.ccc = array29
|
||||
var array30 = buffer.readIntArray()
|
||||
packet.cccc = array30
|
||||
var result31 = buffer.readLong()
|
||||
packet.d = result31
|
||||
var result32 = buffer.readLong()
|
||||
packet.dd = result32
|
||||
var array33 = buffer.readLongArray()
|
||||
packet.ddd = array33
|
||||
var array34 = buffer.readLongArray()
|
||||
packet.dddd = array34
|
||||
var result35 = buffer.readFloat()
|
||||
packet.e = result35
|
||||
var result36 = buffer.readFloat()
|
||||
packet.ee = result36
|
||||
var array37 = buffer.readFloatArray()
|
||||
packet.eee = array37
|
||||
var array38 = buffer.readFloatArray()
|
||||
packet.eeee = array38
|
||||
var result39 = buffer.readDouble()
|
||||
packet.f = result39
|
||||
var result40 = buffer.readDouble()
|
||||
packet.ff = result40
|
||||
var array41 = buffer.readDoubleArray()
|
||||
packet.fff = array41
|
||||
var array42 = buffer.readDoubleArray()
|
||||
packet.ffff = array42
|
||||
var result43 = buffer.readBool()
|
||||
packet.g = result43
|
||||
var result44 = buffer.readBool()
|
||||
packet.gg = result44
|
||||
var array45 = buffer.readBooleanArray()
|
||||
packet.ggg = array45
|
||||
var array46 = buffer.readBooleanArray()
|
||||
packet.gggg = array46
|
||||
var result47 = buffer.readChar()
|
||||
packet.h = result47
|
||||
var result48 = buffer.readChar()
|
||||
packet.hh = result48
|
||||
var array49 = buffer.readCharArray()
|
||||
packet.hhh = array49
|
||||
var array50 = buffer.readCharArray()
|
||||
packet.hhhh = array50
|
||||
var result51 = buffer.readString()
|
||||
packet.jj = result51
|
||||
var array52 = buffer.readStringArray()
|
||||
packet.jjj = array52
|
||||
var result53 = buffer.readPacket(102)
|
||||
packet.kk = result53
|
||||
var array54 = buffer.readPacketArray(102)
|
||||
packet.kkk = array54
|
||||
var list55 = buffer.readIntArray()
|
||||
packet.l = list55
|
||||
var result56 = []
|
||||
var size58 = buffer.readInt()
|
||||
if (size58 > 0):
|
||||
for index57 in range(size58):
|
||||
var result59 = []
|
||||
var size61 = buffer.readInt()
|
||||
if (size61 > 0):
|
||||
for index60 in range(size61):
|
||||
var list62 = buffer.readIntArray()
|
||||
result59.append(list62)
|
||||
result56.append(result59)
|
||||
packet.ll = result56
|
||||
var result63 = []
|
||||
var size65 = buffer.readInt()
|
||||
if (size65 > 0):
|
||||
for index64 in range(size65):
|
||||
var list66 = buffer.readPacketArray(102)
|
||||
result63.append(list66)
|
||||
packet.lll = result63
|
||||
var list67 = buffer.readStringArray()
|
||||
packet.llll = list67
|
||||
var result68 = []
|
||||
var size70 = buffer.readInt()
|
||||
if (size70 > 0):
|
||||
for index69 in range(size70):
|
||||
var map71 = buffer.readIntStringMap()
|
||||
result68.append(map71)
|
||||
packet.lllll = result68
|
||||
var map72 = buffer.readIntStringMap()
|
||||
packet.m = map72
|
||||
var map73 = buffer.readIntPacketMap(102)
|
||||
packet.mm = map73
|
||||
var result74 = {}
|
||||
var size75 = buffer.readInt()
|
||||
if (size75 > 0):
|
||||
for index76 in range(size75):
|
||||
var result77 = buffer.readPacket(102)
|
||||
var list78 = buffer.readIntArray()
|
||||
result74[result77] = list78
|
||||
packet.mmm = result74
|
||||
var result79 = {}
|
||||
var size80 = buffer.readInt()
|
||||
if (size80 > 0):
|
||||
for index81 in range(size80):
|
||||
var result82 = []
|
||||
var size84 = buffer.readInt()
|
||||
if (size84 > 0):
|
||||
for index83 in range(size84):
|
||||
var list85 = buffer.readPacketArray(102)
|
||||
result82.append(list85)
|
||||
var result86 = []
|
||||
var size88 = buffer.readInt()
|
||||
if (size88 > 0):
|
||||
for index87 in range(size88):
|
||||
var result89 = []
|
||||
var size91 = buffer.readInt()
|
||||
if (size91 > 0):
|
||||
for index90 in range(size91):
|
||||
var list92 = buffer.readIntArray()
|
||||
result89.append(list92)
|
||||
result86.append(result89)
|
||||
result79[result82] = result86
|
||||
packet.mmmm = result79
|
||||
var result93 = {}
|
||||
var size94 = buffer.readInt()
|
||||
if (size94 > 0):
|
||||
for index95 in range(size94):
|
||||
var result96 = []
|
||||
var size98 = buffer.readInt()
|
||||
if (size98 > 0):
|
||||
for index97 in range(size98):
|
||||
var map99 = buffer.readIntStringMap()
|
||||
result96.append(map99)
|
||||
var result100 = []
|
||||
var size102 = buffer.readInt()
|
||||
if (size102 > 0):
|
||||
for index101 in range(size102):
|
||||
var map103 = buffer.readIntStringMap()
|
||||
result100.append(map103)
|
||||
result93[result96] = result100
|
||||
packet.mmmmm = result93
|
||||
var set104 = buffer.readIntArray()
|
||||
packet.s = set104
|
||||
var result105 = []
|
||||
var size107 = buffer.readInt()
|
||||
if (size107 > 0):
|
||||
for index106 in range(size107):
|
||||
var result108 = []
|
||||
var size110 = buffer.readInt()
|
||||
if (size110 > 0):
|
||||
for index109 in range(size110):
|
||||
var list111 = buffer.readIntArray()
|
||||
result108.append(list111)
|
||||
result105.append(result108)
|
||||
packet.ss = result105
|
||||
var result112 = []
|
||||
var size114 = buffer.readInt()
|
||||
if (size114 > 0):
|
||||
for index113 in range(size114):
|
||||
var set115 = buffer.readPacketArray(102)
|
||||
result112.append(set115)
|
||||
packet.sss = result112
|
||||
var set116 = buffer.readStringArray()
|
||||
packet.ssss = set116
|
||||
var result117 = []
|
||||
var size119 = buffer.readInt()
|
||||
if (size119 > 0):
|
||||
for index118 in range(size119):
|
||||
var map120 = buffer.readIntStringMap()
|
||||
result117.append(map120)
|
||||
packet.sssss = result117
|
||||
return packet
|
||||
@@ -0,0 +1,88 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
|
||||
var a # byte
|
||||
var aaa # byte[]
|
||||
var b # short
|
||||
var c # int
|
||||
var d # long
|
||||
var e # float
|
||||
var f # double
|
||||
var g # boolean
|
||||
var jj # java.lang.String
|
||||
var kk # com.zfoo.protocol.packet.ObjectA
|
||||
var l # java.util.List<java.lang.Integer>
|
||||
var ll # java.util.List<java.lang.Long>
|
||||
var lll # java.util.List<com.zfoo.protocol.packet.ObjectA>
|
||||
var llll # java.util.List<java.lang.String>
|
||||
var m # java.util.Map<java.lang.Integer, java.lang.String>
|
||||
var mm # java.util.Map<java.lang.Integer, com.zfoo.protocol.packet.ObjectA>
|
||||
var s # java.util.Set<java.lang.Integer>
|
||||
var ssss # java.util.Set<java.lang.String>
|
||||
|
||||
const PROTOCOL_ID = 101
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeByte(packet.a)
|
||||
buffer.writeByteArray(packet.aaa)
|
||||
buffer.writeShort(packet.b)
|
||||
buffer.writeInt(packet.c)
|
||||
buffer.writeLong(packet.d)
|
||||
buffer.writeFloat(packet.e)
|
||||
buffer.writeDouble(packet.f)
|
||||
buffer.writeBool(packet.g)
|
||||
buffer.writeString(packet.jj)
|
||||
buffer.writePacket(packet.kk, 102)
|
||||
buffer.writeIntArray(packet.l)
|
||||
buffer.writeLongArray(packet.ll)
|
||||
buffer.writePacketArray(packet.lll, 102)
|
||||
buffer.writeStringArray(packet.llll)
|
||||
buffer.writeIntStringMap(packet.m)
|
||||
buffer.writeIntPacketMap(packet.mm, 102)
|
||||
buffer.writeIntArray(packet.s)
|
||||
buffer.writeStringArray(packet.ssss)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
var result0 = buffer.readByte()
|
||||
packet.a = result0
|
||||
var array1 = buffer.readByteArray()
|
||||
packet.aaa = array1
|
||||
var result2 = buffer.readShort()
|
||||
packet.b = result2
|
||||
var result3 = buffer.readInt()
|
||||
packet.c = result3
|
||||
var result4 = buffer.readLong()
|
||||
packet.d = result4
|
||||
var result5 = buffer.readFloat()
|
||||
packet.e = result5
|
||||
var result6 = buffer.readDouble()
|
||||
packet.f = result6
|
||||
var result7 = buffer.readBool()
|
||||
packet.g = result7
|
||||
var result8 = buffer.readString()
|
||||
packet.jj = result8
|
||||
var result9 = buffer.readPacket(102)
|
||||
packet.kk = result9
|
||||
var list10 = buffer.readIntArray()
|
||||
packet.l = list10
|
||||
var list11 = buffer.readLongArray()
|
||||
packet.ll = list11
|
||||
var list12 = buffer.readPacketArray(102)
|
||||
packet.lll = list12
|
||||
var list13 = buffer.readStringArray()
|
||||
packet.llll = list13
|
||||
var map14 = buffer.readIntStringMap()
|
||||
packet.m = map14
|
||||
var map15 = buffer.readIntPacketMap(102)
|
||||
packet.mm = map15
|
||||
var set16 = buffer.readIntArray()
|
||||
packet.s = set16
|
||||
var set17 = buffer.readStringArray()
|
||||
packet.ssss = set17
|
||||
return packet
|
||||
@@ -0,0 +1,28 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
|
||||
var a # int
|
||||
var m # java.util.Map<java.lang.Integer, java.lang.String>
|
||||
var objectB # com.zfoo.protocol.packet.ObjectB
|
||||
|
||||
const PROTOCOL_ID = 102
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeInt(packet.a)
|
||||
buffer.writeIntStringMap(packet.m)
|
||||
buffer.writePacket(packet.objectB, 103)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
var result0 = buffer.readInt()
|
||||
packet.a = result0
|
||||
var map1 = buffer.readIntStringMap()
|
||||
packet.m = map1
|
||||
var result2 = buffer.readPacket(103)
|
||||
packet.objectB = result2
|
||||
return packet
|
||||
@@ -0,0 +1,20 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
|
||||
var flag # boolean
|
||||
|
||||
const PROTOCOL_ID = 103
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeBool(packet.flag)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
var result0 = buffer.readBool()
|
||||
packet.flag = result0
|
||||
return packet
|
||||
@@ -0,0 +1,24 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
|
||||
var c # int
|
||||
var g # boolean
|
||||
|
||||
const PROTOCOL_ID = 104
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeInt(packet.c)
|
||||
buffer.writeBool(packet.g)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
var result0 = buffer.readInt()
|
||||
packet.c = result0
|
||||
var result1 = buffer.readBool()
|
||||
packet.g = result1
|
||||
return packet
|
||||
@@ -1,395 +0,0 @@
|
||||
# 复杂的对象
|
||||
# 包括了各种复杂的结构,数组,List,Set,Map
|
||||
#
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
# byte类型,最简单的整形
|
||||
var a # byte
|
||||
# byte的包装类型
|
||||
# 优先使用基础类型,包装类型会有装箱拆箱
|
||||
var aa # java.lang.Byte
|
||||
# 数组类型
|
||||
var aaa # byte[]
|
||||
var aaaa # java.lang.Byte[]
|
||||
var b # short
|
||||
var bb # java.lang.Short
|
||||
var bbb # short[]
|
||||
var bbbb # java.lang.Short[]
|
||||
var c # int
|
||||
var cc # java.lang.Integer
|
||||
var ccc # int[]
|
||||
var cccc # java.lang.Integer[]
|
||||
var d # long
|
||||
var dd # java.lang.Long
|
||||
var ddd # long[]
|
||||
var dddd # java.lang.Long[]
|
||||
var e # float
|
||||
var ee # java.lang.Float
|
||||
var eee # float[]
|
||||
var eeee # java.lang.Float[]
|
||||
var f # double
|
||||
var ff # java.lang.Double
|
||||
var fff # double[]
|
||||
var ffff # java.lang.Double[]
|
||||
var g # boolean
|
||||
var gg # java.lang.Boolean
|
||||
var ggg # boolean[]
|
||||
var gggg # java.lang.Boolean[]
|
||||
var h # char
|
||||
var hh # java.lang.Character
|
||||
var hhh # char[]
|
||||
var hhhh # java.lang.Character[]
|
||||
var jj # java.lang.String
|
||||
var jjj # java.lang.String[]
|
||||
var kk # com.zfoo.protocol.packet.ObjectA
|
||||
var kkk # com.zfoo.protocol.packet.ObjectA[]
|
||||
var l # java.util.List<java.lang.Integer>
|
||||
var ll # java.util.List<java.util.List<java.util.List<java.lang.Integer>>>
|
||||
var lll # java.util.List<java.util.List<com.zfoo.protocol.packet.ObjectA>>
|
||||
var llll # java.util.List<java.lang.String>
|
||||
var lllll # java.util.List<java.util.Map<java.lang.Integer, java.lang.String>>
|
||||
var m # java.util.Map<java.lang.Integer, java.lang.String>
|
||||
var mm # java.util.Map<java.lang.Integer, com.zfoo.protocol.packet.ObjectA>
|
||||
var mmm # java.util.Map<com.zfoo.protocol.packet.ObjectA, java.util.List<java.lang.Integer>>
|
||||
var mmmm # java.util.Map<java.util.List<java.util.List<com.zfoo.protocol.packet.ObjectA>>, java.util.List<java.util.List<java.util.List<java.lang.Integer>>>>
|
||||
var mmmmm # java.util.Map<java.util.List<java.util.Map<java.lang.Integer, java.lang.String>>, java.util.Set<java.util.Map<java.lang.Integer, java.lang.String>>>
|
||||
var s # java.util.Set<java.lang.Integer>
|
||||
var ss # java.util.Set<java.util.Set<java.util.List<java.lang.Integer>>>
|
||||
var sss # java.util.Set<java.util.Set<com.zfoo.protocol.packet.ObjectA>>
|
||||
var ssss # java.util.Set<java.lang.String>
|
||||
var sssss # java.util.Set<java.util.Map<java.lang.Integer, java.lang.String>>
|
||||
|
||||
const PROTOCOL_ID = 100
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeByte(packet.a)
|
||||
buffer.writeByte(packet.aa)
|
||||
buffer.writeByteArray(packet.aaa)
|
||||
buffer.writeByteArray(packet.aaaa)
|
||||
buffer.writeShort(packet.b)
|
||||
buffer.writeShort(packet.bb)
|
||||
buffer.writeShortArray(packet.bbb)
|
||||
buffer.writeShortArray(packet.bbbb)
|
||||
buffer.writeInt(packet.c)
|
||||
buffer.writeInt(packet.cc)
|
||||
buffer.writeIntArray(packet.ccc)
|
||||
buffer.writeIntArray(packet.cccc)
|
||||
buffer.writeLong(packet.d)
|
||||
buffer.writeLong(packet.dd)
|
||||
buffer.writeLongArray(packet.ddd)
|
||||
buffer.writeLongArray(packet.dddd)
|
||||
buffer.writeFloat(packet.e)
|
||||
buffer.writeFloat(packet.ee)
|
||||
buffer.writeFloatArray(packet.eee)
|
||||
buffer.writeFloatArray(packet.eeee)
|
||||
buffer.writeDouble(packet.f)
|
||||
buffer.writeDouble(packet.ff)
|
||||
buffer.writeDoubleArray(packet.fff)
|
||||
buffer.writeDoubleArray(packet.ffff)
|
||||
buffer.writeBool(packet.g)
|
||||
buffer.writeBool(packet.gg)
|
||||
buffer.writeBooleanArray(packet.ggg)
|
||||
buffer.writeBooleanArray(packet.gggg)
|
||||
buffer.writeChar(packet.h)
|
||||
buffer.writeChar(packet.hh)
|
||||
buffer.writeCharArray(packet.hhh)
|
||||
buffer.writeCharArray(packet.hhhh)
|
||||
buffer.writeString(packet.jj)
|
||||
buffer.writeStringArray(packet.jjj)
|
||||
buffer.writePacket(packet.kk, 102)
|
||||
buffer.writePacketArray(packet.kkk, 102)
|
||||
buffer.writeIntArray(packet.l)
|
||||
if (packet.ll == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.ll.size())
|
||||
for element0 in packet.ll:
|
||||
if (element0 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(element0.size())
|
||||
for element1 in element0:
|
||||
buffer.writeIntArray(element1)
|
||||
if (packet.lll == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.lll.size())
|
||||
for element2 in packet.lll:
|
||||
buffer.writePacketArray(element2, 102)
|
||||
buffer.writeStringArray(packet.llll)
|
||||
if (packet.lllll == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.lllll.size())
|
||||
for element3 in packet.lllll:
|
||||
buffer.writeIntStringMap(element3)
|
||||
buffer.writeIntStringMap(packet.m)
|
||||
buffer.writeIntPacketMap(packet.mm, 102)
|
||||
if (packet.mmm == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.mmm.size())
|
||||
for key4 in packet.mmm:
|
||||
var value5 = packet.mmm[key4]
|
||||
buffer.writePacket(key4, 102)
|
||||
buffer.writeIntArray(value5)
|
||||
if (packet.mmmm == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.mmmm.size())
|
||||
for key6 in packet.mmmm:
|
||||
var value7 = packet.mmmm[key6]
|
||||
if (key6 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(key6.size())
|
||||
for element8 in key6:
|
||||
buffer.writePacketArray(element8, 102)
|
||||
if (value7 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(value7.size())
|
||||
for element9 in value7:
|
||||
if (element9 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(element9.size())
|
||||
for element10 in element9:
|
||||
buffer.writeIntArray(element10)
|
||||
if (packet.mmmmm == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.mmmmm.size())
|
||||
for key11 in packet.mmmmm:
|
||||
var value12 = packet.mmmmm[key11]
|
||||
if (key11 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(key11.size())
|
||||
for element13 in key11:
|
||||
buffer.writeIntStringMap(element13)
|
||||
if (value12 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(value12.size())
|
||||
for element14 in value12:
|
||||
buffer.writeIntStringMap(element14)
|
||||
buffer.writeIntArray(packet.s)
|
||||
if (packet.ss == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.ss.size())
|
||||
for element15 in packet.ss:
|
||||
if (element15 == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(element15.size())
|
||||
for element16 in element15:
|
||||
buffer.writeIntArray(element16)
|
||||
if (packet.sss == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.sss.size())
|
||||
for element17 in packet.sss:
|
||||
buffer.writePacketArray(element17, 102)
|
||||
buffer.writeStringArray(packet.ssss)
|
||||
if (packet.sssss == null):
|
||||
buffer.writeInt(0)
|
||||
else:
|
||||
buffer.writeInt(packet.sssss.size())
|
||||
for element18 in packet.sssss:
|
||||
buffer.writeIntStringMap(element18)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(100)
|
||||
var result19 = buffer.readByte()
|
||||
packet.a = result19
|
||||
var result20 = buffer.readByte()
|
||||
packet.aa = result20
|
||||
var array21 = buffer.readByteArray()
|
||||
packet.aaa = array21
|
||||
var array22 = buffer.readByteArray()
|
||||
packet.aaaa = array22
|
||||
var result23 = buffer.readShort()
|
||||
packet.b = result23
|
||||
var result24 = buffer.readShort()
|
||||
packet.bb = result24
|
||||
var array25 = buffer.readShortArray()
|
||||
packet.bbb = array25
|
||||
var array26 = buffer.readShortArray()
|
||||
packet.bbbb = array26
|
||||
var result27 = buffer.readInt()
|
||||
packet.c = result27
|
||||
var result28 = buffer.readInt()
|
||||
packet.cc = result28
|
||||
var array29 = buffer.readIntArray()
|
||||
packet.ccc = array29
|
||||
var array30 = buffer.readIntArray()
|
||||
packet.cccc = array30
|
||||
var result31 = buffer.readLong()
|
||||
packet.d = result31
|
||||
var result32 = buffer.readLong()
|
||||
packet.dd = result32
|
||||
var array33 = buffer.readLongArray()
|
||||
packet.ddd = array33
|
||||
var array34 = buffer.readLongArray()
|
||||
packet.dddd = array34
|
||||
var result35 = buffer.readFloat()
|
||||
packet.e = result35
|
||||
var result36 = buffer.readFloat()
|
||||
packet.ee = result36
|
||||
var array37 = buffer.readFloatArray()
|
||||
packet.eee = array37
|
||||
var array38 = buffer.readFloatArray()
|
||||
packet.eeee = array38
|
||||
var result39 = buffer.readDouble()
|
||||
packet.f = result39
|
||||
var result40 = buffer.readDouble()
|
||||
packet.ff = result40
|
||||
var array41 = buffer.readDoubleArray()
|
||||
packet.fff = array41
|
||||
var array42 = buffer.readDoubleArray()
|
||||
packet.ffff = array42
|
||||
var result43 = buffer.readBool()
|
||||
packet.g = result43
|
||||
var result44 = buffer.readBool()
|
||||
packet.gg = result44
|
||||
var array45 = buffer.readBooleanArray()
|
||||
packet.ggg = array45
|
||||
var array46 = buffer.readBooleanArray()
|
||||
packet.gggg = array46
|
||||
var result47 = buffer.readChar()
|
||||
packet.h = result47
|
||||
var result48 = buffer.readChar()
|
||||
packet.hh = result48
|
||||
var array49 = buffer.readCharArray()
|
||||
packet.hhh = array49
|
||||
var array50 = buffer.readCharArray()
|
||||
packet.hhhh = array50
|
||||
var result51 = buffer.readString()
|
||||
packet.jj = result51
|
||||
var array52 = buffer.readStringArray()
|
||||
packet.jjj = array52
|
||||
var result53 = buffer.readPacket(102)
|
||||
packet.kk = result53
|
||||
var array54 = buffer.readPacketArray(102)
|
||||
packet.kkk = array54
|
||||
var list55 = buffer.readIntArray()
|
||||
packet.l = list55
|
||||
var result56 = []
|
||||
var size58 = buffer.readInt()
|
||||
if (size58 > 0):
|
||||
for index57 in range(size58):
|
||||
var result59 = []
|
||||
var size61 = buffer.readInt()
|
||||
if (size61 > 0):
|
||||
for index60 in range(size61):
|
||||
var list62 = buffer.readIntArray()
|
||||
result59.append(list62)
|
||||
result56.append(result59)
|
||||
packet.ll = result56
|
||||
var result63 = []
|
||||
var size65 = buffer.readInt()
|
||||
if (size65 > 0):
|
||||
for index64 in range(size65):
|
||||
var list66 = buffer.readPacketArray(102)
|
||||
result63.append(list66)
|
||||
packet.lll = result63
|
||||
var list67 = buffer.readStringArray()
|
||||
packet.llll = list67
|
||||
var result68 = []
|
||||
var size70 = buffer.readInt()
|
||||
if (size70 > 0):
|
||||
for index69 in range(size70):
|
||||
var map71 = buffer.readIntStringMap()
|
||||
result68.append(map71)
|
||||
packet.lllll = result68
|
||||
var map72 = buffer.readIntStringMap()
|
||||
packet.m = map72
|
||||
var map73 = buffer.readIntPacketMap(102)
|
||||
packet.mm = map73
|
||||
var result74 = {}
|
||||
var size75 = buffer.readInt()
|
||||
if (size75 > 0):
|
||||
for index76 in range(size75):
|
||||
var result77 = buffer.readPacket(102)
|
||||
var list78 = buffer.readIntArray()
|
||||
result74[result77] = list78
|
||||
packet.mmm = result74
|
||||
var result79 = {}
|
||||
var size80 = buffer.readInt()
|
||||
if (size80 > 0):
|
||||
for index81 in range(size80):
|
||||
var result82 = []
|
||||
var size84 = buffer.readInt()
|
||||
if (size84 > 0):
|
||||
for index83 in range(size84):
|
||||
var list85 = buffer.readPacketArray(102)
|
||||
result82.append(list85)
|
||||
var result86 = []
|
||||
var size88 = buffer.readInt()
|
||||
if (size88 > 0):
|
||||
for index87 in range(size88):
|
||||
var result89 = []
|
||||
var size91 = buffer.readInt()
|
||||
if (size91 > 0):
|
||||
for index90 in range(size91):
|
||||
var list92 = buffer.readIntArray()
|
||||
result89.append(list92)
|
||||
result86.append(result89)
|
||||
result79[result82] = result86
|
||||
packet.mmmm = result79
|
||||
var result93 = {}
|
||||
var size94 = buffer.readInt()
|
||||
if (size94 > 0):
|
||||
for index95 in range(size94):
|
||||
var result96 = []
|
||||
var size98 = buffer.readInt()
|
||||
if (size98 > 0):
|
||||
for index97 in range(size98):
|
||||
var map99 = buffer.readIntStringMap()
|
||||
result96.append(map99)
|
||||
var result100 = []
|
||||
var size102 = buffer.readInt()
|
||||
if (size102 > 0):
|
||||
for index101 in range(size102):
|
||||
var map103 = buffer.readIntStringMap()
|
||||
result100.append(map103)
|
||||
result93[result96] = result100
|
||||
packet.mmmmm = result93
|
||||
var set104 = buffer.readIntArray()
|
||||
packet.s = set104
|
||||
var result105 = []
|
||||
var size107 = buffer.readInt()
|
||||
if (size107 > 0):
|
||||
for index106 in range(size107):
|
||||
var result108 = []
|
||||
var size110 = buffer.readInt()
|
||||
if (size110 > 0):
|
||||
for index109 in range(size110):
|
||||
var list111 = buffer.readIntArray()
|
||||
result108.append(list111)
|
||||
result105.append(result108)
|
||||
packet.ss = result105
|
||||
var result112 = []
|
||||
var size114 = buffer.readInt()
|
||||
if (size114 > 0):
|
||||
for index113 in range(size114):
|
||||
var set115 = buffer.readPacketArray(102)
|
||||
result112.append(set115)
|
||||
packet.sss = result112
|
||||
var set116 = buffer.readStringArray()
|
||||
packet.ssss = set116
|
||||
var result117 = []
|
||||
var size119 = buffer.readInt()
|
||||
if (size119 > 0):
|
||||
for index118 in range(size119):
|
||||
var map120 = buffer.readIntStringMap()
|
||||
result117.append(map120)
|
||||
packet.sssss = result117
|
||||
return packet
|
||||
@@ -1,87 +0,0 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
var a # byte
|
||||
var aaa # byte[]
|
||||
var b # short
|
||||
var c # int
|
||||
var d # long
|
||||
var e # float
|
||||
var f # double
|
||||
var g # boolean
|
||||
var jj # java.lang.String
|
||||
var kk # com.zfoo.protocol.packet.ObjectA
|
||||
var l # java.util.List<java.lang.Integer>
|
||||
var ll # java.util.List<java.lang.Long>
|
||||
var lll # java.util.List<com.zfoo.protocol.packet.ObjectA>
|
||||
var llll # java.util.List<java.lang.String>
|
||||
var m # java.util.Map<java.lang.Integer, java.lang.String>
|
||||
var mm # java.util.Map<java.lang.Integer, com.zfoo.protocol.packet.ObjectA>
|
||||
var s # java.util.Set<java.lang.Integer>
|
||||
var ssss # java.util.Set<java.lang.String>
|
||||
|
||||
const PROTOCOL_ID = 101
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeByte(packet.a)
|
||||
buffer.writeByteArray(packet.aaa)
|
||||
buffer.writeShort(packet.b)
|
||||
buffer.writeInt(packet.c)
|
||||
buffer.writeLong(packet.d)
|
||||
buffer.writeFloat(packet.e)
|
||||
buffer.writeDouble(packet.f)
|
||||
buffer.writeBool(packet.g)
|
||||
buffer.writeString(packet.jj)
|
||||
buffer.writePacket(packet.kk, 102)
|
||||
buffer.writeIntArray(packet.l)
|
||||
buffer.writeLongArray(packet.ll)
|
||||
buffer.writePacketArray(packet.lll, 102)
|
||||
buffer.writeStringArray(packet.llll)
|
||||
buffer.writeIntStringMap(packet.m)
|
||||
buffer.writeIntPacketMap(packet.mm, 102)
|
||||
buffer.writeIntArray(packet.s)
|
||||
buffer.writeStringArray(packet.ssss)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(101)
|
||||
var result0 = buffer.readByte()
|
||||
packet.a = result0
|
||||
var array1 = buffer.readByteArray()
|
||||
packet.aaa = array1
|
||||
var result2 = buffer.readShort()
|
||||
packet.b = result2
|
||||
var result3 = buffer.readInt()
|
||||
packet.c = result3
|
||||
var result4 = buffer.readLong()
|
||||
packet.d = result4
|
||||
var result5 = buffer.readFloat()
|
||||
packet.e = result5
|
||||
var result6 = buffer.readDouble()
|
||||
packet.f = result6
|
||||
var result7 = buffer.readBool()
|
||||
packet.g = result7
|
||||
var result8 = buffer.readString()
|
||||
packet.jj = result8
|
||||
var result9 = buffer.readPacket(102)
|
||||
packet.kk = result9
|
||||
var list10 = buffer.readIntArray()
|
||||
packet.l = list10
|
||||
var list11 = buffer.readLongArray()
|
||||
packet.ll = list11
|
||||
var list12 = buffer.readPacketArray(102)
|
||||
packet.lll = list12
|
||||
var list13 = buffer.readStringArray()
|
||||
packet.llll = list13
|
||||
var map14 = buffer.readIntStringMap()
|
||||
packet.m = map14
|
||||
var map15 = buffer.readIntPacketMap(102)
|
||||
packet.mm = map15
|
||||
var set16 = buffer.readIntArray()
|
||||
packet.s = set16
|
||||
var set17 = buffer.readStringArray()
|
||||
packet.ssss = set17
|
||||
return packet
|
||||
@@ -1,27 +0,0 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
var a # int
|
||||
var m # java.util.Map<java.lang.Integer, java.lang.String>
|
||||
var objectB # com.zfoo.protocol.packet.ObjectB
|
||||
|
||||
const PROTOCOL_ID = 102
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeInt(packet.a)
|
||||
buffer.writeIntStringMap(packet.m)
|
||||
buffer.writePacket(packet.objectB, 103)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(102)
|
||||
var result0 = buffer.readInt()
|
||||
packet.a = result0
|
||||
var map1 = buffer.readIntStringMap()
|
||||
packet.m = map1
|
||||
var result2 = buffer.readPacket(103)
|
||||
packet.objectB = result2
|
||||
return packet
|
||||
@@ -1,19 +0,0 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
var flag # boolean
|
||||
|
||||
const PROTOCOL_ID = 103
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeBool(packet.flag)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(103)
|
||||
var result0 = buffer.readBool()
|
||||
packet.flag = result0
|
||||
return packet
|
||||
@@ -1,23 +0,0 @@
|
||||
# @author jaysunxiao
|
||||
# @version 3.0
|
||||
var c # int
|
||||
var g # boolean
|
||||
|
||||
const PROTOCOL_ID = 104
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (buffer.writePacketFlag(packet)):
|
||||
return
|
||||
buffer.writeInt(packet.c)
|
||||
buffer.writeBool(packet.g)
|
||||
|
||||
|
||||
static func read(buffer):
|
||||
if (!buffer.readBool()):
|
||||
return null
|
||||
var packet = buffer.newInstance(104)
|
||||
var result0 = buffer.readInt()
|
||||
packet.c = result0
|
||||
var result1 = buffer.readBool()
|
||||
packet.g = result1
|
||||
return packet
|
||||
Reference in New Issue
Block a user