https://github.com/protocolbuffers/protobuf/releases/download/v3.1.0/protoc-3.1.0-win32.zip
Cygwin下从源代码安装protoc
从源代码安装protoc可参考文章:https://lobin.iteye.com/blog/2435854
例子:
TestIntMessage.proto
syntax = "proto3"; option java_package = "com.grpc.service"; message TestIntRequest { //optional int32 value = 1; } message TestIntResponse { //optional int32 value = 1; }
编译
$ protoc --java_out=. TestIntMessage.proto
生成
package com.grpc.service; public final class TestIntMessage { private TestIntMessage() {} public static void registerAllExtensions( com.google.protobuf.ExtensionRegistryLite registry) { } public static void registerAllExtensions( com.google.protobuf.ExtensionRegistry registry) { registerAllExtensions( (com.google.protobuf.ExtensionRegistryLite) registry); } public interface TestIntRequestOrBuilder extends // @@protoc_insertion_point(interface_extends:TestIntRequest) com.google.protobuf.MessageOrBuilder { /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ int getValue(); } /** * Protobuf type {@code TestIntRequest} */ public static final class TestIntRequest extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:TestIntRequest) TestIntRequestOrBuilder { // Use TestIntRequest.newBuilder() to construct. private TestIntRequest(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) { super(builder); } private TestIntRequest() { value_ = 0; } @java.lang.Override public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } private TestIntRequest( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { this(); int mutable_bitField0_ = 0; try { boolean done = false; while (!done) { int tag = input.readTag(); switch (tag) { case 0: done = true; break; default: { if (!input.skipField(tag)) { done = true; } break; } case 8: { value_ = 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).setUnfinishedMessage(this); } finally { makeExtensionsImmutable(); } } public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.grpc.service.TestIntMessage.internal_static_TestIntRequest_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.grpc.service.TestIntMessage.internal_static_TestIntRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( com.grpc.service.TestIntMessage.TestIntRequest.class, com.grpc.service.TestIntMessage.TestIntRequest.Builder.class); } public static final int VALUE_FIELD_NUMBER = 1; private int value_; /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public int getValue() { return value_; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; memoizedIsInitialized = 1; return true; } public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (value_ != 0) { output.writeInt32(1, value_); } } public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (value_ != 0) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(1, value_); } memoizedSize = size; return size; } private static final long serialVersionUID = 0L; @java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.grpc.service.TestIntMessage.TestIntRequest)) { return super.equals(obj); } com.grpc.service.TestIntMessage.TestIntRequest other = (com.grpc.service.TestIntMessage.TestIntRequest) obj; boolean result = true; result = result && (getValue() == other.getValue()); return result; } @java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); hash = (37 * hash) + VALUE_FIELD_NUMBER; hash = (53 * hash) + getValue(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntRequest parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } public static com.grpc.service.TestIntMessage.TestIntRequest parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.grpc.service.TestIntMessage.TestIntRequest parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } public static Builder newBuilder(com.grpc.service.TestIntMessage.TestIntRequest prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() { return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); } @java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /** * Protobuf type {@code TestIntRequest} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements // @@protoc_insertion_point(builder_implements:TestIntRequest) com.grpc.service.TestIntMessage.TestIntRequestOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.grpc.service.TestIntMessage.internal_static_TestIntRequest_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.grpc.service.TestIntMessage.internal_static_TestIntRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( com.grpc.service.TestIntMessage.TestIntRequest.class, com.grpc.service.TestIntMessage.TestIntRequest.Builder.class); } // Construct using com.grpc.service.TestIntMessage.TestIntRequest.newBuilder() private Builder() { maybeForceBuilderInitialization(); } private Builder( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessageV3 .alwaysUseFieldBuilders) { } } public Builder clear() { super.clear(); value_ = 0; return this; } public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return com.grpc.service.TestIntMessage.internal_static_TestIntRequest_descriptor; } public com.grpc.service.TestIntMessage.TestIntRequest getDefaultInstanceForType() { return com.grpc.service.TestIntMessage.TestIntRequest.getDefaultInstance(); } public com.grpc.service.TestIntMessage.TestIntRequest build() { com.grpc.service.TestIntMessage.TestIntRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; } public com.grpc.service.TestIntMessage.TestIntRequest buildPartial() { com.grpc.service.TestIntMessage.TestIntRequest result = new com.grpc.service.TestIntMessage.TestIntRequest(this); result.value_ = value_; onBuilt(); return result; } public Builder clone() { return (Builder) super.clone(); } public Builder setField( com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { return (Builder) super.setField(field, value); } public Builder clearField( com.google.protobuf.Descriptors.FieldDescriptor field) { return (Builder) super.clearField(field); } public Builder clearOneof( com.google.protobuf.Descriptors.OneofDescriptor oneof) { return (Builder) super.clearOneof(oneof); } public Builder setRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { return (Builder) super.setRepeatedField(field, index, value); } public Builder addRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { return (Builder) super.addRepeatedField(field, value); } public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.grpc.service.TestIntMessage.TestIntRequest) { return mergeFrom((com.grpc.service.TestIntMessage.TestIntRequest)other); } else { super.mergeFrom(other); return this; } } public Builder mergeFrom(com.grpc.service.TestIntMessage.TestIntRequest other) { if (other == com.grpc.service.TestIntMessage.TestIntRequest.getDefaultInstance()) return this; if (other.getValue() != 0) { setValue(other.getValue()); } onChanged(); return this; } public final boolean isInitialized() { return true; } public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { com.grpc.service.TestIntMessage.TestIntRequest parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.grpc.service.TestIntMessage.TestIntRequest) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; } private int value_ ; /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public int getValue() { return value_; } /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public Builder setValue(int value) { value_ = value; onChanged(); return this; } /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public Builder clearValue() { value_ = 0; onChanged(); return this; } public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; } public final Builder mergeUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; } // @@protoc_insertion_point(builder_scope:TestIntRequest) } // @@protoc_insertion_point(class_scope:TestIntRequest) private static final com.grpc.service.TestIntMessage.TestIntRequest DEFAULT_INSTANCE; static { DEFAULT_INSTANCE = new com.grpc.service.TestIntMessage.TestIntRequest(); } public static com.grpc.service.TestIntMessage.TestIntRequest getDefaultInstance() { return DEFAULT_INSTANCE; } private static final com.google.protobuf.Parser<TestIntRequest> PARSER = new com.google.protobuf.AbstractParser<TestIntRequest>() { public TestIntRequest parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return new TestIntRequest(input, extensionRegistry); } }; public static com.google.protobuf.Parser<TestIntRequest> parser() { return PARSER; } @java.lang.Override public com.google.protobuf.Parser<TestIntRequest> getParserForType() { return PARSER; } public com.grpc.service.TestIntMessage.TestIntRequest getDefaultInstanceForType() { return DEFAULT_INSTANCE; } } public interface TestIntResponseOrBuilder extends // @@protoc_insertion_point(interface_extends:TestIntResponse) com.google.protobuf.MessageOrBuilder { /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ int getValue(); } /** * Protobuf type {@code TestIntResponse} */ public static final class TestIntResponse extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:TestIntResponse) TestIntResponseOrBuilder { // Use TestIntResponse.newBuilder() to construct. private TestIntResponse(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) { super(builder); } private TestIntResponse() { value_ = 0; } @java.lang.Override public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } private TestIntResponse( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { this(); int mutable_bitField0_ = 0; try { boolean done = false; while (!done) { int tag = input.readTag(); switch (tag) { case 0: done = true; break; default: { if (!input.skipField(tag)) { done = true; } break; } case 8: { value_ = 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).setUnfinishedMessage(this); } finally { makeExtensionsImmutable(); } } public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.grpc.service.TestIntMessage.internal_static_TestIntResponse_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.grpc.service.TestIntMessage.internal_static_TestIntResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( com.grpc.service.TestIntMessage.TestIntResponse.class, com.grpc.service.TestIntMessage.TestIntResponse.Builder.class); } public static final int VALUE_FIELD_NUMBER = 1; private int value_; /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public int getValue() { return value_; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; memoizedIsInitialized = 1; return true; } public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (value_ != 0) { output.writeInt32(1, value_); } } public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (value_ != 0) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(1, value_); } memoizedSize = size; return size; } private static final long serialVersionUID = 0L; @java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.grpc.service.TestIntMessage.TestIntResponse)) { return super.equals(obj); } com.grpc.service.TestIntMessage.TestIntResponse other = (com.grpc.service.TestIntMessage.TestIntResponse) obj; boolean result = true; result = result && (getValue() == other.getValue()); return result; } @java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); hash = (37 * hash) + VALUE_FIELD_NUMBER; hash = (53 * hash) + getValue(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntResponse parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } public static com.grpc.service.TestIntMessage.TestIntResponse parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.grpc.service.TestIntMessage.TestIntResponse parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } public static Builder newBuilder(com.grpc.service.TestIntMessage.TestIntResponse prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() { return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); } @java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /** * Protobuf type {@code TestIntResponse} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements // @@protoc_insertion_point(builder_implements:TestIntResponse) com.grpc.service.TestIntMessage.TestIntResponseOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.grpc.service.TestIntMessage.internal_static_TestIntResponse_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.grpc.service.TestIntMessage.internal_static_TestIntResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( com.grpc.service.TestIntMessage.TestIntResponse.class, com.grpc.service.TestIntMessage.TestIntResponse.Builder.class); } // Construct using com.grpc.service.TestIntMessage.TestIntResponse.newBuilder() private Builder() { maybeForceBuilderInitialization(); } private Builder( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessageV3 .alwaysUseFieldBuilders) { } } public Builder clear() { super.clear(); value_ = 0; return this; } public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return com.grpc.service.TestIntMessage.internal_static_TestIntResponse_descriptor; } public com.grpc.service.TestIntMessage.TestIntResponse getDefaultInstanceForType() { return com.grpc.service.TestIntMessage.TestIntResponse.getDefaultInstance(); } public com.grpc.service.TestIntMessage.TestIntResponse build() { com.grpc.service.TestIntMessage.TestIntResponse result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; } public com.grpc.service.TestIntMessage.TestIntResponse buildPartial() { com.grpc.service.TestIntMessage.TestIntResponse result = new com.grpc.service.TestIntMessage.TestIntResponse(this); result.value_ = value_; onBuilt(); return result; } public Builder clone() { return (Builder) super.clone(); } public Builder setField( com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { return (Builder) super.setField(field, value); } public Builder clearField( com.google.protobuf.Descriptors.FieldDescriptor field) { return (Builder) super.clearField(field); } public Builder clearOneof( com.google.protobuf.Descriptors.OneofDescriptor oneof) { return (Builder) super.clearOneof(oneof); } public Builder setRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { return (Builder) super.setRepeatedField(field, index, value); } public Builder addRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { return (Builder) super.addRepeatedField(field, value); } public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.grpc.service.TestIntMessage.TestIntResponse) { return mergeFrom((com.grpc.service.TestIntMessage.TestIntResponse)other); } else { super.mergeFrom(other); return this; } } public Builder mergeFrom(com.grpc.service.TestIntMessage.TestIntResponse other) { if (other == com.grpc.service.TestIntMessage.TestIntResponse.getDefaultInstance()) return this; if (other.getValue() != 0) { setValue(other.getValue()); } onChanged(); return this; } public final boolean isInitialized() { return true; } public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { com.grpc.service.TestIntMessage.TestIntResponse parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.grpc.service.TestIntMessage.TestIntResponse) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; } private int value_ ; /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public int getValue() { return value_; } /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public Builder setValue(int value) { value_ = value; onChanged(); return this; } /** * <pre> *optional * </pre> * * <code>optional int32 value = 1;</code> */ public Builder clearValue() { value_ = 0; onChanged(); return this; } public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; } public final Builder mergeUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; } // @@protoc_insertion_point(builder_scope:TestIntResponse) } // @@protoc_insertion_point(class_scope:TestIntResponse) private static final com.grpc.service.TestIntMessage.TestIntResponse DEFAULT_INSTANCE; static { DEFAULT_INSTANCE = new com.grpc.service.TestIntMessage.TestIntResponse(); } public static com.grpc.service.TestIntMessage.TestIntResponse getDefaultInstance() { return DEFAULT_INSTANCE; } private static final com.google.protobuf.Parser<TestIntResponse> PARSER = new com.google.protobuf.AbstractParser<TestIntResponse>() { public TestIntResponse parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return new TestIntResponse(input, extensionRegistry); } }; public static com.google.protobuf.Parser<TestIntResponse> parser() { return PARSER; } @java.lang.Override public com.google.protobuf.Parser<TestIntResponse> getParserForType() { return PARSER; } public com.grpc.service.TestIntMessage.TestIntResponse getDefaultInstanceForType() { return DEFAULT_INSTANCE; } } private static final com.google.protobuf.Descriptors.Descriptor internal_static_TestIntRequest_descriptor; private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_TestIntRequest_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_TestIntResponse_descriptor; private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_TestIntResponse_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; } private static com.google.protobuf.Descriptors.FileDescriptor descriptor; static { java.lang.String[] descriptorData = { "\n\024TestIntMessage.proto\"\037\n\016TestIntRequest" + "\022\r\n\005value\030\001 \001(\005\" \n\017TestIntResponse\022\r\n\005va" + "lue\030\001 \001(\005B\022\n\020com.grpc.serviceb\006proto3" }; 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; return null; } }; com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { }, assigner); internal_static_TestIntRequest_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_TestIntRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_TestIntRequest_descriptor, new java.lang.String[] { "Value", }); internal_static_TestIntResponse_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_TestIntResponse_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_TestIntResponse_descriptor, new java.lang.String[] { "Value", }); } // @@protoc_insertion_point(outer_class_scope) }
public static void main(String[] args) throws IOException { TestIntMessage.TestIntRequest.Builder requestBuilder1 = TestIntMessage.TestIntRequest.newBuilder(); requestBuilder1.setValue(1234); TestIntMessage.TestIntRequest request1 = requestBuilder1.build(); ByteArrayOutputStream os = new ByteArrayOutputStream(); request1.writeTo(os); InputStream is = new ByteArrayInputStream(os.toByteArray()); TestIntMessage.TestIntRequest request2 = TestIntMessage.TestIntRequest.parseFrom(is); System.out.println(request1); System.out.println(request2); System.out.println("request value1: " + request1.getValue() + ", request value2: " + request2.getValue()); TestIntMessage.TestIntResponse.Builder responseBuilder1 = TestIntMessage.TestIntResponse.newBuilder(); responseBuilder1.setValue(5678); TestIntMessage.TestIntResponse response1 = responseBuilder1.build(); os = new ByteArrayOutputStream(); response1.writeTo(os); is = new ByteArrayInputStream(os.toByteArray()); TestIntMessage.TestIntResponse response2 = TestIntMessage.TestIntResponse.parseFrom(is); System.out.println(response1); System.out.println(response2); System.out.println("response value1: " + response1.getValue() + ", response value2: " + response2.getValue()); }
value: 1234 value: 1234 request value1: 1234, request value2: 1234 value: 5678 value: 5678 response value1: 5678, response value2: 5678
相关推荐
标题中的"protoc-3.14.0-win64_Protoc_"指的是Protocol Buffers(简称Protobuf)的编译器protoc的Windows 64位版本,版本号为3.14.0。Protobuf是Google开发的一种数据序列化协议,用于结构化数据的编码和解码,类似...
在Java环境下使用gRPC时,需要对.proto文件进行编译,生成服务端和客户端的存根代码,这正是`protoc`和`protoc-gen-grpc-java`工具的作用。 `protoc`是Protocol Buffers的编译器,它能够读取.proto文件并生成对应...
标题中的"protoc.exe AND protoc-gen-go.exe.rar"表明这是一个包含了两个关键工具的压缩包:protoc.exe和protoc-gen-go.exe。这两个工具在IT领域,尤其是开发使用Protocol Buffers(protobuf)的项目时非常关键。 ...
在IT行业中,`protoc-gen-go.exe` 和 `protoc.exe` 是两个非常重要的工具,特别是在Golang(Go语言)的开发环境中。这两个工具与Protocol Buffers(简称protobuf)紧密相关,protobuf是一种高效的数据序列化协议,由...
protoc-3.11.0各个版本的下载,包括WIN 32,64,MAC,LINUX的各个版本 protoc-3.11.0-win64.zip protoc-3.11.0-win32.zip protoc-3.11.0-osx-x86_32.zip protoc-3.11.0-linux-x86_64.zip protoc-3.11.0-linux-x86_...
标题中的"protoc-3.17.0-win64"指的是Google的Protocol Buffers(简称protobuf)编译器的Windows 64位版本,版本号为3.17.0。protobuf是一种数据序列化协议,它允许开发者定义数据结构,并在各种数据平台之间进行...
Linux版本的`protoc`是Google开源的Protocol Buffers(简称protobuf)编译器在Linux操作系统上的实现。Protocol Buffers是一种高效的数据序列化协议,它允许开发者定义数据结构,然后生成能够在各种编程语言中轻松...
标题“protoc-window-release-21.2”指的是Google开源项目Protocol Buffers(简称protobuf)的一个特定版本,即v21.2的Windows发行版。Protocol Buffers是一种数据序列化协议,它允许开发者定义数据结构,然后将这些...
标题“protoc-3.17.3-win64”指的是Protocol Buffers(简称protobuf)编译器的Windows 64位版本,版本号为3.17.3。Protocol Buffers是Google开发的一种数据序列化协议,它允许开发者定义数据结构,并在各种数据平台...
标题中的"protoc-3.4.0-win32.zip"指的是Protocol Buffers(简称protobuf)的编译器protoc的Windows 32位版本,版本号为3.4.0。protobuf是Google开发的一种数据序列化协议,类似于XML或JSON,但更高效且紧凑,常用于...
compiler (protoc). This binary is intended for users who want to use Protocol Buffers in languages other than C++ but do not want to compile protoc themselves. To install, simply place this binary ...
标题中的"protoc-3.19.1-linux-x86_64.zip"指的是Google开源的Protocol Buffers(简称protobuf)编译器protoc的3.19.1版本,针对Linux操作系统且适用于x86_64(64位)架构的安装包。protobuf是一种高效的数据序列化...
标题中的"protoc.exe-2.6-win64.rar"是一个压缩文件,它包含了protoc.exe的2.6版本,适用于Windows 64位操作系统。protoc是Protocol Buffers(简称protobuf)的一个重要组件,protobuf是由Google开发的一种数据序列...
标题中的"protoc-3.5.0-win32.zip"指的是Protocol Buffers(简称protobuf)的编译器protoc的3.5.0版本,适用于Windows 32位操作系统。Protocol Buffers是由Google开发的一种数据序列化协议,用于结构化数据的序列化...
标题中的"protoc-2.5.0完整版"指的是Protocol Buffers(简称protobuf)的编译器protoc的一个特定版本,2.5.0。Protocol Buffers是Google开发的一种数据序列化协议,用于结构化数据的编码和解码,类似于XML或JSON,但...
标题“protoc-22.2-win64”指的是Google的Protocol Buffers(protobuf)编译器protoc的Windows 64位版本2.2.2。Protocol Buffers是一种序列化协议,允许开发者定义数据结构,并能高效地在各种数据平台之间交换这些...
**protoc工具详解** 在软件开发中,通信协议和数据序列化是至关重要的环节,而Protocol Buffers(简称protobuf)正是Google推出的一种高效的数据序列化协议。protoc是protobuf的核心工具,它能够将.proto文件转换为...
标题中的"protoc2.5版本"指的是Google开源的Protocol Buffers(简称protobuf)的编译器protoc的2.5版本。Protocol Buffers是一种数据序列化协议,它允许开发者定义数据结构,然后生成能够在各种数据平台之间交换这些...
标题“protoc-3.8.0-win64.rar”指的是一个针对Windows 64位操作系统的Protobuf编译器的压缩包,其中包含了protoc工具的3.8.0版本。Protobuf(Protocol Buffers)是Google开发的一种数据序列化协议,用于高效地存储...
标题中的"protoc"是Google开源的Protocol Buffers(简称protobuf)的核心编译器,它用于将结构化数据序列化,类似于XML、JSON等数据格式,但更小、更快、更简单。protobuf提供了语言中立、平台中立的机制来序列化...