From 29ee2b0d901ac552cb85846c203fd91a99c25ad2 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Mon, 16 May 2022 20:54:14 +0800 Subject: [PATCH] =?UTF-8?q?perf[protocol]:=20=E4=BD=BF=E7=94=A8=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=94=9F=E6=88=90=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generate/GenerateProtocolFile.java | 4 +- .../serializer/cpp/GenerateCppUtils.java | 4 - .../serializer/js/GenerateJsUtils.java | 175 +++++---------- .../serializer/js/JsArraySerializer.java | 3 - .../serializer/js/JsBooleanSerializer.java | 2 - .../serializer/js/JsByteSerializer.java | 2 - .../serializer/js/JsDoubleSerializer.java | 2 - .../serializer/js/JsFloatSerializer.java | 2 - .../serializer/js/JsIntSerializer.java | 1 - .../serializer/js/JsListSerializer.java | 2 - .../serializer/js/JsLongSerializer.java | 1 - .../serializer/js/JsMapSerializer.java | 1 - .../serializer/js/JsSetSerializer.java | 1 - .../serializer/js/JsShortSerializer.java | 2 - ...lManager.js => ProtocolManagerTemplate.js} | 9 + .../src/main/resources/js/ProtocolTemplate.js | 39 ++++ protocol/src/test/cpp/zfoocpp/ByteBuffer.h | 60 +++--- .../jsTest => javascript}/.eslintrc.js | 0 protocol/src/test/javascript/babel.config.js | 5 + .../main.spec.js} | 6 +- protocol/src/test/javascript/package.json | 51 +++++ .../zfoojs}/ProtocolManager.js | 26 +-- .../zfoojs}/buffer/ByteBuffer.js | 203 +++++++++--------- .../zfoojs}/buffer/long.js | 0 .../zfoojs}/buffer/longbits.js | 0 .../zfoojs}/packet/ComplexObject.js | 0 .../zfoojs}/packet/NormalObject.js | 0 .../zfoojs}/packet/ObjectA.js | 0 .../zfoojs}/packet/ObjectB.js | 0 .../zfoojs}/packet/SimpleObject.js | 0 30 files changed, 307 insertions(+), 294 deletions(-) rename protocol/src/main/resources/js/{ProtocolManager.js => ProtocolManagerTemplate.js} (87%) create mode 100644 protocol/src/main/resources/js/ProtocolTemplate.js rename protocol/src/test/{resources/jsTest => javascript}/.eslintrc.js (100%) create mode 100644 protocol/src/test/javascript/babel.config.js rename protocol/src/test/{resources/jsTest/jsProtocolTest.spec.js => javascript/main.spec.js} (93%) create mode 100644 protocol/src/test/javascript/package.json rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/ProtocolManager.js (62%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/buffer/ByteBuffer.js (84%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/buffer/long.js (100%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/buffer/longbits.js (100%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/packet/ComplexObject.js (100%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/packet/NormalObject.js (100%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/packet/ObjectA.js (100%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/packet/ObjectB.js (100%) rename protocol/src/test/{resources/jsTest/jsProtocol => javascript/zfoojs}/packet/SimpleObject.js (100%) diff --git a/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolFile.java b/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolFile.java index 8155f9d8..a1525f4c 100644 --- a/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolFile.java +++ b/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolFile.java @@ -116,7 +116,9 @@ public abstract class GenerateProtocolFile { // 生成Javascript协议 if (generateLanguages.contains(CodeLanguage.JavaScript)) { GenerateJsUtils.init(generateOperation); - allSortedGenerateProtocols.forEach(it -> GenerateJsUtils.createJsProtocolFile((ProtocolRegistration) it)); + for (var protocolRegistration : allSortedGenerateProtocols) { + GenerateJsUtils.createJsProtocolFile((ProtocolRegistration) protocolRegistration); + } GenerateJsUtils.createProtocolManager(allSortedGenerateProtocols); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java index c0539f32..c39542a0 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java @@ -219,12 +219,10 @@ public abstract class GenerateCppUtils { } private static Pair valueOfMethod(ProtocolRegistration registration) { - var protocolId = registration.getId(); var fields = registration.getFields(); var fieldRegistrations = registration.getFieldRegistrations(); var filedList = new ArrayList>(); - for (int i = 0; i < fields.length; i++) { var field = fields[i]; var fieldRegistration = fieldRegistrations[i]; @@ -232,7 +230,6 @@ public abstract class GenerateCppUtils { filedList.add(propertyTypeAndName); } - // ValueOf()方法 var valueOfParams = filedList.stream() .map(it -> StringUtils.format("{} {}", it.getKey(), it.getValue())) @@ -241,7 +238,6 @@ public abstract class GenerateCppUtils { var cppBuilder = new StringBuilder(); filedList.forEach(it -> cppBuilder.append(TAB + TAB + TAB).append(StringUtils.format("packet.{} = {};", it.getValue(), it.getValue())).append(LS)); - return new Pair<>(valueOfParamsStr, cppBuilder.toString()); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/GenerateJsUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/GenerateJsUtils.java index 82811e7a..dddb97b2 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/GenerateJsUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/GenerateJsUtils.java @@ -17,9 +17,9 @@ import com.zfoo.protocol.generate.GenerateOperation; import com.zfoo.protocol.generate.GenerateProtocolDocument; import com.zfoo.protocol.generate.GenerateProtocolFile; import com.zfoo.protocol.generate.GenerateProtocolPath; +import com.zfoo.protocol.model.Pair; import com.zfoo.protocol.registration.IProtocolRegistration; import com.zfoo.protocol.registration.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,8 +28,10 @@ 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 java.util.stream.Collectors; import static com.zfoo.protocol.util.FileUtils.LS; @@ -78,172 +80,106 @@ public abstract class GenerateJsUtils { } public static void createProtocolManager(List protocolList) throws IOException { - var list = List.of("js/buffer/ByteBuffer.js" - , "js/buffer/long.js" - , "js/buffer/longbits.js"); - + var list = List.of("js/buffer/ByteBuffer.js", "js/buffer/long.js", "js/buffer/longbits.js"); for (var fileName : list) { var fileInputStream = ClassUtils.getFileFromClassPath(fileName); var createFile = new File(StringUtils.format("{}/{}", protocolOutputRootPath, StringUtils.substringAfterFirst(fileName, "js/"))); FileUtils.writeInputStreamToFile(createFile, fileInputStream); } - // 生成ProtocolManager.js文件 - var jsBuilder = new StringBuilder(); + var protocolManagerTemplate = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("js/ProtocolManagerTemplate.js"))); - protocolList.stream() - .filter(it -> Objects.nonNull(it)) - .forEach(it -> { - var name = it.protocolConstructor().getDeclaringClass().getSimpleName(); - var path = GenerateProtocolPath.getProtocolPath(it.protocolId()); - if (StringUtils.isBlank(path)) { - jsBuilder.append(StringUtils.format("import {} from './{}.js';", name, name)).append(LS); - } else { - jsBuilder.append(StringUtils.format("import {} from './{}/{}.js';", name, path, name)).append(LS); - } - }); + var importBuilder = new StringBuilder(); + var initProtocolBuilder = new StringBuilder(); + for (var protocol : protocolList) { + var protocolId = protocol.protocolId(); + var protocolName = protocol.protocolConstructor().getDeclaringClass().getSimpleName(); + var path = GenerateProtocolPath.getProtocolPath(protocol.protocolId()); + if (StringUtils.isBlank(path)) { + importBuilder.append(StringUtils.format("import {} from './{}.js';", protocolName, protocolName)).append(LS); + } else { + importBuilder.append(StringUtils.format("import {} from './{}/{}.js';", protocolName, path, protocolName)).append(LS); + } - jsBuilder.append(LS).append(LS); + initProtocolBuilder.append(TAB).append(StringUtils.format("protocols.set({}, {});", protocolId, protocolName)); + } - var protocolManagerStr = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("js/ProtocolManager.js"))); - jsBuilder.append(protocolManagerStr); - - jsBuilder.append("ProtocolManager.initProtocol = function initProtocol() {").append(LS); - protocolList.stream().filter(it -> Objects.nonNull(it)) - .forEach(it -> jsBuilder.append(TAB).append(StringUtils.format("protocols.set({}, {});", it.protocolId(), it.protocolConstructor().getDeclaringClass().getSimpleName())).append(LS)); - jsBuilder.append("};").append(LS + LS); - - jsBuilder.append("export default ProtocolManager;").append(LS); - - FileUtils.writeStringToFile(new File(StringUtils.format("{}/{}", protocolOutputRootPath, "ProtocolManager.js")), jsBuilder.toString()); + protocolManagerTemplate = StringUtils.format(protocolManagerTemplate, importBuilder.toString().trim(), initProtocolBuilder.toString().trim()); + FileUtils.writeStringToFile(new File(StringUtils.format("{}/{}", protocolOutputRootPath, "ProtocolManager.js")), protocolManagerTemplate); } - public static void createJsProtocolFile(ProtocolRegistration registration) { + public static void createJsProtocolFile(ProtocolRegistration registration) throws IOException { // 初始化index GenerateProtocolFile.index.set(0); var protocolId = registration.protocolId(); var registrationConstructor = registration.getConstructor(); - var protocolClazzName = registrationConstructor.getDeclaringClass().getSimpleName(); - var jsBuilder = new StringBuilder(); + var protocolTemplate = StringUtils.bytesToString(IOUtils.toByteArray(ClassUtils.getFileFromClassPath("js/ProtocolTemplate.js"))); - // export object - jsBuilder.append(exportFunction(registration)); + var docTitle = docTitle(registration); + var valueOfMethod = valueOfMethod(registration); + var writeObject = writeObject(registration); + var readObject = readObject(registration); - // protocolId method - jsBuilder.append(protocolIdFunction(registration)); - - // writeObject method - jsBuilder.append(writeObject(registration)); - - // readObject method - jsBuilder.append(readObject(registration)); - - - jsBuilder.append(LS).append(StringUtils.format("export default {};", protocolClazzName)).append(LS); - - - var protocolOutputPath = StringUtils.format("{}/{}/{}.js" - , protocolOutputRootPath - , GenerateProtocolPath.getProtocolPath(protocolId) - , protocolClazzName); - FileUtils.writeStringToFile(new File(protocolOutputPath), jsBuilder.toString()); + protocolTemplate = StringUtils.format(protocolTemplate, docTitle, protocolClazzName + , valueOfMethod.getKey().trim(), valueOfMethod.getValue().trim(), protocolClazzName, protocolId, protocolClazzName + , writeObject.trim(), protocolClazzName, protocolClazzName, readObject.trim(), protocolClazzName); + var protocolOutputPath = StringUtils.format("{}/{}/{}.js", protocolOutputRootPath + , GenerateProtocolPath.getProtocolPath(protocolId), protocolClazzName); + FileUtils.writeStringToFile(new File(protocolOutputPath), protocolTemplate); } - private static String exportFunction(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(); + return docTitle; + } + + private static Pair valueOfMethod(ProtocolRegistration registration) { + var protocolId = registration.getId(); + var fields = registration.getFields(); + + var fieldValueOf = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).collect(Collectors.toList()).toArray()); + var fieldDefinitionBuilder = new StringBuilder(); + + var protocolDocument = GenerateProtocolDocument.getProtocolDocument(protocolId); var docFieldMap = protocolDocument.getValue(); - - var jsBuilder = new StringBuilder(); - - if (StringUtils.isNotBlank(docTitle)) { - jsBuilder.append(docTitle).append(LS); - } - - jsBuilder.append(StringUtils.format("const {} = function(", protocolClazzName)); - jsBuilder.append(StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).collect(Collectors.toList()).toArray())) - .append(") {") - .append(LS); - for (var field : fields) { var propertyName = field.getName(); - // 生成注释 var doc = docFieldMap.get(propertyName); if (StringUtils.isNotBlank(doc)) { - Arrays.stream(doc.split(LS)).forEach(it -> jsBuilder.append(TAB).append(it).append(LS)); + Arrays.stream(doc.split(LS)).forEach(it -> fieldDefinitionBuilder.append(TAB).append(it).append(LS)); } - jsBuilder.append(TAB) + fieldDefinitionBuilder.append(TAB) .append(StringUtils.format("this.{} = {};", propertyName, propertyName)) .append(" // ").append(field.getGenericType().getTypeName())// 生成类型的注释 .append(LS); } - - jsBuilder.append("};").append(LS).append(LS); - return jsBuilder.toString(); + return new Pair<>(fieldValueOf, fieldDefinitionBuilder.toString()); } - private static String protocolIdFunction(ProtocolRegistration registration) { - var protocolId = registration.getId(); - var protocolClazzName = registration.getConstructor().getDeclaringClass().getSimpleName(); - - var jsBuilder = new StringBuilder(); - jsBuilder.append(StringUtils.format("{}.prototype.protocolId = function() {", protocolClazzName)).append(LS); - jsBuilder.append(TAB).append(StringUtils.format("return {};", protocolId)).append(LS); - jsBuilder.append("};").append(LS).append(LS); - - return jsBuilder.toString(); - } - - private static String writeObject(ProtocolRegistration registration) { var fields = registration.getFields(); var fieldRegistrations = registration.getFieldRegistrations(); - var protocolClazzName = registration.getConstructor().getDeclaringClass().getSimpleName(); - var jsBuilder = new StringBuilder(); - jsBuilder.append(StringUtils.format("{}.write = function(buffer, packet) {", protocolClazzName)).append(LS); - - jsBuilder.append(TAB).append("if (buffer.writePacketFlag(packet)) {").append(LS); - jsBuilder.append(TAB + TAB).append("return;").append(LS); - jsBuilder.append(TAB).append("}").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]; jsSerializer(fieldRegistration.serializer()).writeObject(jsBuilder, "packet." + field.getName(), 1, field, fieldRegistration); } - - jsBuilder.append("};").append(LS).append(LS); return jsBuilder.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("{}.read = function(buffer) {", protocolClazzName)).append(LS); - jsBuilder.append(TAB).append("if (!buffer.readBoolean()) {").append(LS); - jsBuilder.append(TAB + TAB).append("return null;").append(LS); - jsBuilder.append(TAB).append("}").append(LS); - - - jsBuilder.append(TAB).append(StringUtils.format("const packet = new {}();", protocolClazzName)).append(LS); - - for (var i = 0; i < fields.length; i++) { var field = fields[i]; var fieldRegistration = fieldRegistrations[i]; @@ -251,13 +187,6 @@ public abstract class GenerateJsUtils { var readObject = jsSerializer(fieldRegistration.serializer()).readObject(jsBuilder, 1, field, fieldRegistration); jsBuilder.append(TAB).append(StringUtils.format("packet.{} = {};", field.getName(), readObject)).append(LS); } - - jsBuilder.append(TAB).append("return packet;").append(LS); - - jsBuilder.append("};").append(LS); - return jsBuilder.toString(); } - - } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsArraySerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsArraySerializer.java index 8d14cf92..0e1c7e93 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsArraySerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsArraySerializer.java @@ -24,7 +24,6 @@ import java.lang.reflect.Field; import static com.zfoo.protocol.util.FileUtils.LS; - /** * @author jaysunxiao * @version 3.0 @@ -91,8 +90,6 @@ public class JsArraySerializer implements IJsSerializer { builder.append("}").append(LS); GenerateProtocolFile.addTab(builder, deep); builder.append("}").append(LS); - - return result; } } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsBooleanSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsBooleanSerializer.java index 802761bb..c25f979f 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsBooleanSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsBooleanSerializer.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import static com.zfoo.protocol.util.FileUtils.LS; - /** * @author jaysunxiao * @version 3.0 @@ -37,7 +36,6 @@ public class JsBooleanSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readBoolean(); ", result)).append(LS); return result; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsByteSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsByteSerializer.java index 76b9d540..38f74367 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsByteSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsByteSerializer.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import static com.zfoo.protocol.util.FileUtils.LS; - /** * @author jaysunxiao * @version 3.0 @@ -37,7 +36,6 @@ public class JsByteSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readByte();", result)).append(LS); return result; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsDoubleSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsDoubleSerializer.java index 20a4564c..2db99937 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsDoubleSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsDoubleSerializer.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import static com.zfoo.protocol.util.FileUtils.LS; - /** * @author jaysunxiao * @version 3.0 @@ -37,7 +36,6 @@ public class JsDoubleSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readDouble();", result)).append(LS); return result; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsFloatSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsFloatSerializer.java index f97e7f94..663dcd53 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsFloatSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsFloatSerializer.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import static com.zfoo.protocol.util.FileUtils.LS; - /** * @author jaysunxiao * @version 3.0 @@ -37,7 +36,6 @@ public class JsFloatSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readFloat();", result)).append(LS); return result; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsIntSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsIntSerializer.java index fcbc2afa..d84bf6df 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsIntSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsIntSerializer.java @@ -36,7 +36,6 @@ public class JsIntSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readInt();", result)).append(LS); return result; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsListSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsListSerializer.java index cc955a73..0216361c 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsListSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsListSerializer.java @@ -90,8 +90,6 @@ public class JsListSerializer implements IJsSerializer { builder.append("}").append(LS); GenerateProtocolFile.addTab(builder, deep); builder.append("}").append(LS); - - return result; } } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsLongSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsLongSerializer.java index 5c117b34..3ee8a6b8 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsLongSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsLongSerializer.java @@ -36,7 +36,6 @@ public class JsLongSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readLong();", result)).append(LS); return result; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsMapSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsMapSerializer.java index bc609f3d..8f94d94e 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsMapSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsMapSerializer.java @@ -100,7 +100,6 @@ public class JsMapSerializer implements IJsSerializer { builder.append("}").append(LS); GenerateProtocolFile.addTab(builder, deep); builder.append("}").append(LS); - return result; } } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsSetSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsSetSerializer.java index 673d0877..13d9f840 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsSetSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsSetSerializer.java @@ -91,7 +91,6 @@ public class JsSetSerializer implements IJsSerializer { builder.append("}").append(LS); GenerateProtocolFile.addTab(builder, deep); builder.append("}").append(LS); - return result; } } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsShortSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsShortSerializer.java index 480f56ce..0fb99f9c 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsShortSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/js/JsShortSerializer.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import static com.zfoo.protocol.util.FileUtils.LS; - /** * @author jaysunxiao * @version 3.0 @@ -37,7 +36,6 @@ public class JsShortSerializer implements IJsSerializer { @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.index.getAndIncrement(); - GenerateProtocolFile.addTab(builder, deep); builder.append(StringUtils.format("const {} = buffer.readShort();", result)).append(LS); return result; diff --git a/protocol/src/main/resources/js/ProtocolManager.js b/protocol/src/main/resources/js/ProtocolManagerTemplate.js similarity index 87% rename from protocol/src/main/resources/js/ProtocolManager.js rename to protocol/src/main/resources/js/ProtocolManagerTemplate.js index 5412a909..db282e69 100644 --- a/protocol/src/main/resources/js/ProtocolManager.js +++ b/protocol/src/main/resources/js/ProtocolManagerTemplate.js @@ -1,3 +1,6 @@ +{ +} + const protocols = new Map(); const ProtocolManager = {}; @@ -24,3 +27,9 @@ ProtocolManager.read = function read(buffer) { return packet; }; +ProtocolManager.initProtocol = function initProtocol() { + { + } +}; + +export default ProtocolManager; diff --git a/protocol/src/main/resources/js/ProtocolTemplate.js b/protocol/src/main/resources/js/ProtocolTemplate.js new file mode 100644 index 00000000..74bdea9a --- /dev/null +++ b/protocol/src/main/resources/js/ProtocolTemplate.js @@ -0,0 +1,39 @@ +{ +} +const {} = function ({}) { + { + } +}; + +{ +} +. +prototype.protocolId = function () { + return {}; +}; + +{ +} +. +write = function (buffer, packet) { + if (buffer.writePacketFlag(packet)) { + return; + } + { + } +}; + +{ +} +. +read = function (buffer) { + if (!buffer.readBoolean()) { + return null; + } + const packet = new {}(); + { + } + return packet; +}; + +export default {}; diff --git a/protocol/src/test/cpp/zfoocpp/ByteBuffer.h b/protocol/src/test/cpp/zfoocpp/ByteBuffer.h index fafe9735..e242a618 100644 --- a/protocol/src/test/cpp/zfoocpp/ByteBuffer.h +++ b/protocol/src/test/cpp/zfoocpp/ByteBuffer.h @@ -417,7 +417,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeBool(value); } } @@ -439,7 +439,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeBool(value); } } @@ -460,7 +460,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeBool(value); } } @@ -482,7 +482,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeByte(value); } } @@ -504,7 +504,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeByte(value); } } @@ -525,7 +525,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeByte(value); } } @@ -547,7 +547,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeShort(value); } } @@ -568,7 +568,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeShort(value); } } @@ -589,7 +589,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeShort(value); } } @@ -611,7 +611,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeInt(value); } } @@ -632,7 +632,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeInt(value); } } @@ -653,7 +653,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeInt(value); } } @@ -675,7 +675,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeLong(value); } } @@ -696,7 +696,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeLong(value); } } @@ -717,7 +717,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeLong(value); } } @@ -739,7 +739,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeFloat(value); } } @@ -760,7 +760,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeFloat(value); } } @@ -781,7 +781,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeFloat(value); } } @@ -803,7 +803,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeDouble(value); } } @@ -824,7 +824,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeDouble(value); } } @@ -845,7 +845,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeDouble(value); } } @@ -867,7 +867,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeChar(value); } } @@ -888,7 +888,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeChar(value); } } @@ -909,7 +909,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeChar(value); } } @@ -931,7 +931,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writeString(value); } } @@ -952,7 +952,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writeString(value); } } @@ -973,7 +973,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writeString(value); } } @@ -1282,7 +1282,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (auto value : array) { + for (const auto &value : array) { writePacket((IPacket *) &value, protocolId); } } @@ -1307,7 +1307,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (auto value : list) { + for (const auto &value : list) { writePacket((IPacket *) &value, protocolId); } } @@ -1332,7 +1332,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (auto value : set) { + for (const auto &value : set) { writePacket((IPacket *) &value, protocolId); } } diff --git a/protocol/src/test/resources/jsTest/.eslintrc.js b/protocol/src/test/javascript/.eslintrc.js similarity index 100% rename from protocol/src/test/resources/jsTest/.eslintrc.js rename to protocol/src/test/javascript/.eslintrc.js diff --git a/protocol/src/test/javascript/babel.config.js b/protocol/src/test/javascript/babel.config.js new file mode 100644 index 00000000..ed3c0c49 --- /dev/null +++ b/protocol/src/test/javascript/babel.config.js @@ -0,0 +1,5 @@ +module.exports = { + presets: [ + '@vue/app' + ] +}; diff --git a/protocol/src/test/resources/jsTest/jsProtocolTest.spec.js b/protocol/src/test/javascript/main.spec.js similarity index 93% rename from protocol/src/test/resources/jsTest/jsProtocolTest.spec.js rename to protocol/src/test/javascript/main.spec.js index 21506ef9..3b08957e 100644 --- a/protocol/src/test/resources/jsTest/jsProtocolTest.spec.js +++ b/protocol/src/test/javascript/main.spec.js @@ -1,11 +1,11 @@ -import ByteBuffer from './jsProtocol/buffer/ByteBuffer.js'; -import ProtocolManager from './jsProtocol/ProtocolManager.js'; +import ByteBuffer from './zfoojs/buffer/ByteBuffer.js'; +import ProtocolManager from './zfoojs/ProtocolManager.js'; const fs = require('fs'); describe('jsProtocolTest', () => { it('complexObjectTest', () => { - const data = fs.readFileSync('C:\\zfoo\\protocol\\src\\test\\resources\\ComplexObject.bytes'); + const data = fs.readFileSync('resources\\ComplexObject.bytes'); ProtocolManager.initProtocol(); diff --git a/protocol/src/test/javascript/package.json b/protocol/src/test/javascript/package.json new file mode 100644 index 00000000..1382dd80 --- /dev/null +++ b/protocol/src/test/javascript/package.json @@ -0,0 +1,51 @@ +{ + "name": "zfoo", + "version": "0.0.0", + "description": "This is a common config for all projects", + "author": "jaysunxiao@gmail.com", + "license": "MIT", + "scripts": { + }, + "dependencies": { + "vue": "2.6.11", + "vue-i18n": "8.12.0", + "vue-meta": "^2.2.2", + "vue-router": "3.1.6", + "vuelidate": "^0.7.5", + "vuetify": "^2.3.3", + "vuex": "3.1.3", + "vuex-router-sync": "^5.0.0" + }, + "devDependencies": { + "@vue/cli-plugin-babel": "~4.3.0", + "@vue/cli-plugin-eslint": "~4.3.0", + "@vue/cli-plugin-pwa": "^4.3.1", + "@vue/cli-service": "~4.3.0", + "@vue/cli-plugin-unit-jest": "~4.3.0", + "@vue/eslint-config-standard": "^4.0.0", + "@vue/test-utils": "1.0.0-beta.33", + "babel-core": "7.0.0-bridge.0", + "babel-jest": "23.6.0", + "babel-eslint": "^10.1.0", + "eslint": "^6.7.2", + "eslint-plugin-vue": "^6.2.2", + "node-sass": "^4.13.0", + "sass": "^1.19.0", + "sass-loader": "^8.0.0", + "stylus": "^0.54.5", + "stylus-loader": "^3.0.1", + "mockjs": "1.0.0", + "vue-template-compiler": "2.6.11", + "vue-cli-plugin-vuetify": "^2.0.6", + "vuetify-loader": "^1.5.0" + }, + "engines": { + "node": ">=8.9", + "npm": ">= 3.0.0" + }, + "browserslist": [ + "> 1%", + "last 2 versions", + "not dead" + ] +} diff --git a/protocol/src/test/resources/jsTest/jsProtocol/ProtocolManager.js b/protocol/src/test/javascript/zfoojs/ProtocolManager.js similarity index 62% rename from protocol/src/test/resources/jsTest/jsProtocol/ProtocolManager.js rename to protocol/src/test/javascript/zfoojs/ProtocolManager.js index 63cc4ce6..ce83dfcd 100644 --- a/protocol/src/test/resources/jsTest/jsProtocol/ProtocolManager.js +++ b/protocol/src/test/javascript/zfoojs/ProtocolManager.js @@ -4,10 +4,13 @@ import ObjectA from './packet/ObjectA.js'; import ObjectB from './packet/ObjectB.js'; import SimpleObject from './packet/SimpleObject.js'; - const protocols = new Map(); -const ProtocolManager = {}; +const ProtocolManager = protocols.set(100, ComplexObject); +protocols.set(101, NormalObject); +protocols.set(102, ObjectA); +protocols.set(103, ObjectB); +protocols.set(104, SimpleObject); ProtocolManager.getProtocol = function getProtocol(protocolId) { const protocol = protocols.get(protocolId); @@ -17,26 +20,23 @@ ProtocolManager.getProtocol = function getProtocol(protocolId) { return protocol; }; -ProtocolManager.write = function write(byteBuffer, packet) { +ProtocolManager.write = function write(buffer, packet) { const protocolId = packet.protocolId(); - byteBuffer.writeShort(protocolId); + buffer.writeShort(protocolId); const protocol = ProtocolManager.getProtocol(protocolId); - protocol.write(byteBuffer, packet); + protocol.write(buffer, packet); }; -ProtocolManager.read = function read(byteBuffer) { - const protocolId = byteBuffer.readShort(); +ProtocolManager.read = function read(buffer) { + const protocolId = buffer.readShort(); const protocol = ProtocolManager.getProtocol(protocolId); - const packet = protocol.read(byteBuffer); + const packet = protocol.read(buffer); return packet; }; ProtocolManager.initProtocol = function initProtocol() { - protocols.set(100, ComplexObject); - protocols.set(101, NormalObject); - protocols.set(102, ObjectA); - protocols.set(103, ObjectB); - protocols.set(104, SimpleObject); + { + } }; export default ProtocolManager; diff --git a/protocol/src/test/resources/jsTest/jsProtocol/buffer/ByteBuffer.js b/protocol/src/test/javascript/zfoojs/buffer/ByteBuffer.js similarity index 84% rename from protocol/src/test/resources/jsTest/jsProtocol/buffer/ByteBuffer.js rename to protocol/src/test/javascript/zfoojs/buffer/ByteBuffer.js index ffa63dcf..642b7a0e 100644 --- a/protocol/src/test/resources/jsTest/jsProtocol/buffer/ByteBuffer.js +++ b/protocol/src/test/javascript/zfoojs/buffer/ByteBuffer.js @@ -1,4 +1,4 @@ -import { readInt64, writeInt64 } from './longbits.js'; +import {readInt64, writeInt64} from './longbits.js'; import ProtocolManager from '../ProtocolManager.js'; const empty_str = ''; @@ -19,6 +19,7 @@ const minInt = -2147483648; const util = require('util'); const encoder = new util.TextEncoder('utf-8'); const decoder = new util.TextDecoder('utf-8'); + // 在js中long可以支持的最大值 // const maxLong = 9007199254740992; // const minLong = -9007199254740992; @@ -343,28 +344,28 @@ const ByteBuffer = function() { return flag; }; - this.writePacket = function(value, protocolId) { + this.writePacket = function (packet, protocolId) { const protocolRegistration = ProtocolManager.getProtocol(protocolId); - protocolRegistration.write(this, value); + protocolRegistration.write(this, packet); }; - this.readPacket = function(protocolId) { + this.readPacket = function (protocolId) { const protocolRegistration = ProtocolManager.getProtocol(protocolId); return protocolRegistration.read(this); }; - this.writeBooleanArray = function(value) { - if (value === null) { + this.writeBooleanArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeBoolean(element); }); } }; - this.readBooleanArray = function() { + this.readBooleanArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -375,18 +376,18 @@ const ByteBuffer = function() { return array; }; - this.writeByteArray = function(value) { - if (value === null) { + this.writeByteArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeByte(element); }); } }; - this.readByteArray = function() { + this.readByteArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -397,18 +398,18 @@ const ByteBuffer = function() { return array; }; - this.writeShortArray = function(value) { - if (value === null) { + this.writeShortArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeShort(element); }); } }; - this.readShortArray = function() { + this.readShortArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -419,18 +420,18 @@ const ByteBuffer = function() { return array; }; - this.writeIntArray = function(value) { - if (value === null) { + this.writeIntArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeInt(element); }); } }; - this.readIntArray = function() { + this.readIntArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -441,18 +442,18 @@ const ByteBuffer = function() { return array; }; - this.writeLongArray = function(value) { - if (value === null) { + this.writeLongArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeLong(element); }); } }; - this.readLongArray = function() { + this.readLongArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -463,18 +464,18 @@ const ByteBuffer = function() { return array; }; - this.writeFloatArray = function(value) { - if (value === null) { + this.writeFloatArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeFloat(element); }); } }; - this.readFloatArray = function() { + this.readFloatArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -485,18 +486,18 @@ const ByteBuffer = function() { return array; }; - this.writeDoubleArray = function(value) { - if (value === null) { + this.writeDoubleArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeDouble(element); }); } }; - this.readDoubleArray = function() { + this.readDoubleArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -507,18 +508,18 @@ const ByteBuffer = function() { return array; }; - this.writeStringArray = function(value) { - if (value === null) { + this.writeStringArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeString(element); }); } }; - this.readStringArray = function() { + this.readStringArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -529,18 +530,18 @@ const ByteBuffer = function() { return array; }; - this.writeCharArray = function(value) { - if (value === null) { + this.writeCharArray = function (array) { + if (array === null) { this.writeInt(0); } else { - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { this.writeChar(element); }); } }; - this.readCharArray = function() { + this.readCharArray = function () { const array = []; const length = this.readInt(); if (length > 0) { @@ -551,13 +552,13 @@ const ByteBuffer = function() { return array; }; - this.writePacketArray = function(value, protocolId) { - if (value === null) { + this.writePacketArray = function (array, protocolId) { + if (array === null) { this.writeInt(0); } else { const protocolRegistration = ProtocolManager.getProtocol(protocolId); - this.writeInt(value.length); - value.forEach(element => { + this.writeInt(array.length); + array.forEach(element => { protocolRegistration.write(this, element); }); } @@ -575,12 +576,12 @@ const ByteBuffer = function() { return array; }; - this.writeIntIntMap = function(value) { - if (value === null) { + this.writeIntIntMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeInt(key); this.writeInt(value); }); @@ -600,12 +601,12 @@ const ByteBuffer = function() { return map; }; - this.writeIntLongMap = function(value) { - if (value === null) { + this.writeIntLongMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeInt(key); this.writeLong(value); }); @@ -625,12 +626,12 @@ const ByteBuffer = function() { return map; }; - this.writeIntStringMap = function(value) { - if (value === null) { + this.writeIntStringMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeInt(key); this.writeString(value); }); @@ -650,13 +651,13 @@ const ByteBuffer = function() { return map; }; - this.writeIntPacketMap = function(value, protocolId) { - if (value === null) { + this.writeIntPacketMap = function (map, protocolId) { + if (map === null) { this.writeInt(0); } else { const protocolRegistration = ProtocolManager.getProtocol(protocolId); - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeInt(key); protocolRegistration.write(this, value); }); @@ -677,12 +678,12 @@ const ByteBuffer = function() { return map; }; - this.writeLongIntMap = function(value) { - if (value === null) { + this.writeLongIntMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeLong(key); this.writeInt(value); }); @@ -702,12 +703,12 @@ const ByteBuffer = function() { return map; }; - this.writeLongLongMap = function(value) { - if (value === null) { + this.writeLongLongMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeLong(key); this.writeLong(value); }); @@ -727,12 +728,12 @@ const ByteBuffer = function() { return map; }; - this.writeLongStringMap = function(value) { - if (value === null) { + this.writeLongStringMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeLong(key); this.writeString(value); }); @@ -752,13 +753,13 @@ const ByteBuffer = function() { return map; }; - this.writeLongPacketMap = function(value, protocolId) { - if (value === null) { + this.writeLongPacketMap = function (map, protocolId) { + if (map === null) { this.writeInt(0); } else { const protocolRegistration = ProtocolManager.getProtocol(protocolId); - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeLong(key); protocolRegistration.write(this, value); }); @@ -779,12 +780,12 @@ const ByteBuffer = function() { return map; }; - this.writeStringIntMap = function(value) { - if (value === null) { + this.writeStringIntMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeString(key); this.writeInt(value); }); @@ -804,12 +805,12 @@ const ByteBuffer = function() { return map; }; - this.writeStringLongMap = function(value) { - if (value === null) { + this.writeStringLongMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeString(key); this.writeLong(value); }); @@ -829,12 +830,12 @@ const ByteBuffer = function() { return map; }; - this.writeStringStringMap = function(value) { - if (value === null) { + this.writeStringStringMap = function (map) { + if (map === null) { this.writeInt(0); } else { - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeString(key); this.writeString(value); }); @@ -854,13 +855,13 @@ const ByteBuffer = function() { return map; }; - this.writeStringPacketMap = function(value, protocolId) { - if (value === null) { + this.writeStringPacketMap = function (map, protocolId) { + if (map === null) { this.writeInt(0); } else { const protocolRegistration = ProtocolManager.getProtocol(protocolId); - this.writeInt(value.size); - value.forEach((value, key) => { + this.writeInt(map.size); + map.forEach((value, key) => { this.writeString(key); protocolRegistration.write(this, value); }); diff --git a/protocol/src/test/resources/jsTest/jsProtocol/buffer/long.js b/protocol/src/test/javascript/zfoojs/buffer/long.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/buffer/long.js rename to protocol/src/test/javascript/zfoojs/buffer/long.js diff --git a/protocol/src/test/resources/jsTest/jsProtocol/buffer/longbits.js b/protocol/src/test/javascript/zfoojs/buffer/longbits.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/buffer/longbits.js rename to protocol/src/test/javascript/zfoojs/buffer/longbits.js diff --git a/protocol/src/test/resources/jsTest/jsProtocol/packet/ComplexObject.js b/protocol/src/test/javascript/zfoojs/packet/ComplexObject.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/packet/ComplexObject.js rename to protocol/src/test/javascript/zfoojs/packet/ComplexObject.js diff --git a/protocol/src/test/resources/jsTest/jsProtocol/packet/NormalObject.js b/protocol/src/test/javascript/zfoojs/packet/NormalObject.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/packet/NormalObject.js rename to protocol/src/test/javascript/zfoojs/packet/NormalObject.js diff --git a/protocol/src/test/resources/jsTest/jsProtocol/packet/ObjectA.js b/protocol/src/test/javascript/zfoojs/packet/ObjectA.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/packet/ObjectA.js rename to protocol/src/test/javascript/zfoojs/packet/ObjectA.js diff --git a/protocol/src/test/resources/jsTest/jsProtocol/packet/ObjectB.js b/protocol/src/test/javascript/zfoojs/packet/ObjectB.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/packet/ObjectB.js rename to protocol/src/test/javascript/zfoojs/packet/ObjectB.js diff --git a/protocol/src/test/resources/jsTest/jsProtocol/packet/SimpleObject.js b/protocol/src/test/javascript/zfoojs/packet/SimpleObject.js similarity index 100% rename from protocol/src/test/resources/jsTest/jsProtocol/packet/SimpleObject.js rename to protocol/src/test/javascript/zfoojs/packet/SimpleObject.js