From 06242287a049608c1c8c2261da0f8ac1aab8620a Mon Sep 17 00:00:00 2001 From: godotg Date: Mon, 15 Jul 2024 15:15:39 +0800 Subject: [PATCH] ref[protocol]: refactor field method --- .../com/zfoo/protocol/serializer/php/CodeGeneratePhp.java | 6 ++++-- .../zfoo/protocol/serializer/scala/CodeGenerateScala.java | 6 ++++-- .../serializer/typescript/CodeGenerateTypeScript.java | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/php/CodeGeneratePhp.java b/protocol/src/main/java/com/zfoo/protocol/serializer/php/CodeGeneratePhp.java index abfd4ef4c..cb897a497 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/php/CodeGeneratePhp.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/php/CodeGeneratePhp.java @@ -243,8 +243,10 @@ private String protocol_field_definition(ProtocolRegistration registration) { for (var fieldNote : fieldNotes) { phpBuilder.append(fieldNote).append(LS); } - var pair = phpSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); - phpBuilder.append(StringUtils.format("var {} ${} = {};", pair.getKey(), fieldName, pair.getValue())).append(LS); + var fieldTypeDefaultValue = phpSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); + var fieldType = fieldTypeDefaultValue.getKey(); + var fieldDefaultValue = fieldTypeDefaultValue.getValue(); + phpBuilder.append(StringUtils.format("var {} ${} = {};", fieldType, fieldName, fieldDefaultValue)).append(LS); } return phpBuilder.toString(); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/scala/CodeGenerateScala.java b/protocol/src/main/java/com/zfoo/protocol/serializer/scala/CodeGenerateScala.java index 73d82c1dd..e65b913c5 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/scala/CodeGenerateScala.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/scala/CodeGenerateScala.java @@ -279,8 +279,10 @@ private String protocol_field_definition(ProtocolRegistration registration) { for (var fieldNote : fieldNotes) { scalaBuilder.append(fieldNote).append(LS); } - var pair = scalaSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); - scalaBuilder.append(StringUtils.format("var {}: {} = {}", fieldName, pair.getKey(), pair.getValue())).append(LS); + var fieldTypeDefaultValue = scalaSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); + var fieldType = fieldTypeDefaultValue.getKey(); + var fieldDefaultValue = fieldTypeDefaultValue.getValue(); + scalaBuilder.append(StringUtils.format("var {}: {} = {}", fieldName, fieldType, fieldDefaultValue)).append(LS); } return scalaBuilder.toString(); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/CodeGenerateTypeScript.java b/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/CodeGenerateTypeScript.java index 3e4e70778..415b830b5 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/CodeGenerateTypeScript.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/CodeGenerateTypeScript.java @@ -293,8 +293,10 @@ private String protocol_field_definition(ProtocolRegistration registration) { for (var fieldNote : fieldNotes) { tsBuilder.append(fieldNote).append(LS); } - var pair = tsSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); - tsBuilder.append(StringUtils.format("{}: {} = {};", fieldName, pair.getKey(), pair.getValue())).append(LS); + var fieldTypeDefaultValue = tsSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); + var fieldType = fieldTypeDefaultValue.getKey(); + var fieldDefaultValue = fieldTypeDefaultValue.getValue(); + tsBuilder.append(StringUtils.format("{}: {} = {};", fieldName, fieldType, fieldDefaultValue)).append(LS); } return tsBuilder.toString(); }