最近新换了工作,之前都没有接触过protobuf ,最近做了一点研究
在maven中generate-protobuf有两种方法
直接上代码,不废话
1.pom.xml
dependencies> <dependency> <groupId>com.googlecode.protobuf-java-formatgroupId> <artifactId>protobuf-java-formatartifactId> <version>1.2version> dependency> <dependency> <groupId>com.google.protobufgroupId> <artifactId>protobuf-javaartifactId> <version>2.6.1version> <scope>compilescope> <optional>trueoptional> dependency> dependencies>
<build> <plugins> <plugin> <groupId>com.google.protobuf.toolsgroupId> <artifactId>maven-protoc-pluginartifactId> <version>1.1.0version> <executions> <execution> <id>generate-sourcesid> <goals> <goal>compilegoal> goals> <phase>generate-sourcesphase> <configuration> <protoSourceRoot>${basedir}/src/main/proto/protoSourceRoot> <includes> <param>**/*.protoparam> includes> configuration> execution> executions> <configuration> <protocExecutable>D:/software/protoc-3.5.1-win32/bin/protoc.exeprotocExecutable><!–protoc.exe文件地址,使用2.5版本–> configuration> plugin> plugins> build>2.proto文件
option java_package = "com.bjzw.proto"; option java_outer_classname = "UserProto"; message User { int64 id = 1; string name = 2; message PhoneNumber { string number = 1; } repeated PhoneNumber phone = 4; }3.对应的写一个测试类
package com.bjzw.proto; import java.io.IOException; public class ProtoTest { public static void main(String[] args) { String protoFile = "user.proto";// String strCmd = "D:/software/protoc-3.5.1-win32/bin/protoc.exe --java_out=./src/main/java ./src/main/resources/"+ protoFile; try { Runtime.getRuntime().exec(strCmd); } catch (IOException e) { e.printStackTrace(); }//通过执行cmd命令调用protoc.exe程序 } }执行就可以获取到对应的Java文件
// Generated by the protocol buffer compiler. DO NOT EDIT! // source: src/main/resources/user.proto package com.bjzw.proto; public final class UserProto { private UserProto() {} 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 UserOrBuilder extends // @@protoc_insertion_point(interface_extends:User) com.google.protobuf.MessageOrBuilder { /** *废话不想说,直接看代码,还有一种方式,正在研究,后续会继续为大家讲解int64 id = 1; */ long getId(); /** *
string name = 2; */ java.lang.String getName(); /** *
string name = 2; */ com.google.protobuf.ByteString getNameBytes(); /** *
repeated .User.PhoneNumber phone = 4; */ java.util.List
getPhoneList(); /** * repeated .User.PhoneNumber phone = 4; */ com.bjzw.proto.UserProto.User.PhoneNumber getPhone(int index); /** *
repeated .User.PhoneNumber phone = 4; */ int getPhoneCount(); /** *
repeated .User.PhoneNumber phone = 4; */ java.util.List extends com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder> getPhoneOrBuilderList(); /** *
repeated .User.PhoneNumber phone = 4; */ com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder getPhoneOrBuilder( int index); } /** * Protobuf type {@code User} */ public static final class User extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:User) UserOrBuilder { private static final long serialVersionUID = 0L; // Use User.newBuilder() to construct. private User(com.google.protobuf.GeneratedMessageV3.Builder> builder) { super(builder); } private User() { id_ = 0L; name_ = ""; phone_ = java.util.Collections.emptyList(); } @java.lang.Override public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return this.unknownFields; } private User( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { this(); if (extensionRegistry == null) { throw new java.lang.NullPointerException(); } 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 (!parseUnknownFieldProto3( input, unknownFields, extensionRegistry, tag)) { done = true; } break; } case 8: { id_ = input.readInt64(); break; } case 18: { java.lang.String s = input.readStringRequireUtf8(); name_ = s; break; } case 34: { if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { phone_ = new java.util.ArrayList
(); mutable_bitField0_ |= 0x00000004; } phone_.add( input.readMessage(com.bjzw.proto.UserProto.User.PhoneNumber.parser(), extensionRegistry)); 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 { if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { phone_ = java.util.Collections.unmodifiableList(phone_); } this.unknownFields = unknownFields.build(); makeExtensionsImmutable(); } } public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.bjzw.proto.UserProto.internal_static_User_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.bjzw.proto.UserProto.internal_static_User_fieldAccessorTable .ensureFieldAccessorsInitialized( com.bjzw.proto.UserProto.User.class, com.bjzw.proto.UserProto.User.Builder.class); } public interface PhoneNumberOrBuilder extends // @@protoc_insertion_point(interface_extends:User.PhoneNumber) com.google.protobuf.MessageOrBuilder { /** * string number = 1; */ java.lang.String getNumber(); /** *
string number = 1; */ com.google.protobuf.ByteString getNumberBytes(); } /** * Protobuf type {@code User.PhoneNumber} */ public static final class PhoneNumber extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:User.PhoneNumber) PhoneNumberOrBuilder { private static final long serialVersionUID = 0L; // Use PhoneNumber.newBuilder() to construct. private PhoneNumber(com.google.protobuf.GeneratedMessageV3.Builder> builder) { super(builder); } private PhoneNumber() { number_ = ""; } @java.lang.Override public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return this.unknownFields; } private PhoneNumber( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { this(); if (extensionRegistry == null) { throw new java.lang.NullPointerException(); } 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 (!parseUnknownFieldProto3( input, unknownFields, extensionRegistry, tag)) { done = true; } break; } case 10: { java.lang.String s = input.readStringRequireUtf8(); number_ = s; 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 { this.unknownFields = unknownFields.build(); makeExtensionsImmutable(); } } public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.bjzw.proto.UserProto.internal_static_User_PhoneNumber_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.bjzw.proto.UserProto.internal_static_User_PhoneNumber_fieldAccessorTable .ensureFieldAccessorsInitialized( com.bjzw.proto.UserProto.User.PhoneNumber.class, com.bjzw.proto.UserProto.User.PhoneNumber.Builder.class); } public static final int NUMBER_FIELD_NUMBER = 1; private volatile java.lang.Object number_; /** *
string number = 1; */ public java.lang.String getNumber() { java.lang.Object ref = number_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); number_ = s; return s; } } /** *
string number = 1; */ public com.google.protobuf.ByteString getNumberBytes() { java.lang.Object ref = number_; if (ref instanceof java.lang.String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); number_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } 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 (!getNumberBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, number_); } unknownFields.writeTo(output); } public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (!getNumberBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, number_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; } @java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.bjzw.proto.UserProto.User.PhoneNumber)) { return super.equals(obj); } com.bjzw.proto.UserProto.User.PhoneNumber other = (com.bjzw.proto.UserProto.User.PhoneNumber) obj; boolean result = true; result = result && getNumber() .equals(other.getNumber()); result = result && unknownFields.equals(other.unknownFields); return result; } @java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NUMBER_FIELD_NUMBER; hash = (53 * hash) + getNumber().hashCode(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom( java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom( java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.bjzw.proto.UserProto.User.PhoneNumber parseFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.bjzw.proto.UserProto.User.PhoneNumber 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.bjzw.proto.UserProto.User.PhoneNumber parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } public static com.bjzw.proto.UserProto.User.PhoneNumber 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.bjzw.proto.UserProto.User.PhoneNumber parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.bjzw.proto.UserProto.User.PhoneNumber 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.bjzw.proto.UserProto.User.PhoneNumber 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 User.PhoneNumber} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder
implements // @@protoc_insertion_point(builder_implements:User.PhoneNumber) com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.bjzw.proto.UserProto.internal_static_User_PhoneNumber_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.bjzw.proto.UserProto.internal_static_User_PhoneNumber_fieldAccessorTable .ensureFieldAccessorsInitialized( com.bjzw.proto.UserProto.User.PhoneNumber.class, com.bjzw.proto.UserProto.User.PhoneNumber.Builder.class); } // Construct using com.bjzw.proto.UserProto.User.PhoneNumber.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(); number_ = ""; return this; } public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return com.bjzw.proto.UserProto.internal_static_User_PhoneNumber_descriptor; } public com.bjzw.proto.UserProto.User.PhoneNumber getDefaultInstanceForType() { return com.bjzw.proto.UserProto.User.PhoneNumber.getDefaultInstance(); } public com.bjzw.proto.UserProto.User.PhoneNumber build() { com.bjzw.proto.UserProto.User.PhoneNumber result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; } public com.bjzw.proto.UserProto.User.PhoneNumber buildPartial() { com.bjzw.proto.UserProto.User.PhoneNumber result = new com.bjzw.proto.UserProto.User.PhoneNumber(this); result.number_ = number_; onBuilt(); return result; } public Builder clone() { return (Builder) super.clone(); } public Builder setField( com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.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, java.lang.Object value) { return (Builder) super.setRepeatedField(field, index, value); } public Builder addRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { return (Builder) super.addRepeatedField(field, value); } public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.bjzw.proto.UserProto.User.PhoneNumber) { return mergeFrom((com.bjzw.proto.UserProto.User.PhoneNumber)other); } else { super.mergeFrom(other); return this; } } public Builder mergeFrom(com.bjzw.proto.UserProto.User.PhoneNumber other) { if (other == com.bjzw.proto.UserProto.User.PhoneNumber.getDefaultInstance()) return this; if (!other.getNumber().isEmpty()) { number_ = other.number_; onChanged(); } this.mergeUnknownFields(other.unknownFields); 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.bjzw.proto.UserProto.User.PhoneNumber parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.bjzw.proto.UserProto.User.PhoneNumber) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; } private java.lang.Object number_ = ""; /** * string number = 1; */ public java.lang.String getNumber() { java.lang.Object ref = number_; if (!(ref instanceof java.lang.String)) { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); number_ = s; return s; } else { return (java.lang.String) ref; } } /** *
string number = 1; */ public com.google.protobuf.ByteString getNumberBytes() { java.lang.Object ref = number_; if (ref instanceof String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); number_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } /** *
string number = 1; */ public Builder setNumber( java.lang.String value) { if (value == null) { throw new NullPointerException(); } number_ = value; onChanged(); return this; } /** *
string number = 1; */ public Builder clearNumber() { number_ = getDefaultInstance().getNumber(); onChanged(); return this; } /** *
string number = 1; */ public Builder setNumberBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); number_ = value; onChanged(); return this; } public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFieldsProto3(unknownFields); } public final Builder mergeUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return super.mergeUnknownFields(unknownFields); } // @@protoc_insertion_point(builder_scope:User.PhoneNumber) } // @@protoc_insertion_point(class_scope:User.PhoneNumber) private static final com.bjzw.proto.UserProto.User.PhoneNumber DEFAULT_INSTANCE; static { DEFAULT_INSTANCE = new com.bjzw.proto.UserProto.User.PhoneNumber(); } public static com.bjzw.proto.UserProto.User.PhoneNumber getDefaultInstance() { return DEFAULT_INSTANCE; } private static final com.google.protobuf.Parser
PARSER = new com.google.protobuf.AbstractParser () { public PhoneNumber parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return new PhoneNumber(input, extensionRegistry); } }; public static com.google.protobuf.Parser parser() { return PARSER; } @java.lang.Override public com.google.protobuf.Parser getParserForType() { return PARSER; } public com.bjzw.proto.UserProto.User.PhoneNumber getDefaultInstanceForType() { return DEFAULT_INSTANCE; } } private int bitField0_; public static final int ID_FIELD_NUMBER = 1; private long id_; /** * int64 id = 1; */ public long getId() { return id_; } public static final int NAME_FIELD_NUMBER = 2; private volatile java.lang.Object name_; /** *
string name = 2; */ public java.lang.String getName() { java.lang.Object ref = name_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); name_ = s; return s; } } /** *
string name = 2; */ public com.google.protobuf.ByteString getNameBytes() { java.lang.Object ref = name_; if (ref instanceof java.lang.String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); name_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } public static final int PHONE_FIELD_NUMBER = 4; private java.util.List
phone_; /** * repeated .User.PhoneNumber phone = 4; */ public java.util.List
getPhoneList() { return phone_; } /** * repeated .User.PhoneNumber phone = 4; */ public java.util.List extends com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder> getPhoneOrBuilderList() { return phone_; } /** *
repeated .User.PhoneNumber phone = 4; */ public int getPhoneCount() { return phone_.size(); } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumber getPhone(int index) { return phone_.get(index); } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder getPhoneOrBuilder( int index) { return phone_.get(index); } 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 (id_ != 0L) { output.writeInt64(1, id_); } if (!getNameBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_); } for (int i = 0; i < phone_.size(); i++) { output.writeMessage(4, phone_.get(i)); } unknownFields.writeTo(output); } public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (id_ != 0L) { size += com.google.protobuf.CodedOutputStream .computeInt64Size(1, id_); } if (!getNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_); } for (int i = 0; i < phone_.size(); i++) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(4, phone_.get(i)); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; } @java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.bjzw.proto.UserProto.User)) { return super.equals(obj); } com.bjzw.proto.UserProto.User other = (com.bjzw.proto.UserProto.User) obj; boolean result = true; result = result && (getId() == other.getId()); result = result && getName() .equals(other.getName()); result = result && getPhoneList() .equals(other.getPhoneList()); result = result && unknownFields.equals(other.unknownFields); return result; } @java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + ID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getId()); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); if (getPhoneCount() > 0) { hash = (37 * hash) + PHONE_FIELD_NUMBER; hash = (53 * hash) + getPhoneList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; } public static com.bjzw.proto.UserProto.User parseFrom( java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.bjzw.proto.UserProto.User parseFrom( java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.bjzw.proto.UserProto.User parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.bjzw.proto.UserProto.User parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.bjzw.proto.UserProto.User parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } public static com.bjzw.proto.UserProto.User parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } public static com.bjzw.proto.UserProto.User parseFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.bjzw.proto.UserProto.User 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.bjzw.proto.UserProto.User parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } public static com.bjzw.proto.UserProto.User 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.bjzw.proto.UserProto.User parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input); } public static com.bjzw.proto.UserProto.User 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.bjzw.proto.UserProto.User 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 User} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder
implements // @@protoc_insertion_point(builder_implements:User) com.bjzw.proto.UserProto.UserOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return com.bjzw.proto.UserProto.internal_static_User_descriptor; } protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return com.bjzw.proto.UserProto.internal_static_User_fieldAccessorTable .ensureFieldAccessorsInitialized( com.bjzw.proto.UserProto.User.class, com.bjzw.proto.UserProto.User.Builder.class); } // Construct using com.bjzw.proto.UserProto.User.newBuilder() private Builder() { maybeForceBuilderInitialization(); } private Builder( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessageV3 .alwaysUseFieldBuilders) { getPhoneFieldBuilder(); } } public Builder clear() { super.clear(); id_ = 0L; name_ = ""; if (phoneBuilder_ == null) { phone_ = java.util.Collections.emptyList(); bitField0_ = (bitField0_ & ~0x00000004); } else { phoneBuilder_.clear(); } return this; } public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return com.bjzw.proto.UserProto.internal_static_User_descriptor; } public com.bjzw.proto.UserProto.User getDefaultInstanceForType() { return com.bjzw.proto.UserProto.User.getDefaultInstance(); } public com.bjzw.proto.UserProto.User build() { com.bjzw.proto.UserProto.User result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; } public com.bjzw.proto.UserProto.User buildPartial() { com.bjzw.proto.UserProto.User result = new com.bjzw.proto.UserProto.User(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; result.id_ = id_; result.name_ = name_; if (phoneBuilder_ == null) { if (((bitField0_ & 0x00000004) == 0x00000004)) { phone_ = java.util.Collections.unmodifiableList(phone_); bitField0_ = (bitField0_ & ~0x00000004); } result.phone_ = phone_; } else { result.phone_ = phoneBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; } public Builder clone() { return (Builder) super.clone(); } public Builder setField( com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.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, java.lang.Object value) { return (Builder) super.setRepeatedField(field, index, value); } public Builder addRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { return (Builder) super.addRepeatedField(field, value); } public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.bjzw.proto.UserProto.User) { return mergeFrom((com.bjzw.proto.UserProto.User)other); } else { super.mergeFrom(other); return this; } } public Builder mergeFrom(com.bjzw.proto.UserProto.User other) { if (other == com.bjzw.proto.UserProto.User.getDefaultInstance()) return this; if (other.getId() != 0L) { setId(other.getId()); } if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (phoneBuilder_ == null) { if (!other.phone_.isEmpty()) { if (phone_.isEmpty()) { phone_ = other.phone_; bitField0_ = (bitField0_ & ~0x00000004); } else { ensurePhoneIsMutable(); phone_.addAll(other.phone_); } onChanged(); } } else { if (!other.phone_.isEmpty()) { if (phoneBuilder_.isEmpty()) { phoneBuilder_.dispose(); phoneBuilder_ = null; phone_ = other.phone_; bitField0_ = (bitField0_ & ~0x00000004); phoneBuilder_ = com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? getPhoneFieldBuilder() : null; } else { phoneBuilder_.addAllMessages(other.phone_); } } } this.mergeUnknownFields(other.unknownFields); 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.bjzw.proto.UserProto.User parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.bjzw.proto.UserProto.User) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; } private int bitField0_; private long id_ ; /** * int64 id = 1; */ public long getId() { return id_; } /** *
int64 id = 1; */ public Builder setId(long value) { id_ = value; onChanged(); return this; } /** *
int64 id = 1; */ public Builder clearId() { id_ = 0L; onChanged(); return this; } private java.lang.Object name_ = ""; /** *
string name = 2; */ public java.lang.String getName() { java.lang.Object ref = name_; if (!(ref instanceof java.lang.String)) { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); name_ = s; return s; } else { return (java.lang.String) ref; } } /** *
string name = 2; */ public com.google.protobuf.ByteString getNameBytes() { java.lang.Object ref = name_; if (ref instanceof String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); name_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } /** *
string name = 2; */ public Builder setName( java.lang.String value) { if (value == null) { throw new NullPointerException(); } name_ = value; onChanged(); return this; } /** *
string name = 2; */ public Builder clearName() { name_ = getDefaultInstance().getName(); onChanged(); return this; } /** *
string name = 2; */ public Builder setNameBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); name_ = value; onChanged(); return this; } private java.util.List
phone_ = java.util.Collections.emptyList(); private void ensurePhoneIsMutable() { if (!((bitField0_ & 0x00000004) == 0x00000004)) { phone_ = new java.util.ArrayList (phone_); bitField0_ |= 0x00000004; } } private com.google.protobuf.RepeatedFieldBuilderV3< com.bjzw.proto.UserProto.User.PhoneNumber, com.bjzw.proto.UserProto.User.PhoneNumber.Builder, com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder> phoneBuilder_; /** * repeated .User.PhoneNumber phone = 4; */ public java.util.List
getPhoneList() { if (phoneBuilder_ == null) { return java.util.Collections.unmodifiableList(phone_); } else { return phoneBuilder_.getMessageList(); } } /** * repeated .User.PhoneNumber phone = 4; */ public int getPhoneCount() { if (phoneBuilder_ == null) { return phone_.size(); } else { return phoneBuilder_.getCount(); } } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumber getPhone(int index) { if (phoneBuilder_ == null) { return phone_.get(index); } else { return phoneBuilder_.getMessage(index); } } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder setPhone( int index, com.bjzw.proto.UserProto.User.PhoneNumber value) { if (phoneBuilder_ == null) { if (value == null) { throw new NullPointerException(); } ensurePhoneIsMutable(); phone_.set(index, value); onChanged(); } else { phoneBuilder_.setMessage(index, value); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder setPhone( int index, com.bjzw.proto.UserProto.User.PhoneNumber.Builder builderForValue) { if (phoneBuilder_ == null) { ensurePhoneIsMutable(); phone_.set(index, builderForValue.build()); onChanged(); } else { phoneBuilder_.setMessage(index, builderForValue.build()); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder addPhone(com.bjzw.proto.UserProto.User.PhoneNumber value) { if (phoneBuilder_ == null) { if (value == null) { throw new NullPointerException(); } ensurePhoneIsMutable(); phone_.add(value); onChanged(); } else { phoneBuilder_.addMessage(value); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder addPhone( int index, com.bjzw.proto.UserProto.User.PhoneNumber value) { if (phoneBuilder_ == null) { if (value == null) { throw new NullPointerException(); } ensurePhoneIsMutable(); phone_.add(index, value); onChanged(); } else { phoneBuilder_.addMessage(index, value); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder addPhone( com.bjzw.proto.UserProto.User.PhoneNumber.Builder builderForValue) { if (phoneBuilder_ == null) { ensurePhoneIsMutable(); phone_.add(builderForValue.build()); onChanged(); } else { phoneBuilder_.addMessage(builderForValue.build()); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder addPhone( int index, com.bjzw.proto.UserProto.User.PhoneNumber.Builder builderForValue) { if (phoneBuilder_ == null) { ensurePhoneIsMutable(); phone_.add(index, builderForValue.build()); onChanged(); } else { phoneBuilder_.addMessage(index, builderForValue.build()); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder addAllPhone( java.lang.Iterable extends com.bjzw.proto.UserProto.User.PhoneNumber> values) { if (phoneBuilder_ == null) { ensurePhoneIsMutable(); com.google.protobuf.AbstractMessageLite.Builder.addAll( values, phone_); onChanged(); } else { phoneBuilder_.addAllMessages(values); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder clearPhone() { if (phoneBuilder_ == null) { phone_ = java.util.Collections.emptyList(); bitField0_ = (bitField0_ & ~0x00000004); onChanged(); } else { phoneBuilder_.clear(); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public Builder removePhone(int index) { if (phoneBuilder_ == null) { ensurePhoneIsMutable(); phone_.remove(index); onChanged(); } else { phoneBuilder_.remove(index); } return this; } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumber.Builder getPhoneBuilder( int index) { return getPhoneFieldBuilder().getBuilder(index); } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder getPhoneOrBuilder( int index) { if (phoneBuilder_ == null) { return phone_.get(index); } else { return phoneBuilder_.getMessageOrBuilder(index); } } /** *
repeated .User.PhoneNumber phone = 4; */ public java.util.List extends com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder> getPhoneOrBuilderList() { if (phoneBuilder_ != null) { return phoneBuilder_.getMessageOrBuilderList(); } else { return java.util.Collections.unmodifiableList(phone_); } } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumber.Builder addPhoneBuilder() { return getPhoneFieldBuilder().addBuilder( com.bjzw.proto.UserProto.User.PhoneNumber.getDefaultInstance()); } /** *
repeated .User.PhoneNumber phone = 4; */ public com.bjzw.proto.UserProto.User.PhoneNumber.Builder addPhoneBuilder( int index) { return getPhoneFieldBuilder().addBuilder( index, com.bjzw.proto.UserProto.User.PhoneNumber.getDefaultInstance()); } /** *
repeated .User.PhoneNumber phone = 4; */ public java.util.List
getPhoneBuilderList() { return getPhoneFieldBuilder().getBuilderList(); } private com.google.protobuf.RepeatedFieldBuilderV3< com.bjzw.proto.UserProto.User.PhoneNumber, com.bjzw.proto.UserProto.User.PhoneNumber.Builder, com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder> getPhoneFieldBuilder() { if (phoneBuilder_ == null) { phoneBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< com.bjzw.proto.UserProto.User.PhoneNumber, com.bjzw.proto.UserProto.User.PhoneNumber.Builder, com.bjzw.proto.UserProto.User.PhoneNumberOrBuilder>( phone_, ((bitField0_ & 0x00000004) == 0x00000004), getParentForChildren(), isClean()); phone_ = null; } return phoneBuilder_; } public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFieldsProto3(unknownFields); } public final Builder mergeUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return super.mergeUnknownFields(unknownFields); } // @@protoc_insertion_point(builder_scope:User) } // @@protoc_insertion_point(class_scope:User) private static final com.bjzw.proto.UserProto.User DEFAULT_INSTANCE; static { DEFAULT_INSTANCE = new com.bjzw.proto.UserProto.User(); } public static com.bjzw.proto.UserProto.User getDefaultInstance() { return DEFAULT_INSTANCE; } private static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser () { public User parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return new User(input, extensionRegistry); } }; public static com.google.protobuf.Parser parser() { return PARSER; } @java.lang.Override public com.google.protobuf.Parser getParserForType() { return PARSER; } public com.bjzw.proto.UserProto.User getDefaultInstanceForType() { return DEFAULT_INSTANCE; } } private static final com.google.protobuf.Descriptors.Descriptor internal_static_User_descriptor; private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_User_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor internal_static_User_PhoneNumber_descriptor; private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_User_PhoneNumber_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\035src/main/resources/user.proto\"a\n\004User\022" + "\n\n\002id\030\001 \001(\003\022\014\n\004name\030\002 \001(\t\022 \n\005phone\030\004 \003(\013" + "2\021.User.PhoneNumber\032\035\n\013PhoneNumber\022\016\n\006nu" + "mber\030\001 \001(\tB\033\n\016com.bjzw.protoB\tUserProtob" + "\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_User_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_User_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_User_descriptor, new java.lang.String[] { "Id", "Name", "Phone", }); internal_static_User_PhoneNumber_descriptor = internal_static_User_descriptor.getNestedTypes().get(0); internal_static_User_PhoneNumber_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_User_PhoneNumber_descriptor, new java.lang.String[] { "Number", }); } // @@protoc_insertion_point(outer_class_scope) }