Skip to content

Commit

Permalink
Merge from main and some fixes
Browse files Browse the repository at this point in the history
Signed-off-by: jasperpotts <[email protected]>
  • Loading branch information
jasperpotts committed Jan 13, 2025
1 parent de37734 commit 596bd1f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static String buildCleanFieldJavaDoc(List<Integer> fieldNumbers, Protobuf
public static String cleanJavaDocComment(String fieldComment) {
return cleanDocStr(fieldComment
.replaceAll("/\\*\\*[\n\r\s\t]*\\*[\t\s]*|[\n\r\s\t]*\\*/","") // remove java doc
.replaceAll("\n\s+\\*\s+","\n") // remove indenting and *
.replaceAll("(^|\n)\s+\\*(\s+|\n|$)","\n") // remove indenting and *
.replaceAll("\n\s+\\*\s*\n","\n\n") // remove indenting and *
.replaceAll("/\\*\\*","") // remove indenting and /** at beginning of comment.
.trim() // Remove leading and trailing spaces.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ public void generate(final MessageDefContext msgDef,
final String modelPackage = lookupHelper.getPackageForMessage(FileType.MODEL, msgDef);
// The File to write the sources that we generate into
final File javaFile = getJavaFile(destinationSrcDir, modelPackage, javaRecordName);
// The javadoc comment to use for the model class, which comes **directly** from the protobuf schema,
// but is cleaned up and formatted for use in JavaDoc.
String javaDocComment = (msgDef.docComment()== null) ? "/**\\n * " + javaRecordName +" */" :
cleanDocStr(msgDef.docComment().getText().replaceAll("\n \\*\s*\n","\n * <p>\n"));
// The Javadoc "@Deprecated" tag, which is set if the protobuf schema says the field is deprecated
String deprecated = "";
// The list of fields, as defined in the protobuf schema & precomputed fields
Expand Down Expand Up @@ -131,6 +127,16 @@ public void generate(final MessageDefContext msgDef,
"$protobufEncodedSize", null, null,
null, null, "Computed protobuf encoded size, manual input ignored.", false, null));

// The javadoc comment to use for the model class, which comes **directly** from the protobuf schema,
// but is cleaned up and formatted for use in JavaDoc.
String docComment = (msgDef.docComment() == null || msgDef.docComment().getText().isBlank())
? javaRecordName :
cleanJavaDocComment(msgDef.docComment().getText());
if (docComment.endsWith("\n")) {
docComment = docComment.substring(0, docComment.length() - 1);
}
final String javaDocComment = "/**\n * " + docComment.replaceAll("\n", "\n * ") + "\n */";

// === Build Body Content
String bodyContent = "";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.hedera.pbj.intergration.jmh;

import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import com.hedera.hapi.node.base.Timestamp;
Expand All @@ -14,6 +13,9 @@
import com.hedera.pbj.runtime.io.buffer.BufferedData;
import com.hedera.pbj.test.proto.pbj.Everything;
import com.hederahashgraph.api.proto.java.GetAccountDetailsResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -26,21 +28,17 @@
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

@SuppressWarnings("unused")
@Fork(1)
@Warmup(iterations = 2, time = 2)
@Measurement(iterations = 5, time = 2)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public abstract class JsonBench<P extends Record,G extends GeneratedMessage> {
public abstract class JsonBench<P,G extends GeneratedMessage> {

@SuppressWarnings("rawtypes")
@State(Scope.Benchmark)
public static class JsonBenchmarkState<P extends Record,G extends GeneratedMessage> {
public static class JsonBenchmarkState<P,G extends GeneratedMessage> {
private JsonCodec<P> pbjJsonCodec;
private Supplier<GeneratedMessage.Builder> builderSupplier;
// input objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
@Measurement(iterations = 7, time = 2)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public abstract class ProtobufObjectBench<P extends Record,G extends GeneratedMessage> {
public abstract class ProtobufObjectBench<P,G extends GeneratedMessage> {
/** we repeat all operations 1000 times so that measured times are nig enough */
private static final int OPERATION_COUNT = 1000;

@State(Scope.Benchmark)
public static class BenchmarkState<P extends Record,G extends GeneratedMessage> {
public static class BenchmarkState<P,G extends GeneratedMessage> {
private Codec<P> pbjCodec;
private ProtobufParseFunction<byte[], G> googleByteArrayParseMethod;
private ProtobufParseFunction<ByteBuffer, G> googleByteBufferParseMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;

/**
* Faster non-synchronized ByteArrayInputStream. This class is not thread safe, and does not require synchronization.
Expand Down Expand Up @@ -83,7 +82,7 @@ public int read(byte[] b, int off, int len) {
* {@inheritDoc}
*/
@Override
public byte @NotNull [] readAllBytes() {
public byte [] readAllBytes() {
byte[] result = Arrays.copyOfRange(buf, pos, count);
pos = count;
return result;
Expand Down

0 comments on commit 596bd1f

Please sign in to comment.