perf[protobuf]: generate pojo in protobuf

This commit is contained in:
godotg
2023-12-03 10:27:51 +08:00
parent bc5bf563fe
commit e174fc5480
3 changed files with 19 additions and 24 deletions
@@ -78,6 +78,9 @@ public class GeneratePbUtils {
if (options != null) {
options.forEach(o -> protoOptions.put(o.getName(), o.getValue()));
}
if (CollectionUtils.isEmpty(proto.getMessages())) {
continue;
}
generateDtoMessage(buildOption, proto, allProtos);
}
@@ -86,29 +89,24 @@ public class GeneratePbUtils {
private static void generateDtoMessage(PbBuildOption buildOption, Proto proto, Map<String, Proto> protos) {
JavaBuilder builder = new JavaBuilder();
String msgPath = buildOption.getOutputPath() + File.separator;
Map<String, String> msgComments = new HashMap<>();
List<ProtoMessage> msgs = proto.getMessages();
if (CollectionUtils.isNotEmpty(msgs)) {
String msgPath = buildOption.getOutputPath() + File.separator;
msgs.stream()
.sorted(Comparator.comparing(ProtoMessage::getName))
.forEach(it -> {
StringBuilder mc = new StringBuilder();
if (it.getComment() != null) {
mc.append(it.getComment());
} else {
if (it.getComment() != null && it.getComment().getLines() != null) {
it.getComment().getLines().forEach(c -> mc.append(c));
}
}
msgComments.put(it.getName(), mc.toString());
var code = builder.buildMessage(proto, it, 1, null, protos);
var filePath = msgPath + File.separator + it.getName() + ".java";
FileUtils.writeStringToFile(new File(filePath), code, false);
});
for (var msg : msgs) {
StringBuilder mc = new StringBuilder();
if (msg.getComment() != null) {
mc.append(msg.getComment());
} else {
if (msg.getComment() != null && msg.getComment().getLines() != null) {
msg.getComment().getLines().forEach(c -> mc.append(c));
}
}
msgComments.put(msg.getName(), mc.toString());
var code = builder.buildMessage(proto, msg, 1, null, protos);
var filePath = msgPath + File.separator + msg.getName() + ".java";
FileUtils.writeStringToFile(new File(filePath), code, false);
}
}
@@ -1,6 +1,5 @@
/*
* Copyright 2021 The edap Project
*
* Copyright (C) 2020 The zfoo Authors
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
@@ -11,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.protocol.serializer.protobuf.internal;
package com.zfoo.protocol.serializer.protobuf.builder;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@@ -14,8 +14,6 @@
package com.zfoo.protocol.serializer.protobuf.builder;
import com.zfoo.protocol.collection.CollectionUtils;
import com.zfoo.protocol.serializer.protobuf.PbBuildOption;
import com.zfoo.protocol.serializer.protobuf.internal.CodeBuilder;
import com.zfoo.protocol.serializer.protobuf.wire.*;
import com.zfoo.protocol.serializer.protobuf.wire.Field.Type;
import com.zfoo.protocol.serializer.protobuf.wire.WireFormat.JavaType;