diff --git a/spring-web/src/jmh/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterBenchmark.java b/spring-web/src/jmh/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterBenchmark.java new file mode 100644 index 00000000000..3026a2d7695 --- /dev/null +++ b/spring-web/src/jmh/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverterBenchmark.java @@ -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 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 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(); + } + + } +} diff --git a/spring-web/src/test/java/org/springframework/protobuf/Msg.java b/spring-web/src/test/java/org/springframework/protobuf/Msg.java index b81eaa6e31e..9a278ee9019 100644 --- a/spring-web/src/test/java/org/springframework/protobuf/Msg.java +++ b/spring-web/src/test/java/org/springframework/protobuf/Msg.java @@ -1,19 +1,3 @@ -/* - * Copyright 2002-2022 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. - */ - // Generated by the protocol buffer compiler. DO NOT EDIT! // source: sample.proto @@ -22,134 +6,64 @@ package org.springframework.protobuf; /** * Protobuf type {@code Msg} */ -@SuppressWarnings("serial") -public final class Msg extends - com.google.protobuf.GeneratedMessage - implements MsgOrBuilder { +public final class Msg extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:Msg) + MsgOrBuilder { +private static final long serialVersionUID = 0L; // Use Msg.newBuilder() to construct. - private Msg(com.google.protobuf.GeneratedMessage.Builder builder) { + private Msg(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); - this.unknownFields = builder.getUnknownFields(); } - private Msg(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final Msg defaultInstance; - public static Msg getDefaultInstance() { - return defaultInstance; + private Msg() { + foo_ = ""; } - public Msg getDefaultInstanceForType() { - return defaultInstance; + @Override + @SuppressWarnings({"unused"}) + protected Object newInstance( + UnusedPrivateParameter unused) { + return new Msg(); } - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private Msg( - 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 10: { - bitField0_ |= 0x00000001; - foo_ = input.readBytes(); - break; - } - case 18: { - org.springframework.protobuf.SecondMsg.Builder subBuilder = null; - if (((bitField0_ & 0x00000002) == 0x00000002)) { - subBuilder = blah_.toBuilder(); - } - blah_ = input.readMessage(org.springframework.protobuf.SecondMsg.PARSER, extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(blah_); - blah_ = subBuilder.buildPartial(); - } - bitField0_ |= 0x00000002; - 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_Msg_descriptor; + return OuterSample.internal_static_Msg_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { - return org.springframework.protobuf.OuterSample.internal_static_Msg_fieldAccessorTable + return OuterSample.internal_static_Msg_fieldAccessorTable .ensureFieldAccessorsInitialized( - org.springframework.protobuf.Msg.class, org.springframework.protobuf.Msg.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public Msg parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Msg(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; + Msg.class, Builder.class); } private int bitField0_; - // optional string foo = 1; public static final int FOO_FIELD_NUMBER = 1; - private java.lang.Object foo_; + @SuppressWarnings("serial") + private volatile Object foo_ = ""; /** * optional string foo = 1; + * @return Whether the foo field is set. */ + @Override public boolean hasFoo() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional string foo = 1; + * @return The foo. */ - public java.lang.String getFoo() { - java.lang.Object ref = foo_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; + @Override + public String getFoo() { + Object ref = foo_; + if (ref instanceof String) { + return (String) ref; } else { - com.google.protobuf.ByteString bs = + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); + String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { foo_ = s; } @@ -158,14 +72,16 @@ public final class Msg extends } /** * optional string foo = 1; + * @return The bytes for foo. */ + @Override public com.google.protobuf.ByteString getFooBytes() { - java.lang.Object ref = foo_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = + Object ref = foo_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); + (String) ref); foo_ = b; return b; } else { @@ -173,142 +89,206 @@ public final class Msg extends } } - // optional .SecondMsg blah = 2; public static final int BLAH_FIELD_NUMBER = 2; - private org.springframework.protobuf.SecondMsg blah_; + private SecondMsg blah_; /** * optional .SecondMsg blah = 2; + * @return Whether the blah field is set. */ + @Override public boolean hasBlah() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** * optional .SecondMsg blah = 2; + * @return The blah. */ - public org.springframework.protobuf.SecondMsg getBlah() { - return blah_; + @Override + public SecondMsg getBlah() { + return blah_ == null ? SecondMsg.getDefaultInstance() : blah_; } /** * optional .SecondMsg blah = 2; */ - public org.springframework.protobuf.SecondMsgOrBuilder getBlahOrBuilder() { - return blah_; + @Override + public SecondMsgOrBuilder getBlahOrBuilder() { + return blah_ == null ? SecondMsg.getDefaultInstance() : blah_; } - private void initFields() { - foo_ = ""; - blah_ = org.springframework.protobuf.SecondMsg.getDefaultInstance(); - } 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)) { - output.writeBytes(1, getFooBytes()); + if (((bitField0_ & 0x00000001) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, foo_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeMessage(2, blah_); + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(2, getBlah()); } 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)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getFooBytes()); + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, foo_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { + if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, blah_); + .computeMessageSize(2, getBlah()); } 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 Msg)) { + return super.equals(obj); + } + Msg other = (Msg) obj; + + if (hasFoo() != other.hasFoo()) return false; + if (hasFoo()) { + if (!getFoo() + .equals(other.getFoo())) return false; + } + if (hasBlah() != other.hasBlah()) return false; + if (hasBlah()) { + if (!getBlah() + .equals(other.getBlah())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasFoo()) { + hash = (37 * hash) + FOO_FIELD_NUMBER; + hash = (53 * hash) + getFoo().hashCode(); + } + if (hasBlah()) { + hash = (37 * hash) + BLAH_FIELD_NUMBER; + hash = (53 * hash) + getBlah().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; } - public static org.springframework.protobuf.Msg parseFrom( + public static Msg parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static Msg parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static Msg parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.springframework.protobuf.Msg parseFrom( + public static Msg 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.Msg parseFrom(byte[] data) + public static Msg parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.springframework.protobuf.Msg parseFrom( + public static Msg parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static org.springframework.protobuf.Msg parseFrom(java.io.InputStream input) + public static Msg 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.Msg parseFrom( + public static Msg 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.Msg parseDelimitedFrom(java.io.InputStream input) + + public static Msg 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.Msg parseDelimitedFrom( + + public static Msg 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.Msg parseFrom( + public static Msg 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.Msg parseFrom( + public static Msg 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.Msg prototype) { - return newBuilder().mergeFrom(prototype); + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(Msg 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; } @@ -316,18 +296,20 @@ public final class Msg extends * Protobuf type {@code Msg} */ public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.springframework.protobuf.MsgOrBuilder { + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:Msg) + MsgOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.springframework.protobuf.OuterSample.internal_static_Msg_descriptor; + return OuterSample.internal_static_Msg_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { - return org.springframework.protobuf.OuterSample.internal_static_Msg_fieldAccessorTable + return OuterSample.internal_static_Msg_fieldAccessorTable .ensureFieldAccessorsInitialized( - org.springframework.protobuf.Msg.class, org.springframework.protobuf.Msg.Builder.class); + Msg.class, Builder.class); } // Construct using org.springframework.protobuf.Msg.newBuilder() @@ -336,152 +318,217 @@ public final class Msg extends } private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { getBlahFieldBuilder(); } } - private static Builder create() { - return new Builder(); - } - + @Override public Builder clear() { super.clear(); + bitField0_ = 0; foo_ = ""; - bitField0_ = (bitField0_ & ~0x00000001); - if (blahBuilder_ == null) { - blah_ = org.springframework.protobuf.SecondMsg.getDefaultInstance(); - } else { - blahBuilder_.clear(); + blah_ = null; + if (blahBuilder_ != null) { + blahBuilder_.dispose(); + blahBuilder_ = null; } - bitField0_ = (bitField0_ & ~0x00000002); return this; } - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - + @Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.springframework.protobuf.OuterSample.internal_static_Msg_descriptor; + return OuterSample.internal_static_Msg_descriptor; } - public org.springframework.protobuf.Msg getDefaultInstanceForType() { - return org.springframework.protobuf.Msg.getDefaultInstance(); + @Override + public Msg getDefaultInstanceForType() { + return Msg.getDefaultInstance(); } - public org.springframework.protobuf.Msg build() { - org.springframework.protobuf.Msg result = buildPartial(); + @Override + public Msg build() { + Msg result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; } - public org.springframework.protobuf.Msg buildPartial() { - org.springframework.protobuf.Msg result = new org.springframework.protobuf.Msg(this); + @Override + public Msg buildPartial() { + Msg result = new Msg(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(Msg result) { int from_bitField0_ = bitField0_; int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + if (((from_bitField0_ & 0x00000001) != 0)) { + result.foo_ = foo_; to_bitField0_ |= 0x00000001; } - result.foo_ = foo_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + if (((from_bitField0_ & 0x00000002) != 0)) { + result.blah_ = blahBuilder_ == null + ? blah_ + : blahBuilder_.build(); to_bitField0_ |= 0x00000002; } - if (blahBuilder_ == null) { - result.blah_ = blah_; - } else { - result.blah_ = blahBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; + 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.Msg) { - return mergeFrom((org.springframework.protobuf.Msg)other); + if (other instanceof Msg) { + return mergeFrom((Msg)other); } else { super.mergeFrom(other); return this; } } - public Builder mergeFrom(org.springframework.protobuf.Msg other) { - if (other == org.springframework.protobuf.Msg.getDefaultInstance()) return this; + public Builder mergeFrom(Msg other) { + if (other == Msg.getDefaultInstance()) return this; if (other.hasFoo()) { - bitField0_ |= 0x00000001; foo_ = other.foo_; + bitField0_ |= 0x00000001; onChanged(); } if (other.hasBlah()) { mergeBlah(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.Msg parsedMessage = null; + if (extensionRegistry == null) { + throw new NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + foo_ = input.readBytes(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + input.readMessage( + getBlahFieldBuilder().getBuilder(), + extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 + 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) { - parsedMessage = (org.springframework.protobuf.Msg) e.getUnfinishedMessage(); - throw e; + throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; - // optional string foo = 1; - private java.lang.Object foo_ = ""; + private Object foo_ = ""; /** * optional string foo = 1; + * @return Whether the foo field is set. */ public boolean hasFoo() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional string foo = 1; + * @return The foo. */ - public java.lang.String getFoo() { - java.lang.Object ref = foo_; - if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - foo_ = s; + public String getFoo() { + Object ref = foo_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + foo_ = s; + } return s; } else { - return (java.lang.String) ref; + return (String) ref; } } /** * optional string foo = 1; + * @return The bytes for foo. */ public com.google.protobuf.ByteString getFooBytes() { - java.lang.Object ref = foo_; + Object ref = foo_; if (ref instanceof String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); + (String) ref); foo_ = b; return b; } else { @@ -490,57 +537,58 @@ public final class Msg extends } /** * optional string foo = 1; + * @param value The foo to set. + * @return This builder for chaining. */ public Builder setFoo( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + String value) { + if (value == null) { throw new NullPointerException(); } foo_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } /** * optional string foo = 1; + * @return This builder for chaining. */ public Builder clearFoo() { - bitField0_ = (bitField0_ & ~0x00000001); foo_ = getDefaultInstance().getFoo(); + bitField0_ = (bitField0_ & ~0x00000001); onChanged(); return this; } /** * optional string foo = 1; + * @param value The bytes for foo to set. + * @return This builder for chaining. */ public Builder setFooBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + if (value == null) { throw new NullPointerException(); } foo_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } - // optional .SecondMsg blah = 2; - private org.springframework.protobuf.SecondMsg blah_ = org.springframework.protobuf.SecondMsg.getDefaultInstance(); - private com.google.protobuf.SingleFieldBuilder< - org.springframework.protobuf.SecondMsg, org.springframework.protobuf.SecondMsg.Builder, - org.springframework.protobuf.SecondMsgOrBuilder> blahBuilder_; + private SecondMsg blah_; + private com.google.protobuf.SingleFieldBuilderV3< + SecondMsg, SecondMsg.Builder, SecondMsgOrBuilder> blahBuilder_; /** * optional .SecondMsg blah = 2; + * @return Whether the blah field is set. */ public boolean hasBlah() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** * optional .SecondMsg blah = 2; + * @return The blah. */ - public org.springframework.protobuf.SecondMsg getBlah() { + public SecondMsg getBlah() { if (blahBuilder_ == null) { - return blah_; + return blah_ == null ? SecondMsg.getDefaultInstance() : blah_; } else { return blahBuilder_.getMessage(); } @@ -548,69 +596,71 @@ public final class Msg extends /** * optional .SecondMsg blah = 2; */ - public Builder setBlah(org.springframework.protobuf.SecondMsg value) { + public Builder setBlah(SecondMsg value) { if (blahBuilder_ == null) { if (value == null) { throw new NullPointerException(); } blah_ = value; - onChanged(); } else { blahBuilder_.setMessage(value); } bitField0_ |= 0x00000002; + onChanged(); return this; } /** * optional .SecondMsg blah = 2; */ public Builder setBlah( - org.springframework.protobuf.SecondMsg.Builder builderForValue) { + SecondMsg.Builder builderForValue) { if (blahBuilder_ == null) { blah_ = builderForValue.build(); - onChanged(); } else { blahBuilder_.setMessage(builderForValue.build()); } bitField0_ |= 0x00000002; + onChanged(); return this; } /** * optional .SecondMsg blah = 2; */ - public Builder mergeBlah(org.springframework.protobuf.SecondMsg value) { + public Builder mergeBlah(SecondMsg value) { if (blahBuilder_ == null) { - if (((bitField0_ & 0x00000002) == 0x00000002) && - blah_ != org.springframework.protobuf.SecondMsg.getDefaultInstance()) { - blah_ = - org.springframework.protobuf.SecondMsg.newBuilder(blah_).mergeFrom(value).buildPartial(); + if (((bitField0_ & 0x00000002) != 0) && + blah_ != null && + blah_ != SecondMsg.getDefaultInstance()) { + getBlahBuilder().mergeFrom(value); } else { blah_ = value; } - onChanged(); } else { blahBuilder_.mergeFrom(value); } - bitField0_ |= 0x00000002; + if (blah_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } return this; } /** * optional .SecondMsg blah = 2; */ public Builder clearBlah() { - if (blahBuilder_ == null) { - blah_ = org.springframework.protobuf.SecondMsg.getDefaultInstance(); - onChanged(); - } else { - blahBuilder_.clear(); - } bitField0_ = (bitField0_ & ~0x00000002); + blah_ = null; + if (blahBuilder_ != null) { + blahBuilder_.dispose(); + blahBuilder_ = null; + } + onChanged(); return this; } /** * optional .SecondMsg blah = 2; */ - public org.springframework.protobuf.SecondMsg.Builder getBlahBuilder() { + public SecondMsg.Builder getBlahBuilder() { bitField0_ |= 0x00000002; onChanged(); return getBlahFieldBuilder().getBuilder(); @@ -618,38 +668,91 @@ public final class Msg extends /** * optional .SecondMsg blah = 2; */ - public org.springframework.protobuf.SecondMsgOrBuilder getBlahOrBuilder() { + public SecondMsgOrBuilder getBlahOrBuilder() { if (blahBuilder_ != null) { return blahBuilder_.getMessageOrBuilder(); } else { - return blah_; + return blah_ == null ? + SecondMsg.getDefaultInstance() : blah_; } } /** * optional .SecondMsg blah = 2; */ - private com.google.protobuf.SingleFieldBuilder< - org.springframework.protobuf.SecondMsg, org.springframework.protobuf.SecondMsg.Builder, - org.springframework.protobuf.SecondMsgOrBuilder> + private com.google.protobuf.SingleFieldBuilderV3< + SecondMsg, SecondMsg.Builder, SecondMsgOrBuilder> getBlahFieldBuilder() { if (blahBuilder_ == null) { - blahBuilder_ = new com.google.protobuf.SingleFieldBuilder<>( - blah_, - getParentForChildren(), - isClean()); + blahBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< + SecondMsg, SecondMsg.Builder, SecondMsgOrBuilder>( + getBlah(), + getParentForChildren(), + isClean()); blah_ = null; } return blahBuilder_; } + @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:Msg) } + // @@protoc_insertion_point(class_scope:Msg) + private static final Msg DEFAULT_INSTANCE; static { - defaultInstance = new Msg(true); - defaultInstance.initFields(); + DEFAULT_INSTANCE = new Msg(); + } + + public static Msg getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @Override + public Msg 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 parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public Msg getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - // @@protoc_insertion_point(class_scope:Msg) } diff --git a/spring-web/src/test/java/org/springframework/protobuf/MsgOrBuilder.java b/spring-web/src/test/java/org/springframework/protobuf/MsgOrBuilder.java index 7a25a3ad556..866b7cfde73 100644 --- a/spring-web/src/test/java/org/springframework/protobuf/MsgOrBuilder.java +++ b/spring-web/src/test/java/org/springframework/protobuf/MsgOrBuilder.java @@ -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; /** * optional string foo = 1; + * @return Whether the foo field is set. */ boolean hasFoo(); /** * optional string foo = 1; + * @return The foo. */ - java.lang.String getFoo(); + String getFoo(); /** * optional string foo = 1; + * @return The bytes for foo. */ com.google.protobuf.ByteString getFooBytes(); - // optional .SecondMsg blah = 2; /** * optional .SecondMsg blah = 2; + * @return Whether the blah field is set. */ boolean hasBlah(); /** * optional .SecondMsg blah = 2; + * @return The blah. */ - org.springframework.protobuf.SecondMsg getBlah(); + SecondMsg getBlah(); /** * optional .SecondMsg blah = 2; */ - org.springframework.protobuf.SecondMsgOrBuilder getBlahOrBuilder(); + SecondMsgOrBuilder getBlahOrBuilder(); } diff --git a/spring-web/src/test/java/org/springframework/protobuf/OuterSample.java b/spring-web/src/test/java/org/springframework/protobuf/OuterSample.java index afafe62772e..9b63ef72885 100644 --- a/spring-web/src/test/java/org/springframework/protobuf/OuterSample.java +++ b/spring-web/src/test/java/org/springframework/protobuf/OuterSample.java @@ -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.ExtensionRegistryLite registry) { + } + public static void registerAllExtensions( com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); } - static com.google.protobuf.Descriptors.Descriptor + 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) diff --git a/spring-web/src/test/java/org/springframework/protobuf/SecondMsg.java b/spring-web/src/test/java/org/springframework/protobuf/SecondMsg.java index dedeee4a55e..5b6ab1092dd 100644 --- a/spring-web/src/test/java/org/springframework/protobuf/SecondMsg.java +++ b/spring-web/src/test/java/org/springframework/protobuf/SecondMsg.java @@ -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 PARSER = - new com.google.protobuf.AbstractParser() { - 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 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; /** * optional int32 blah = 1; + * @return Whether the blah field is set. */ + @Override public boolean hasBlah() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional int32 blah = 1; + * @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 - implements org.springframework.protobuf.SecondMsgOrBuilder { + com.google.protobuf.GeneratedMessageV3.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); + @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) == 0x00000001)) { + if (((from_bitField0_ & 0x00000001) != 0)) { + result.blah_ = blah_; to_bitField0_ |= 0x00000001; } - result.blah_ = blah_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; + 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; + if (extensionRegistry == null) { + throw new NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + 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) { - parsedMessage = (org.springframework.protobuf.SecondMsg) e.getUnfinishedMessage(); - throw e; + throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; - // optional int32 blah = 1; private int blah_ ; /** * optional int32 blah = 1; + * @return Whether the blah field is set. */ + @Override public boolean hasBlah() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional int32 blah = 1; + * @return The blah. */ + @Override public int getBlah() { return blah_; } /** * optional int32 blah = 1; + * @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; } /** * optional int32 blah = 1; + * @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 + PARSER = new com.google.protobuf.AbstractParser() { + @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 parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public SecondMsg getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - // @@protoc_insertion_point(class_scope:SecondMsg) } diff --git a/spring-web/src/test/java/org/springframework/protobuf/SecondMsgOrBuilder.java b/spring-web/src/test/java/org/springframework/protobuf/SecondMsgOrBuilder.java index baafb872ddf..fdfe62258e0 100644 --- a/spring-web/src/test/java/org/springframework/protobuf/SecondMsgOrBuilder.java +++ b/spring-web/src/test/java/org/springframework/protobuf/SecondMsgOrBuilder.java @@ -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; /** * optional int32 blah = 1; + * @return Whether the blah field is set. */ boolean hasBlah(); /** * optional int32 blah = 1; + * @return The blah. */ int getBlah(); }