Add JMH benchmarks for Protobuf message converter

This commit re-generates the protobuf Java classes with a recent version
of the protoc binary and adds JMH benchmarks that exercise the message
converter for both the reading and writing cases.

See gh-29496
This commit is contained in:
Brian Clozel 2023-10-20 16:33:57 +02:00
parent 631a5d1dc1
commit 31a62ff8ba
6 changed files with 843 additions and 515 deletions

View File

@ -0,0 +1,116 @@
/*
* Copyright 2002-2023 the original author or 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http.converter.protobuf;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.stream.Stream;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.springframework.protobuf.Msg;
import org.springframework.protobuf.SecondMsg;
import org.springframework.web.testfixture.http.MockHttpInputMessage;
import org.springframework.web.testfixture.http.MockHttpOutputMessage;
/**
* Benchmarks for the {@link ProtobufHttpMessageConverter}.
*
* @author Brian Clozel
*/
@BenchmarkMode(Mode.Throughput)
public class ProtobufHttpMessageConverterBenchmark {
@Benchmark
public void writeMessages(BenchmarkWriteData data, Blackhole bh) throws IOException {
for (Msg message : data.messages) {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
data.converter.write(message, ProtobufHttpMessageConverter.PROTOBUF, outputMessage);
bh.consume(outputMessage);
}
}
/**
* Benchmark data holding typical Protobuf messages to be converted to bytes.
*/
@State(Scope.Benchmark)
public static class BenchmarkWriteData {
@Param({"40"})
public int messageCount;
public List<Msg> messages;
public ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter();
@Setup(Level.Trial)
public void createMessages() {
Random random = new Random();
this.messages = Stream.generate(() -> createMessage(random.nextInt())).limit(this.messageCount).toList();
}
private Msg createMessage(int randomValue) {
return Msg.newBuilder().setFoo(String.valueOf(randomValue)).setBlah(SecondMsg.newBuilder().setBlah(randomValue).build()).build();
}
}
@Benchmark
public void readMessages(BenchmarkReadData data, Blackhole bh) throws IOException {
for (byte[] message : data.messages) {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(message);
bh.consume(data.converter.read(Msg.class, inputMessage));
}
}
/**
* Benchmark data holding typical Protobuf messages to be converted to bytes.
*/
@State(Scope.Benchmark)
public static class BenchmarkReadData {
@Param({"40"})
public int messageCount;
public List<byte[]> messages;
public ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter();
@Setup(Level.Trial)
public void createMessages() {
Random random = new Random();
this.messages = Stream.generate(() -> createMessage(random.nextInt())).limit(this.messageCount).toList();
}
private byte[] createMessage(int randomValue) {
return Msg.newBuilder().setFoo(String.valueOf(randomValue)).setBlah(SecondMsg.newBuilder().setBlah(randomValue).build()).build().toByteArray();
}
}
}

View File

@ -3,35 +3,39 @@
package org.springframework.protobuf;
public interface MsgOrBuilder
extends com.google.protobuf.MessageOrBuilder {
public interface MsgOrBuilder extends
// @@protoc_insertion_point(interface_extends:Msg)
com.google.protobuf.MessageOrBuilder {
// optional string foo = 1;
/**
* <code>optional string foo = 1;</code>
* @return Whether the foo field is set.
*/
boolean hasFoo();
/**
* <code>optional string foo = 1;</code>
* @return The foo.
*/
java.lang.String getFoo();
String getFoo();
/**
* <code>optional string foo = 1;</code>
* @return The bytes for foo.
*/
com.google.protobuf.ByteString
getFooBytes();
// optional .SecondMsg blah = 2;
/**
* <code>optional .SecondMsg blah = 2;</code>
* @return Whether the blah field is set.
*/
boolean hasBlah();
/**
* <code>optional .SecondMsg blah = 2;</code>
* @return The blah.
*/
org.springframework.protobuf.SecondMsg getBlah();
SecondMsg getBlah();
/**
* <code>optional .SecondMsg blah = 2;</code>
*/
org.springframework.protobuf.SecondMsgOrBuilder getBlahOrBuilder();
SecondMsgOrBuilder getBlahOrBuilder();
}

View File

@ -3,60 +3,57 @@
package org.springframework.protobuf;
@SuppressWarnings("deprecation")
public class OuterSample {
public final class OuterSample {
private OuterSample() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
com.google.protobuf.ExtensionRegistryLite registry) {
}
static com.google.protobuf.Descriptors.Descriptor
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
static final com.google.protobuf.Descriptors.Descriptor
internal_static_Msg_descriptor;
static
com.google.protobuf.GeneratedMessage.FieldAccessorTable
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_Msg_fieldAccessorTable;
static com.google.protobuf.Descriptors.Descriptor
static final com.google.protobuf.Descriptors.Descriptor
internal_static_SecondMsg_descriptor;
static
com.google.protobuf.GeneratedMessage.FieldAccessorTable
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SecondMsg_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
String[] descriptorData = {
"\n\014sample.proto\",\n\003Msg\022\013\n\003foo\030\001 \001(\t\022\030\n\004bl" +
"ah\030\002 \001(\0132\n.SecondMsg\"\031\n\tSecondMsg\022\014\n\004bla" +
"h\030\001 \001(\005B-\n\034org.springframework.protobufB" +
"\013OuterSampleP\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
public com.google.protobuf.ExtensionRegistry assignDescriptors(
com.google.protobuf.Descriptors.FileDescriptor root) {
descriptor = root;
internal_static_Msg_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_Msg_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_Msg_descriptor,
new java.lang.String[] { "Foo", "Blah", });
internal_static_SecondMsg_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_SecondMsg_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_SecondMsg_descriptor,
new java.lang.String[] { "Blah", });
return null;
}
};
com.google.protobuf.Descriptors.FileDescriptor
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
}, assigner);
});
internal_static_Msg_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_Msg_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_Msg_descriptor,
new String[] { "Foo", "Blah", });
internal_static_SecondMsg_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_SecondMsg_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SecondMsg_descriptor,
new String[] { "Blah", });
}
// @@protoc_insertion_point(outer_class_scope)

View File

@ -6,223 +6,217 @@ package org.springframework.protobuf;
/**
* Protobuf type {@code SecondMsg}
*/
@SuppressWarnings("serial")
public final class SecondMsg extends
com.google.protobuf.GeneratedMessage
implements SecondMsgOrBuilder {
public final class SecondMsg extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SecondMsg)
SecondMsgOrBuilder {
private static final long serialVersionUID = 0L;
// Use SecondMsg.newBuilder() to construct.
private SecondMsg(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
private SecondMsg(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
this.unknownFields = builder.getUnknownFields();
}
private SecondMsg(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
private static final SecondMsg defaultInstance;
public static SecondMsg getDefaultInstance() {
return defaultInstance;
private SecondMsg() {
}
public SecondMsg getDefaultInstanceForType() {
return defaultInstance;
@Override
@SuppressWarnings({"unused"})
protected Object newInstance(
UnusedPrivateParameter unused) {
return new SecondMsg();
}
private final com.google.protobuf.UnknownFieldSet unknownFields;
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SecondMsg(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
initFields();
@SuppressWarnings("unused")
int mutable_bitField0_ = 0;
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
default: {
if (!parseUnknownField(input, unknownFields,
extensionRegistry, tag)) {
done = true;
}
break;
}
case 8: {
bitField0_ |= 0x00000001;
blah_ = input.readInt32();
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e.getMessage()).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return org.springframework.protobuf.OuterSample.internal_static_SecondMsg_descriptor;
return OuterSample.internal_static_SecondMsg_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
@Override
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return org.springframework.protobuf.OuterSample.internal_static_SecondMsg_fieldAccessorTable
return OuterSample.internal_static_SecondMsg_fieldAccessorTable
.ensureFieldAccessorsInitialized(
org.springframework.protobuf.SecondMsg.class, org.springframework.protobuf.SecondMsg.Builder.class);
}
public static com.google.protobuf.Parser<SecondMsg> PARSER =
new com.google.protobuf.AbstractParser<SecondMsg>() {
public SecondMsg parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SecondMsg(input, extensionRegistry);
}
};
@java.lang.Override
public com.google.protobuf.Parser<SecondMsg> getParserForType() {
return PARSER;
SecondMsg.class, Builder.class);
}
private int bitField0_;
// optional int32 blah = 1;
public static final int BLAH_FIELD_NUMBER = 1;
private int blah_;
private int blah_ = 0;
/**
* <code>optional int32 blah = 1;</code>
* @return Whether the blah field is set.
*/
@Override
public boolean hasBlah() {
return ((bitField0_ & 0x00000001) == 0x00000001);
return ((bitField0_ & 0x00000001) != 0);
}
/**
* <code>optional int32 blah = 1;</code>
* @return The blah.
*/
@Override
public int getBlah() {
return blah_;
}
private void initFields() {
blah_ = 0;
}
private byte memoizedIsInitialized = -1;
@Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized != -1) return isInitialized == 1;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
if (((bitField0_ & 0x00000001) == 0x00000001)) {
if (((bitField0_ & 0x00000001) != 0)) {
output.writeInt32(1, blah_);
}
getUnknownFields().writeTo(output);
}
private int memoizedSerializedSize = -1;
@Override
public int getSerializedSize() {
int size = memoizedSerializedSize;
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (((bitField0_ & 0x00000001) == 0x00000001)) {
if (((bitField0_ & 0x00000001) != 0)) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(1, blah_);
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
memoizedSize = size;
return size;
}
private static final long serialVersionUID = 0L;
@java.lang.Override
protected java.lang.Object writeReplace()
throws java.io.ObjectStreamException {
return super.writeReplace();
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof SecondMsg)) {
return super.equals(obj);
}
SecondMsg other = (SecondMsg) obj;
if (hasBlah() != other.hasBlah()) return false;
if (hasBlah()) {
if (getBlah()
!= other.getBlah()) return false;
}
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
public static org.springframework.protobuf.SecondMsg parseFrom(
@Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
if (hasBlah()) {
hash = (37 * hash) + BLAH_FIELD_NUMBER;
hash = (53 * hash) + getBlah();
}
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
}
public static SecondMsg parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static SecondMsg parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static SecondMsg parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.springframework.protobuf.SecondMsg parseFrom(
public static SecondMsg parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.springframework.protobuf.SecondMsg parseFrom(byte[] data)
public static SecondMsg parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.springframework.protobuf.SecondMsg parseFrom(
public static SecondMsg parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.springframework.protobuf.SecondMsg parseFrom(java.io.InputStream input)
public static SecondMsg parseFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static org.springframework.protobuf.SecondMsg parseFrom(
public static SecondMsg parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static org.springframework.protobuf.SecondMsg parseDelimitedFrom(java.io.InputStream input)
public static SecondMsg parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input);
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static org.springframework.protobuf.SecondMsg parseDelimitedFrom(
public static SecondMsg parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input, extensionRegistry);
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static org.springframework.protobuf.SecondMsg parseFrom(
public static SecondMsg parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static org.springframework.protobuf.SecondMsg parseFrom(
public static SecondMsg parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static Builder newBuilder() { return Builder.create(); }
@Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder(org.springframework.protobuf.SecondMsg prototype) {
return newBuilder().mergeFrom(prototype);
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(SecondMsg prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
public Builder toBuilder() { return newBuilder(this); }
@java.lang.Override
@Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
@ -230,145 +224,205 @@ public final class SecondMsg extends
* Protobuf type {@code SecondMsg}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessage.Builder<Builder>
implements org.springframework.protobuf.SecondMsgOrBuilder {
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SecondMsg)
SecondMsgOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return org.springframework.protobuf.OuterSample.internal_static_SecondMsg_descriptor;
return OuterSample.internal_static_SecondMsg_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
@Override
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return org.springframework.protobuf.OuterSample.internal_static_SecondMsg_fieldAccessorTable
return OuterSample.internal_static_SecondMsg_fieldAccessorTable
.ensureFieldAccessorsInitialized(
org.springframework.protobuf.SecondMsg.class, org.springframework.protobuf.SecondMsg.Builder.class);
SecondMsg.class, Builder.class);
}
// Construct using org.springframework.protobuf.SecondMsg.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
}
}
private static Builder create() {
return new Builder();
}
}
@Override
public Builder clear() {
super.clear();
bitField0_ = 0;
blah_ = 0;
bitField0_ = (bitField0_ & ~0x00000001);
return this;
}
public Builder clone() {
return create().mergeFrom(buildPartial());
}
@Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return org.springframework.protobuf.OuterSample.internal_static_SecondMsg_descriptor;
return OuterSample.internal_static_SecondMsg_descriptor;
}
public org.springframework.protobuf.SecondMsg getDefaultInstanceForType() {
return org.springframework.protobuf.SecondMsg.getDefaultInstance();
@Override
public SecondMsg getDefaultInstanceForType() {
return SecondMsg.getDefaultInstance();
}
public org.springframework.protobuf.SecondMsg build() {
org.springframework.protobuf.SecondMsg result = buildPartial();
@Override
public SecondMsg build() {
SecondMsg result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public org.springframework.protobuf.SecondMsg buildPartial() {
org.springframework.protobuf.SecondMsg result = new org.springframework.protobuf.SecondMsg(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
to_bitField0_ |= 0x00000001;
}
result.blah_ = blah_;
result.bitField0_ = to_bitField0_;
@Override
public SecondMsg buildPartial() {
SecondMsg result = new SecondMsg(this);
if (bitField0_ != 0) { buildPartial0(result); }
onBuilt();
return result;
}
private void buildPartial0(SecondMsg result) {
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) != 0)) {
result.blah_ = blah_;
to_bitField0_ |= 0x00000001;
}
result.bitField0_ |= to_bitField0_;
}
@Override
public Builder clone() {
return super.clone();
}
@Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
Object value) {
return super.setField(field, value);
}
@Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, Object value) {
return super.setRepeatedField(field, index, value);
}
@Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
Object value) {
return super.addRepeatedField(field, value);
}
@Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof org.springframework.protobuf.SecondMsg) {
return mergeFrom((org.springframework.protobuf.SecondMsg)other);
if (other instanceof SecondMsg) {
return mergeFrom((SecondMsg)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(org.springframework.protobuf.SecondMsg other) {
if (other == org.springframework.protobuf.SecondMsg.getDefaultInstance()) return this;
public Builder mergeFrom(SecondMsg other) {
if (other == SecondMsg.getDefaultInstance()) return this;
if (other.hasBlah()) {
setBlah(other.getBlah());
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
return this;
}
@Override
public final boolean isInitialized() {
return true;
}
@Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
org.springframework.protobuf.SecondMsg parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (org.springframework.protobuf.SecondMsg) e.getUnfinishedMessage();
throw e;
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
if (extensionRegistry == null) {
throw new NullPointerException();
}
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 8: {
blah_ = input.readInt32();
bitField0_ |= 0x00000001;
break;
} // case 8
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
}
break;
} // default:
} // switch (tag)
} // while (!done)
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.unwrapIOException();
} finally {
onChanged();
} // finally
return this;
}
private int bitField0_;
// optional int32 blah = 1;
private int blah_ ;
/**
* <code>optional int32 blah = 1;</code>
* @return Whether the blah field is set.
*/
@Override
public boolean hasBlah() {
return ((bitField0_ & 0x00000001) == 0x00000001);
return ((bitField0_ & 0x00000001) != 0);
}
/**
* <code>optional int32 blah = 1;</code>
* @return The blah.
*/
@Override
public int getBlah() {
return blah_;
}
/**
* <code>optional int32 blah = 1;</code>
* @param value The blah to set.
* @return This builder for chaining.
*/
public Builder setBlah(int value) {
bitField0_ |= 0x00000001;
blah_ = value;
bitField0_ |= 0x00000001;
onChanged();
return this;
}
/**
* <code>optional int32 blah = 1;</code>
* @return This builder for chaining.
*/
public Builder clearBlah() {
bitField0_ = (bitField0_ & ~0x00000001);
@ -376,15 +430,67 @@ public final class SecondMsg extends
onChanged();
return this;
}
@Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SecondMsg)
}
// @@protoc_insertion_point(class_scope:SecondMsg)
private static final SecondMsg DEFAULT_INSTANCE;
static {
defaultInstance = new SecondMsg(true);
defaultInstance.initFields();
DEFAULT_INSTANCE = new SecondMsg();
}
public static SecondMsg getDefaultInstance() {
return DEFAULT_INSTANCE;
}
@Deprecated public static final com.google.protobuf.Parser<SecondMsg>
PARSER = new com.google.protobuf.AbstractParser<SecondMsg>() {
@Override
public SecondMsg parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
Builder builder = newBuilder();
try {
builder.mergeFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(builder.buildPartial());
} catch (com.google.protobuf.UninitializedMessageException e) {
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(e)
.setUnfinishedMessage(builder.buildPartial());
}
return builder.buildPartial();
}
};
public static com.google.protobuf.Parser<SecondMsg> parser() {
return PARSER;
}
@Override
public com.google.protobuf.Parser<SecondMsg> getParserForType() {
return PARSER;
}
@Override
public SecondMsg getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
// @@protoc_insertion_point(class_scope:SecondMsg)
}

View File

@ -3,16 +3,18 @@
package org.springframework.protobuf;
public interface SecondMsgOrBuilder
extends com.google.protobuf.MessageOrBuilder {
public interface SecondMsgOrBuilder extends
// @@protoc_insertion_point(interface_extends:SecondMsg)
com.google.protobuf.MessageOrBuilder {
// optional int32 blah = 1;
/**
* <code>optional int32 blah = 1;</code>
* @return Whether the blah field is set.
*/
boolean hasBlah();
/**
* <code>optional int32 blah = 1;</code>
* @return The blah.
*/
int getBlah();
}