Java with Google protocol buffer

Connect with

Oracle Java

Google Protocol Buffer:
Why GPB(google protocol buffer):
We can consider and example and application perform some read/write operation in network. Each user write and read some standard information. So, now the problem occurs in serializable. Serialization and de-serialization is cpu intensive operation which consumes considerable amount of CPU. How we can serialized our application and get data from it.

Different Methods

1. Java Serialization Method: use default java Seralizable interface that will take care effectively.
When java serialization not : when such an architecture occur where different language perform read/write operation in that case it will not work.(ex. Python,nodejs,C++,C etc).
2. We can used serialized XML to solve above problem, that now days adopted by rest web service.
Disadvantage of this is inside that network it is little bit bulk and its is human readable formation.
In that case some encoding and decoding operation should perform by user.
3. Use some ad-hoc conversion technique resolve such type of problem.
Another way to solve the above problem is to user Google protocol buffer:

Let me demonstrate you how we can create a proto file and generate language specific code:-

  1. Step Create file having extension .proto file.
  2. Install protoc compiler as per the required version that is protoc.
  3. Now generate .proto to .java file.
protoc  - -java_out=C:\Users\SKY-O4DSol\Desktop\proto\ 
 --proto_path=C:\Users\SKY-O4DSol\Desktop\proto 
C:\Users\SKY-O4DSol\Desktop\proto\Employee.proto

Create proto file


option java_outer_classname = "EAddressBook";
message Employee {
  required string name =1;
  required int32  id   =2;
  enum PhoneType  {
     MOBILE =0;
     WORK   =1;
     HOME   =2;
  }
 message PhoneNumber {
   required string number=1;
   optional PhoneType  ptype = 2[default = HOME];
 }
 repeated PhoneNumber  phone=4;
 }
 message EmplyeeBook {
   repeated Employee emp =1;
 }

It generate .proto to .java file run command mentioned in step 3.

EAddressBook.java

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: Employee.proto

public final class EAddressBook {
  private EAddressBook() {}
  public static void registerAllExtensions(
      com.google.protobuf.ExtensionRegistry registry) {
  }
  public interface EmployeeOrBuilder
      extends com.google.protobuf.MessageOrBuilder {
    
    // required string name = 1;
    boolean hasName();
    String getName();
    
    // required int32 id = 2;
    boolean hasId();
    int getId();
    
    // repeated .Employee.PhoneNumber phone = 4;
    java.util.List 
        getPhoneList();
    EAddressBook.Employee.PhoneNumber getPhone(int index);
    int getPhoneCount();
    java.util.List 
        getPhoneOrBuilderList();
    EAddressBook.Employee.PhoneNumberOrBuilder getPhoneOrBuilder(
        int index);
  }
  public static final class Employee extends
      com.google.protobuf.GeneratedMessage
      implements EmployeeOrBuilder {
    // Use Employee.newBuilder() to construct.
    private Employee(Builder builder) {
      super(builder);
    }
    private Employee(boolean noInit) {}
    
    private static final Employee defaultInstance;
    public static Employee getDefaultInstance() {
      return defaultInstance;
    }
    
    public Employee getDefaultInstanceForType() {
      return defaultInstance;
    }
    
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return EAddressBook.internal_static_Employee_descriptor;
    }
    
    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return EAddressBook.internal_static_Employee_fieldAccessorTable;
    }
    
    public enum PhoneType
        implements com.google.protobuf.ProtocolMessageEnum {
      MOBILE(0, 0),
      WORK(1, 1),
      HOME(2, 2),
      ;
      
      public static final int MOBILE_VALUE = 0;
      public static final int WORK_VALUE = 1;
      public static final int HOME_VALUE = 2;
      
      
      public final int getNumber() { return value; }
      
      public static PhoneType valueOf(int value) {
        switch (value) {
          case 0: return MOBILE;
          case 1: return WORK;
          case 2: return HOME;
          default: return null;
        }
      }
      
      public static com.google.protobuf.Internal.EnumLiteMap
          internalGetValueMap() {
        return internalValueMap;
      }
      private static com.google.protobuf.Internal.EnumLiteMap
          internalValueMap =
            new com.google.protobuf.Internal.EnumLiteMap() {
              public PhoneType findValueByNumber(int number) {
                return PhoneType.valueOf(number);
              }
            };
      
      public final com.google.protobuf.Descriptors.EnumValueDescriptor
          getValueDescriptor() {
        return getDescriptor().getValues().get(index);
      }
      public final com.google.protobuf.Descriptors.EnumDescriptor
          getDescriptorForType() {
        return getDescriptor();
      }
      public static final com.google.protobuf.Descriptors.EnumDescriptor
          getDescriptor() {
        return EAddressBook.Employee.getDescriptor().getEnumTypes().get(0);
      }
      
      private static final PhoneType[] VALUES = {
        MOBILE, WORK, HOME, 
      };
      
      public static PhoneType valueOf(
          com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
        if (desc.getType() != getDescriptor()) {
          throw new java.lang.IllegalArgumentException(
            "EnumValueDescriptor is not for this type.");
        }
        return VALUES[desc.getIndex()];
      }
      
      private final int index;
      private final int value;
      
      private PhoneType(int index, int value) {
        this.index = index;
        this.value = value;
      }
      
      // @@protoc_insertion_point(enum_scope:Employee.PhoneType)
    }
    
    public interface PhoneNumberOrBuilder
        extends com.google.protobuf.MessageOrBuilder {
      
      // required string number = 1;
      boolean hasNumber();
      String getNumber();
      
      // optional .Employee.PhoneType ptype = 2 [default = HOME];
      boolean hasPtype();
      EAddressBook.Employee.PhoneType getPtype();
    }
    public static final class PhoneNumber extends
        com.google.protobuf.GeneratedMessage
        implements PhoneNumberOrBuilder {
      // Use PhoneNumber.newBuilder() to construct.
      private PhoneNumber(Builder builder) {
        super(builder);
      }
      private PhoneNumber(boolean noInit) {}
      
      private static final PhoneNumber defaultInstance;
      public static PhoneNumber getDefaultInstance() {
        return defaultInstance;
      }
      
      public PhoneNumber getDefaultInstanceForType() {
        return defaultInstance;
      }
      
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return EAddressBook.internal_static_Employee_PhoneNumber_descriptor;
      }
      
      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return EAddressBook.internal_static_Employee_PhoneNumber_fieldAccessorTable;
      }
      
      private int bitField0_;
      // required string number = 1;
      public static final int NUMBER_FIELD_NUMBER = 1;
      private java.lang.Object number_;
      public boolean hasNumber() {
        return ((bitField0_ & 0x00000001) == 0x00000001);
      }
      public String getNumber() {
        java.lang.Object ref = number_;
        if (ref instanceof String) {
          return (String) ref;
        } else {
          com.google.protobuf.ByteString bs = 
              (com.google.protobuf.ByteString) ref;
          String s = bs.toStringUtf8();
          if (com.google.protobuf.Internal.isValidUtf8(bs)) {
            number_ = s;
          }
          return s;
        }
      }
      private com.google.protobuf.ByteString getNumberBytes() {
        java.lang.Object ref = number_;
        if (ref instanceof String) {
          com.google.protobuf.ByteString b = 
              com.google.protobuf.ByteString.copyFromUtf8((String) ref);
          number_ = b;
          return b;
        } else {
          return (com.google.protobuf.ByteString) ref;
        }
      }
      
      // optional .Employee.PhoneType ptype = 2 [default = HOME];
      public static final int PTYPE_FIELD_NUMBER = 2;
      private EAddressBook.Employee.PhoneType ptype_;
      public boolean hasPtype() {
        return ((bitField0_ & 0x00000002) == 0x00000002);
      }
      public EAddressBook.Employee.PhoneType getPtype() {
        return ptype_;
      }
      
      private void initFields() {
        number_ = "";
        ptype_ = EAddressBook.Employee.PhoneType.HOME;
      }
      private byte memoizedIsInitialized = -1;
      public final boolean isInitialized() {
        byte isInitialized = memoizedIsInitialized;
        if (isInitialized != -1) return isInitialized == 1;
        
        if (!hasNumber()) {
          memoizedIsInitialized = 0;
          return false;
        }
        memoizedIsInitialized = 1;
        return true;
      }
      
      public void writeTo(com.google.protobuf.CodedOutputStream output)
                          throws java.io.IOException {
        getSerializedSize();
        if (((bitField0_ & 0x00000001) == 0x00000001)) {
          output.writeBytes(1, getNumberBytes());
        }
        if (((bitField0_ & 0x00000002) == 0x00000002)) {
          output.writeEnum(2, ptype_.getNumber());
        }
        getUnknownFields().writeTo(output);
      }
      
      private int memoizedSerializedSize = -1;
      public int getSerializedSize() {
        int size = memoizedSerializedSize;
        if (size != -1) return size;
      
        size = 0;
        if (((bitField0_ & 0x00000001) == 0x00000001)) {
          size += com.google.protobuf.CodedOutputStream
            .computeBytesSize(1, getNumberBytes());
        }
        if (((bitField0_ & 0x00000002) == 0x00000002)) {
          size += com.google.protobuf.CodedOutputStream
            .computeEnumSize(2, ptype_.getNumber());
        }
        size += getUnknownFields().getSerializedSize();
        memoizedSerializedSize = size;
        return size;
      }
      
      private static final long serialVersionUID = 0L;
      @java.lang.Override
      protected java.lang.Object writeReplace()
          throws java.io.ObjectStreamException {
        return super.writeReplace();
      }
      
      public static EAddressBook.Employee.PhoneNumber parseFrom(
          com.google.protobuf.ByteString data)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return newBuilder().mergeFrom(data).buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(
          com.google.protobuf.ByteString data,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return newBuilder().mergeFrom(data, extensionRegistry)
                 .buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(byte[] data)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return newBuilder().mergeFrom(data).buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(
          byte[] data,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return newBuilder().mergeFrom(data, extensionRegistry)
                 .buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(java.io.InputStream input)
          throws java.io.IOException {
        return newBuilder().mergeFrom(input).buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(
          java.io.InputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        return newBuilder().mergeFrom(input, extensionRegistry)
                 .buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseDelimitedFrom(java.io.InputStream input)
          throws java.io.IOException {
        Builder builder = newBuilder();
        if (builder.mergeDelimitedFrom(input)) {
          return builder.buildParsed();
        } else {
          return null;
        }
      }
      public static EAddressBook.Employee.PhoneNumber parseDelimitedFrom(
          java.io.InputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        Builder builder = newBuilder();
        if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
          return builder.buildParsed();
        } else {
          return null;
        }
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(
          com.google.protobuf.CodedInputStream input)
          throws java.io.IOException {
        return newBuilder().mergeFrom(input).buildParsed();
      }
      public static EAddressBook.Employee.PhoneNumber parseFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        return newBuilder().mergeFrom(input, extensionRegistry)
                 .buildParsed();
      }
      
      public static Builder newBuilder() { return Builder.create(); }
      public Builder newBuilderForType() { return newBuilder(); }
      public static Builder newBuilder(EAddressBook.Employee.PhoneNumber prototype) {
        return newBuilder().mergeFrom(prototype);
      }
      public Builder toBuilder() { return newBuilder(this); }
      
      @java.lang.Override
      protected Builder newBuilderForType(
          com.google.protobuf.GeneratedMessage.BuilderParent parent) {
        Builder builder = new Builder(parent);
        return builder;
      }
      public static final class Builder extends
          com.google.protobuf.GeneratedMessage.Builder
         implements EAddressBook.Employee.PhoneNumberOrBuilder {
        public static final com.google.protobuf.Descriptors.Descriptor
            getDescriptor() {
          return EAddressBook.internal_static_Employee_PhoneNumber_descriptor;
        }
        
        protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
            internalGetFieldAccessorTable() {
          return EAddressBook.internal_static_Employee_PhoneNumber_fieldAccessorTable;
        }
        
        // Construct using EAddressBook.Employee.PhoneNumber.newBuilder()
        private Builder() {
          maybeForceBuilderInitialization();
        }
        
        private Builder(BuilderParent parent) {
          super(parent);
          maybeForceBuilderInitialization();
        }
        private void maybeForceBuilderInitialization() {
          if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
          }
        }
        private static Builder create() {
          return new Builder();
        }
        
        public Builder clear() {
          super.clear();
          number_ = "";
          bitField0_ = (bitField0_ & ~0x00000001);
          ptype_ = EAddressBook.Employee.PhoneType.HOME;
          bitField0_ = (bitField0_ & ~0x00000002);
          return this;
        }
        
        public Builder clone() {
          return create().mergeFrom(buildPartial());
        }
        
        public com.google.protobuf.Descriptors.Descriptor
            getDescriptorForType() {
          return EAddressBook.Employee.PhoneNumber.getDescriptor();
        }
        
        public EAddressBook.Employee.PhoneNumber getDefaultInstanceForType() {
          return EAddressBook.Employee.PhoneNumber.getDefaultInstance();
        }
        
        public EAddressBook.Employee.PhoneNumber build() {
          EAddressBook.Employee.PhoneNumber result = buildPartial();
          if (!result.isInitialized()) {
            throw newUninitializedMessageException(result);
          }
          return result;
        }
        
        private EAddressBook.Employee.PhoneNumber buildParsed()
            throws com.google.protobuf.InvalidProtocolBufferException {
          EAddressBook.Employee.PhoneNumber result = buildPartial();
          if (!result.isInitialized()) {
            throw newUninitializedMessageException(
              result).asInvalidProtocolBufferException();
          }
          return result;
        }
        
        public EAddressBook.Employee.PhoneNumber buildPartial() {
          EAddressBook.Employee.PhoneNumber result = new EAddressBook.Employee.PhoneNumber(this);
          int from_bitField0_ = bitField0_;
          int to_bitField0_ = 0;
          if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
            to_bitField0_ |= 0x00000001;
          }
          result.number_ = number_;
          if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
            to_bitField0_ |= 0x00000002;
          }
          result.ptype_ = ptype_;
          result.bitField0_ = to_bitField0_;
          onBuilt();
          return result;
        }
        
        public Builder mergeFrom(com.google.protobuf.Message other) {
          if (other instanceof EAddressBook.Employee.PhoneNumber) {
            return mergeFrom((EAddressBook.Employee.PhoneNumber)other);
          } else {
            super.mergeFrom(other);
            return this;
          }
        }
        
        public Builder mergeFrom(EAddressBook.Employee.PhoneNumber other) {
          if (other == EAddressBook.Employee.PhoneNumber.getDefaultInstance()) return this;
          if (other.hasNumber()) {
            setNumber(other.getNumber());
          }
          if (other.hasPtype()) {
            setPtype(other.getPtype());
          }
          this.mergeUnknownFields(other.getUnknownFields());
          return this;
        }
        
        public final boolean isInitialized() {
          if (!hasNumber()) {
            
            return false;
          }
          return true;
        }
        
        public Builder mergeFrom(
            com.google.protobuf.CodedInputStream input,
            com.google.protobuf.ExtensionRegistryLite extensionRegistry)
            throws java.io.IOException {
          com.google.protobuf.UnknownFieldSet.Builder unknownFields =
            com.google.protobuf.UnknownFieldSet.newBuilder(
              this.getUnknownFields());
          while (true) {
            int tag = input.readTag();
            switch (tag) {
              case 0:
                this.setUnknownFields(unknownFields.build());
                onChanged();
                return this;
              default: {
                if (!parseUnknownField(input, unknownFields,
                                       extensionRegistry, tag)) {
                  this.setUnknownFields(unknownFields.build());
                  onChanged();
                  return this;
                }
                break;
              }
              case 10: {
                bitField0_ |= 0x00000001;
                number_ = input.readBytes();
                break;
              }
              case 16: {
                int rawValue = input.readEnum();
                EAddressBook.Employee.PhoneType value = EAddressBook.Employee.PhoneType.valueOf(rawValue);
                if (value == null) {
                  unknownFields.mergeVarintField(2, rawValue);
                } else {
                  bitField0_ |= 0x00000002;
                  ptype_ = value;
                }
                break;
              }
            }
          }
        }
        
        private int bitField0_;
        
        // required string number = 1;
        private java.lang.Object number_ = "";
        public boolean hasNumber() {
          return ((bitField0_ & 0x00000001) == 0x00000001);
        }
        public String getNumber() {
          java.lang.Object ref = number_;
          if (!(ref instanceof String)) {
            String s = ((com.google.protobuf.ByteString) ref).toStringUtf8();
            number_ = s;
            return s;
          } else {
            return (String) ref;
          }
        }
        public Builder setNumber(String value) {
          if (value == null) {
    throw new NullPointerException();
  }
  bitField0_ |= 0x00000001;
          number_ = value;
          onChanged();
          return this;
        }
        public Builder clearNumber() {
          bitField0_ = (bitField0_ & ~0x00000001);
          number_ = getDefaultInstance().getNumber();
          onChanged();
          return this;
        }
        void setNumber(com.google.protobuf.ByteString value) {
          bitField0_ |= 0x00000001;
          number_ = value;
          onChanged();
        }
        
        // optional .Employee.PhoneType ptype = 2 [default = HOME];
        private EAddressBook.Employee.PhoneType ptype_ = EAddressBook.Employee.PhoneType.HOME;
        public boolean hasPtype() {
          return ((bitField0_ & 0x00000002) == 0x00000002);
        }
        public EAddressBook.Employee.PhoneType getPtype() {
          return ptype_;
        }
        public Builder setPtype(EAddressBook.Employee.PhoneType value) {
          if (value == null) {
            throw new NullPointerException();
          }
          bitField0_ |= 0x00000002;
          ptype_ = value;
          onChanged();
          return this;
        }
        public Builder clearPtype() {
          bitField0_ = (bitField0_ & ~0x00000002);
          ptype_ = EAddressBook.Employee.PhoneType.HOME;
          onChanged();
          return this;
        }
        
        // @@protoc_insertion_point(builder_scope:Employee.PhoneNumber)
      }
      
      static {
        defaultInstance = new PhoneNumber(true);
        defaultInstance.initFields();
      }
      
      // @@protoc_insertion_point(class_scope:Employee.PhoneNumber)
    }
    
    private int bitField0_;
    // required string name = 1;
    public static final int NAME_FIELD_NUMBER = 1;
    private java.lang.Object name_;
    public boolean hasName() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    public String getName() {
      java.lang.Object ref = name_;
      if (ref instanceof String) {
        return (String) ref;
      } else {
        com.google.protobuf.ByteString bs = 
            (com.google.protobuf.ByteString) ref;
        String s = bs.toStringUtf8();
        if (com.google.protobuf.Internal.isValidUtf8(bs)) {
          name_ = s;
        }
        return s;
      }
    }
    private com.google.protobuf.ByteString getNameBytes() {
      java.lang.Object ref = name_;
      if (ref instanceof String) {
        com.google.protobuf.ByteString b = 
            com.google.protobuf.ByteString.copyFromUtf8((String) ref);
        name_ = b;
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }
    
    // required int32 id = 2;
    public static final int ID_FIELD_NUMBER = 2;
    private int id_;
    public boolean hasId() {
      return ((bitField0_ & 0x00000002) == 0x00000002);
    }
    public int getId() {
      return id_;
    }
    
    // repeated .Employee.PhoneNumber phone = 4;
    public static final int PHONE_FIELD_NUMBER = 4;
    private java.util.List phone_;
    public java.util.List getPhoneList() {
      return phone_;
    }
    public java.util.List 
        getPhoneOrBuilderList() {
      return phone_;
    }
    public int getPhoneCount() {
      return phone_.size();
    }
    public EAddressBook.Employee.PhoneNumber getPhone(int index) {
      return phone_.get(index);
    }
    public EAddressBook.Employee.PhoneNumberOrBuilder getPhoneOrBuilder(
        int index) {
      return phone_.get(index);
    }
    
    private void initFields() {
      name_ = "";
      id_ = 0;
      phone_ = java.util.Collections.emptyList();
    }
    private byte memoizedIsInitialized = -1;
    public final boolean isInitialized() {
      byte isInitialized = memoizedIsInitialized;
      if (isInitialized != -1) return isInitialized == 1;
      
      if (!hasName()) {
        memoizedIsInitialized = 0;
        return false;
      }
      if (!hasId()) {
        memoizedIsInitialized = 0;
        return false;
      }
      for (int i = 0; i < getPhoneCount(); i++) {
        if (!getPhone(i).isInitialized()) {
          memoizedIsInitialized = 0;
          return false;
        }
      }
      memoizedIsInitialized = 1;
      return true;
    }
    
    public void writeTo(com.google.protobuf.CodedOutputStream output)
                        throws java.io.IOException {
      getSerializedSize();
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        output.writeBytes(1, getNameBytes());
      }
      if (((bitField0_ & 0x00000002) == 0x00000002)) {
        output.writeInt32(2, id_);
      }
      for (int i = 0; i < phone_.size(); i++) {
        output.writeMessage(4, phone_.get(i));
      }
      getUnknownFields().writeTo(output);
    }
    
    private int memoizedSerializedSize = -1;
    public int getSerializedSize() {
      int size = memoizedSerializedSize;
      if (size != -1) return size;
    
      size = 0;
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        size += com.google.protobuf.CodedOutputStream
          .computeBytesSize(1, getNameBytes());
      }
      if (((bitField0_ & 0x00000002) == 0x00000002)) {
        size += com.google.protobuf.CodedOutputStream
          .computeInt32Size(2, id_);
      }
      for (int i = 0; i < phone_.size(); i++) {
        size += com.google.protobuf.CodedOutputStream
          .computeMessageSize(4, phone_.get(i));
      }
      size += getUnknownFields().getSerializedSize();
      memoizedSerializedSize = size;
      return size;
    }
    
    private static final long serialVersionUID = 0L;
    @java.lang.Override
    protected java.lang.Object writeReplace()
        throws java.io.ObjectStreamException {
      return super.writeReplace();
    }
    
    public static EAddressBook.Employee parseFrom(
        com.google.protobuf.ByteString data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data).buildParsed();
    }
    public static EAddressBook.Employee parseFrom(
        com.google.protobuf.ByteString data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data, extensionRegistry)
               .buildParsed();
    }
    public static EAddressBook.Employee parseFrom(byte[] data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data).buildParsed();
    }
    public static EAddressBook.Employee parseFrom(
        byte[] data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data, extensionRegistry)
               .buildParsed();
    }
    public static EAddressBook.Employee parseFrom(java.io.InputStream input)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input).buildParsed();
    }
    public static EAddressBook.Employee parseFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input, extensionRegistry)
               .buildParsed();
    }
    public static EAddressBook.Employee parseDelimitedFrom(java.io.InputStream input)
        throws java.io.IOException {
      Builder builder = newBuilder();
      if (builder.mergeDelimitedFrom(input)) {
        return builder.buildParsed();
      } else {
        return null;
      }
    }
    public static EAddressBook.Employee parseDelimitedFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      Builder builder = newBuilder();
      if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
        return builder.buildParsed();
      } else {
        return null;
      }
    }
    public static EAddressBook.Employee parseFrom(
        com.google.protobuf.CodedInputStream input)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input).buildParsed();
    }
    public static EAddressBook.Employee parseFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input, extensionRegistry)
               .buildParsed();
    }
    
    public static Builder newBuilder() { return Builder.create(); }
    public Builder newBuilderForType() { return newBuilder(); }
    public static Builder newBuilder(EAddressBook.Employee prototype) {
      return newBuilder().mergeFrom(prototype);
    }
    public Builder toBuilder() { return newBuilder(this); }
    
    @java.lang.Override
    protected Builder newBuilderForType(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      Builder builder = new Builder(parent);
      return builder;
    }
    public static final class Builder extends
        com.google.protobuf.GeneratedMessage.Builder
       implements EAddressBook.EmployeeOrBuilder {
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return EAddressBook.internal_static_Employee_descriptor;
      }
      
      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return EAddressBook.internal_static_Employee_fieldAccessorTable;
      }
      
      // Construct using EAddressBook.Employee.newBuilder()
      private Builder() {
        maybeForceBuilderInitialization();
      }
      
      private Builder(BuilderParent parent) {
        super(parent);
        maybeForceBuilderInitialization();
      }
      private void maybeForceBuilderInitialization() {
        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
          getPhoneFieldBuilder();
        }
      }
      private static Builder create() {
        return new Builder();
      }
      
      public Builder clear() {
        super.clear();
        name_ = "";
        bitField0_ = (bitField0_ & ~0x00000001);
        id_ = 0;
        bitField0_ = (bitField0_ & ~0x00000002);
        if (phoneBuilder_ == null) {
          phone_ = java.util.Collections.emptyList();
          bitField0_ = (bitField0_ & ~0x00000004);
        } else {
          phoneBuilder_.clear();
        }
        return this;
      }
      
      public Builder clone() {
        return create().mergeFrom(buildPartial());
      }
      
      public com.google.protobuf.Descriptors.Descriptor
          getDescriptorForType() {
        return EAddressBook.Employee.getDescriptor();
      }
      
      public EAddressBook.Employee getDefaultInstanceForType() {
        return EAddressBook.Employee.getDefaultInstance();
      }
      
      public EAddressBook.Employee build() {
        EAddressBook.Employee result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(result);
        }
        return result;
      }
      
      private EAddressBook.Employee buildParsed()
          throws com.google.protobuf.InvalidProtocolBufferException {
        EAddressBook.Employee result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(
            result).asInvalidProtocolBufferException();
        }
        return result;
      }
      
      public EAddressBook.Employee buildPartial() {
        EAddressBook.Employee result = new EAddressBook.Employee(this);
        int from_bitField0_ = bitField0_;
        int to_bitField0_ = 0;
        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
          to_bitField0_ |= 0x00000001;
        }
        result.name_ = name_;
        if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
          to_bitField0_ |= 0x00000002;
        }
        result.id_ = id_;
        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 mergeFrom(com.google.protobuf.Message other) {
        if (other instanceof EAddressBook.Employee) {
          return mergeFrom((EAddressBook.Employee)other);
        } else {
          super.mergeFrom(other);
          return this;
        }
      }
      
      public Builder mergeFrom(EAddressBook.Employee other) {
        if (other == EAddressBook.Employee.getDefaultInstance()) return this;
        if (other.hasName()) {
          setName(other.getName());
        }
        if (other.hasId()) {
          setId(other.getId());
        }
        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.GeneratedMessage.alwaysUseFieldBuilders ?
                   getPhoneFieldBuilder() : null;
            } else {
              phoneBuilder_.addAllMessages(other.phone_);
            }
          }
        }
        this.mergeUnknownFields(other.getUnknownFields());
        return this;
      }
      
      public final boolean isInitialized() {
        if (!hasName()) {
          
          return false;
        }
        if (!hasId()) {
          
          return false;
        }
        for (int i = 0; i < getPhoneCount(); i++) {
          if (!getPhone(i).isInitialized()) {
            
            return false;
          }
        }
        return true;
      }
      
      public Builder mergeFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        com.google.protobuf.UnknownFieldSet.Builder unknownFields =
          com.google.protobuf.UnknownFieldSet.newBuilder(
            this.getUnknownFields());
        while (true) {
          int tag = input.readTag();
          switch (tag) {
            case 0:
              this.setUnknownFields(unknownFields.build());
              onChanged();
              return this;
            default: {
              if (!parseUnknownField(input, unknownFields,
                                     extensionRegistry, tag)) {
                this.setUnknownFields(unknownFields.build());
                onChanged();
                return this;
              }
              break;
            }
            case 10: {
              bitField0_ |= 0x00000001;
              name_ = input.readBytes();
              break;
            }
            case 16: {
              bitField0_ |= 0x00000002;
              id_ = input.readInt32();
              break;
            }
            case 34: {
              EAddressBook.Employee.PhoneNumber.Builder subBuilder = EAddressBook.Employee.PhoneNumber.newBuilder();
              input.readMessage(subBuilder, extensionRegistry);
              addPhone(subBuilder.buildPartial());
              break;
            }
          }
        }
      }
      
      private int bitField0_;
      
      // required string name = 1;
      private java.lang.Object name_ = "";
      public boolean hasName() {
        return ((bitField0_ & 0x00000001) == 0x00000001);
      }
      public String getName() {
        java.lang.Object ref = name_;
        if (!(ref instanceof String)) {
          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8();
          name_ = s;
          return s;
        } else {
          return (String) ref;
        }
      }
      public Builder setName(String value) {
        if (value == null) {
    throw new NullPointerException();
  }
  bitField0_ |= 0x00000001;
        name_ = value;
        onChanged();
        return this;
      }
      public Builder clearName() {
        bitField0_ = (bitField0_ & ~0x00000001);
        name_ = getDefaultInstance().getName();
        onChanged();
        return this;
      }
      void setName(com.google.protobuf.ByteString value) {
        bitField0_ |= 0x00000001;
        name_ = value;
        onChanged();
      }
      
      // required int32 id = 2;
      private int id_ ;
      public boolean hasId() {
        return ((bitField0_ & 0x00000002) == 0x00000002);
      }
      public int getId() {
        return id_;
      }
      public Builder setId(int value) {
        bitField0_ |= 0x00000002;
        id_ = value;
        onChanged();
        return this;
      }
      public Builder clearId() {
        bitField0_ = (bitField0_ & ~0x00000002);
        id_ = 0;
        onChanged();
        return this;
      }
      
      // repeated .Employee.PhoneNumber phone = 4;
      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.RepeatedFieldBuilder phoneBuilder_;
      
      public java.util.List getPhoneList() {
        if (phoneBuilder_ == null) {
          return java.util.Collections.unmodifiableList(phone_);
        } else {
          return phoneBuilder_.getMessageList();
        }
      }
      public int getPhoneCount() {
        if (phoneBuilder_ == null) {
          return phone_.size();
        } else {
          return phoneBuilder_.getCount();
        }
      }
      public EAddressBook.Employee.PhoneNumber getPhone(int index) {
        if (phoneBuilder_ == null) {
          return phone_.get(index);
        } else {
          return phoneBuilder_.getMessage(index);
        }
      }
      public Builder setPhone(
          int index, EAddressBook.Employee.PhoneNumber value) {
        if (phoneBuilder_ == null) {
          if (value == null) {
            throw new NullPointerException();
          }
          ensurePhoneIsMutable();
          phone_.set(index, value);
          onChanged();
        } else {
          phoneBuilder_.setMessage(index, value);
        }
        return this;
      }
      public Builder setPhone(
          int index, EAddressBook.Employee.PhoneNumber.Builder builderForValue) {
        if (phoneBuilder_ == null) {
          ensurePhoneIsMutable();
          phone_.set(index, builderForValue.build());
          onChanged();
        } else {
          phoneBuilder_.setMessage(index, builderForValue.build());
        }
        return this;
      }
      public Builder addPhone(EAddressBook.Employee.PhoneNumber value) {
        if (phoneBuilder_ == null) {
          if (value == null) {
            throw new NullPointerException();
          }
          ensurePhoneIsMutable();
          phone_.add(value);
          onChanged();
        } else {
          phoneBuilder_.addMessage(value);
        }
        return this;
      }
      public Builder addPhone(
          int index, EAddressBook.Employee.PhoneNumber value) {
        if (phoneBuilder_ == null) {
          if (value == null) {
            throw new NullPointerException();
          }
          ensurePhoneIsMutable();
          phone_.add(index, value);
          onChanged();
        } else {
          phoneBuilder_.addMessage(index, value);
        }
        return this;
      }
      public Builder addPhone(
          EAddressBook.Employee.PhoneNumber.Builder builderForValue) {
        if (phoneBuilder_ == null) {
          ensurePhoneIsMutable();
          phone_.add(builderForValue.build());
          onChanged();
        } else {
          phoneBuilder_.addMessage(builderForValue.build());
        }
        return this;
      }
      public Builder addPhone(
          int index, EAddressBook.Employee.PhoneNumber.Builder builderForValue) {
        if (phoneBuilder_ == null) {
          ensurePhoneIsMutable();
          phone_.add(index, builderForValue.build());
          onChanged();
        } else {
          phoneBuilder_.addMessage(index, builderForValue.build());
        }
        return this;
      }
      public Builder addAllPhone(
          java.lang.Iterable values) {
        if (phoneBuilder_ == null) {
          ensurePhoneIsMutable();
          super.addAll(values, phone_);
          onChanged();
        } else {
          phoneBuilder_.addAllMessages(values);
        }
        return this;
      }
      public Builder clearPhone() {
        if (phoneBuilder_ == null) {
          phone_ = java.util.Collections.emptyList();
          bitField0_ = (bitField0_ & ~0x00000004);
          onChanged();
        } else {
          phoneBuilder_.clear();
        }
        return this;
      }
      public Builder removePhone(int index) {
        if (phoneBuilder_ == null) {
          ensurePhoneIsMutable();
          phone_.remove(index);
          onChanged();
        } else {
          phoneBuilder_.remove(index);
        }
        return this;
      }
      public EAddressBook.Employee.PhoneNumber.Builder getPhoneBuilder(
          int index) {
        return getPhoneFieldBuilder().getBuilder(index);
      }
      public EAddressBook.Employee.PhoneNumberOrBuilder getPhoneOrBuilder(
          int index) {
        if (phoneBuilder_ == null) {
          return phone_.get(index);  } else {
          return phoneBuilder_.getMessageOrBuilder(index);
        }
      }
      public java.util.List 
           getPhoneOrBuilderList() {
        if (phoneBuilder_ != null) {
          return phoneBuilder_.getMessageOrBuilderList();
        } else {
          return java.util.Collections.unmodifiableList(phone_);
        }
      }
      public EAddressBook.Employee.PhoneNumber.Builder addPhoneBuilder() {
        return getPhoneFieldBuilder().addBuilder(
            EAddressBook.Employee.PhoneNumber.getDefaultInstance());
      }
      public EAddressBook.Employee.PhoneNumber.Builder addPhoneBuilder(
          int index) {
        return getPhoneFieldBuilder().addBuilder(
            index, EAddressBook.Employee.PhoneNumber.getDefaultInstance());
      }
      public java.util.List 
           getPhoneBuilderList() {
        return getPhoneFieldBuilder().getBuilderList();
      }
      private com.google.protobuf.RepeatedFieldBuilder 
          getPhoneFieldBuilder() {
        if (phoneBuilder_ == null) {
          phoneBuilder_ = new com.google.protobuf.RepeatedFieldBuilder(
                  phone_,
                  ((bitField0_ & 0x00000004) == 0x00000004),
                  getParentForChildren(),
                  isClean());
          phone_ = null;
        }
        return phoneBuilder_;
      }
      
      // @@protoc_insertion_point(builder_scope:Employee)
    }
    
    static {
      defaultInstance = new Employee(true);
      defaultInstance.initFields();
    }
    
    // @@protoc_insertion_point(class_scope:Employee)
  }
  
  public interface EmplyeeBookOrBuilder
      extends com.google.protobuf.MessageOrBuilder {
    
    // repeated .Employee emp = 1;
    java.util.List 
        getEmpList();
    EAddressBook.Employee getEmp(int index);
    int getEmpCount();
    java.util.List 
        getEmpOrBuilderList();
    EAddressBook.EmployeeOrBuilder getEmpOrBuilder(
        int index);
  }
  public static final class EmplyeeBook extends
      com.google.protobuf.GeneratedMessage
      implements EmplyeeBookOrBuilder {
    // Use EmplyeeBook.newBuilder() to construct.
    private EmplyeeBook(Builder builder) {
      super(builder);
    }
    private EmplyeeBook(boolean noInit) {}
    
    private static final EmplyeeBook defaultInstance;
    public static EmplyeeBook getDefaultInstance() {
      return defaultInstance;
    }
    
    public EmplyeeBook getDefaultInstanceForType() {
      return defaultInstance;
    }
    
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return EAddressBook.internal_static_EmplyeeBook_descriptor;
    }
    
    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return EAddressBook.internal_static_EmplyeeBook_fieldAccessorTable;
    }
    
    // repeated .Employee emp = 1;
    public static final int EMP_FIELD_NUMBER = 1;
    private java.util.List emp_;
    public java.util.List getEmpList() {
      return emp_;
    }
    public java.util.List 
        getEmpOrBuilderList() {
      return emp_;
    }
    public int getEmpCount() {
      return emp_.size();
    }
    public EAddressBook.Employee getEmp(int index) {
      return emp_.get(index);
    }
    public EAddressBook.EmployeeOrBuilder getEmpOrBuilder(
        int index) {
      return emp_.get(index);
    }
    
    private void initFields() {
      emp_ = java.util.Collections.emptyList();
    }
    private byte memoizedIsInitialized = -1;
    public final boolean isInitialized() {
      byte isInitialized = memoizedIsInitialized;
      if (isInitialized != -1) return isInitialized == 1;
      
      for (int i = 0; i < getEmpCount(); i++) {
        if (!getEmp(i).isInitialized()) {
          memoizedIsInitialized = 0;
          return false;
        }
      }
      memoizedIsInitialized = 1;
      return true;
    }
    
    public void writeTo(com.google.protobuf.CodedOutputStream output)
                        throws java.io.IOException {
      getSerializedSize();
      for (int i = 0; i < emp_.size(); i++) {
        output.writeMessage(1, emp_.get(i));
      }
      getUnknownFields().writeTo(output);
    }
    
    private int memoizedSerializedSize = -1;
    public int getSerializedSize() {
      int size = memoizedSerializedSize;
      if (size != -1) return size;
    
      size = 0;
      for (int i = 0; i < emp_.size(); i++) {
        size += com.google.protobuf.CodedOutputStream
          .computeMessageSize(1, emp_.get(i));
      }
      size += getUnknownFields().getSerializedSize();
      memoizedSerializedSize = size;
      return size;
    }
    
    private static final long serialVersionUID = 0L;
    @java.lang.Override
    protected java.lang.Object writeReplace()
        throws java.io.ObjectStreamException {
      return super.writeReplace();
    }
    
    public static EAddressBook.EmplyeeBook parseFrom(
        com.google.protobuf.ByteString data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data).buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseFrom(
        com.google.protobuf.ByteString data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data, extensionRegistry)
               .buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseFrom(byte[] data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data).buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseFrom(
        byte[] data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return newBuilder().mergeFrom(data, extensionRegistry)
               .buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseFrom(java.io.InputStream input)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input).buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input, extensionRegistry)
               .buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseDelimitedFrom(java.io.InputStream input)
        throws java.io.IOException {
      Builder builder = newBuilder();
      if (builder.mergeDelimitedFrom(input)) {
        return builder.buildParsed();
      } else {
        return null;
      }
    }
    public static EAddressBook.EmplyeeBook parseDelimitedFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      Builder builder = newBuilder();
      if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
        return builder.buildParsed();
      } else {
        return null;
      }
    }
    public static EAddressBook.EmplyeeBook parseFrom(
        com.google.protobuf.CodedInputStream input)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input).buildParsed();
    }
    public static EAddressBook.EmplyeeBook parseFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return newBuilder().mergeFrom(input, extensionRegistry)
               .buildParsed();
    }
    
    public static Builder newBuilder() { return Builder.create(); }
    public Builder newBuilderForType() { return newBuilder(); }
    public static Builder newBuilder(EAddressBook.EmplyeeBook prototype) {
      return newBuilder().mergeFrom(prototype);
    }
    public Builder toBuilder() { return newBuilder(this); }
    
    @java.lang.Override
    protected Builder newBuilderForType(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      Builder builder = new Builder(parent);
      return builder;
    }
    public static final class Builder extends
        com.google.protobuf.GeneratedMessage.Builder
       implements EAddressBook.EmplyeeBookOrBuilder {
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return EAddressBook.internal_static_EmplyeeBook_descriptor;
      }
      
      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return EAddressBook.internal_static_EmplyeeBook_fieldAccessorTable;
      }
      
      // Construct using EAddressBook.EmplyeeBook.newBuilder()
      private Builder() {
        maybeForceBuilderInitialization();
      }
      
      private Builder(BuilderParent parent) {
        super(parent);
        maybeForceBuilderInitialization();
      }
      private void maybeForceBuilderInitialization() {
        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
          getEmpFieldBuilder();
        }
      }
      private static Builder create() {
        return new Builder();
      }
      
      public Builder clear() {
        super.clear();
        if (empBuilder_ == null) {
          emp_ = java.util.Collections.emptyList();
          bitField0_ = (bitField0_ & ~0x00000001);
        } else {
          empBuilder_.clear();
        }
        return this;
      }
      
      public Builder clone() {
        return create().mergeFrom(buildPartial());
      }
      
      public com.google.protobuf.Descriptors.Descriptor
          getDescriptorForType() {
        return EAddressBook.EmplyeeBook.getDescriptor();
      }
      
      public EAddressBook.EmplyeeBook getDefaultInstanceForType() {
        return EAddressBook.EmplyeeBook.getDefaultInstance();
      }
      
      public EAddressBook.EmplyeeBook build() {
        EAddressBook.EmplyeeBook result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(result);
        }
        return result;
      }
      
      private EAddressBook.EmplyeeBook buildParsed()
          throws com.google.protobuf.InvalidProtocolBufferException {
        EAddressBook.EmplyeeBook result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(
            result).asInvalidProtocolBufferException();
        }
        return result;
      }
      
      public EAddressBook.EmplyeeBook buildPartial() {
        EAddressBook.EmplyeeBook result = new EAddressBook.EmplyeeBook(this);
        int from_bitField0_ = bitField0_;
        if (empBuilder_ == null) {
          if (((bitField0_ & 0x00000001) == 0x00000001)) {
            emp_ = java.util.Collections.unmodifiableList(emp_);
            bitField0_ = (bitField0_ & ~0x00000001);
          }
          result.emp_ = emp_;
        } else {
          result.emp_ = empBuilder_.build();
        }
        onBuilt();
        return result;
      }
      
      public Builder mergeFrom(com.google.protobuf.Message other) {
        if (other instanceof EAddressBook.EmplyeeBook) {
          return mergeFrom((EAddressBook.EmplyeeBook)other);
        } else {
          super.mergeFrom(other);
          return this;
        }
      }
      
      public Builder mergeFrom(EAddressBook.EmplyeeBook other) {
        if (other == EAddressBook.EmplyeeBook.getDefaultInstance()) return this;
        if (empBuilder_ == null) {
          if (!other.emp_.isEmpty()) {
            if (emp_.isEmpty()) {
              emp_ = other.emp_;
              bitField0_ = (bitField0_ & ~0x00000001);
            } else {
              ensureEmpIsMutable();
              emp_.addAll(other.emp_);
            }
            onChanged();
          }
        } else {
          if (!other.emp_.isEmpty()) {
            if (empBuilder_.isEmpty()) {
              empBuilder_.dispose();
              empBuilder_ = null;
              emp_ = other.emp_;
              bitField0_ = (bitField0_ & ~0x00000001);
              empBuilder_ = 
                com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
                   getEmpFieldBuilder() : null;
            } else {
              empBuilder_.addAllMessages(other.emp_);
            }
          }
        }
        this.mergeUnknownFields(other.getUnknownFields());
        return this;
      }
      
      public final boolean isInitialized() {
        for (int i = 0; i < getEmpCount(); i++) {
          if (!getEmp(i).isInitialized()) {
            
            return false;
          }
        }
        return true;
      }
      
      public Builder mergeFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        com.google.protobuf.UnknownFieldSet.Builder unknownFields =
          com.google.protobuf.UnknownFieldSet.newBuilder(
            this.getUnknownFields());
        while (true) {
          int tag = input.readTag();
          switch (tag) {
            case 0:
              this.setUnknownFields(unknownFields.build());
              onChanged();
              return this;
            default: {
              if (!parseUnknownField(input, unknownFields,
                                     extensionRegistry, tag)) {
                this.setUnknownFields(unknownFields.build());
                onChanged();
                return this;
              }
              break;
            }
            case 10: {
              EAddressBook.Employee.Builder subBuilder = EAddressBook.Employee.newBuilder();
              input.readMessage(subBuilder, extensionRegistry);
              addEmp(subBuilder.buildPartial());
              break;
            }
          }
        }
      }
      
      private int bitField0_;
      
      // repeated .Employee emp = 1;
      private java.util.List emp_ =
        java.util.Collections.emptyList();
      private void ensureEmpIsMutable() {
        if (!((bitField0_ & 0x00000001) == 0x00000001)) {
          emp_ = new java.util.ArrayList(emp_);
          bitField0_ |= 0x00000001;
         }
      }
      
      private com.google.protobuf.RepeatedFieldBuilder empBuilder_;
      
      public java.util.List getEmpList() {
        if (empBuilder_ == null) {
          return java.util.Collections.unmodifiableList(emp_);
        } else {
          return empBuilder_.getMessageList();
        }
      }
      public int getEmpCount() {
        if (empBuilder_ == null) {
          return emp_.size();
        } else {
          return empBuilder_.getCount();
        }
      }
      public EAddressBook.Employee getEmp(int index) {
        if (empBuilder_ == null) {
          return emp_.get(index);
        } else {
          return empBuilder_.getMessage(index);
        }
      }
      public Builder setEmp(
          int index, EAddressBook.Employee value) {
        if (empBuilder_ == null) {
          if (value == null) {
            throw new NullPointerException();
          }
          ensureEmpIsMutable();
          emp_.set(index, value);
          onChanged();
        } else {
          empBuilder_.setMessage(index, value);
        }
        return this;
      }
      public Builder setEmp(
          int index, EAddressBook.Employee.Builder builderForValue) {
        if (empBuilder_ == null) {
          ensureEmpIsMutable();
          emp_.set(index, builderForValue.build());
          onChanged();
        } else {
          empBuilder_.setMessage(index, builderForValue.build());
        }
        return this;
      }
      public Builder addEmp(EAddressBook.Employee value) {
        if (empBuilder_ == null) {
          if (value == null) {
            throw new NullPointerException();
          }
          ensureEmpIsMutable();
          emp_.add(value);
          onChanged();
        } else {
          empBuilder_.addMessage(value);
        }
        return this;
      }
      public Builder addEmp(
          int index, EAddressBook.Employee value) {
        if (empBuilder_ == null) {
          if (value == null) {
            throw new NullPointerException();
          }
          ensureEmpIsMutable();
          emp_.add(index, value);
          onChanged();
        } else {
          empBuilder_.addMessage(index, value);
        }
        return this;
      }
      public Builder addEmp(
          EAddressBook.Employee.Builder builderForValue) {
        if (empBuilder_ == null) {
          ensureEmpIsMutable();
          emp_.add(builderForValue.build());
          onChanged();
        } else {
          empBuilder_.addMessage(builderForValue.build());
        }
        return this;
      }
      public Builder addEmp(
          int index, EAddressBook.Employee.Builder builderForValue) {
        if (empBuilder_ == null) {
          ensureEmpIsMutable();
          emp_.add(index, builderForValue.build());
          onChanged();
        } else {
          empBuilder_.addMessage(index, builderForValue.build());
        }
        return this;
      }
      public Builder addAllEmp(
          java.lang.Iterable values) {
        if (empBuilder_ == null) {
          ensureEmpIsMutable();
          super.addAll(values, emp_);
          onChanged();
        } else {
          empBuilder_.addAllMessages(values);
        }
        return this;
      }
      public Builder clearEmp() {
        if (empBuilder_ == null) {
          emp_ = java.util.Collections.emptyList();
          bitField0_ = (bitField0_ & ~0x00000001);
          onChanged();
        } else {
          empBuilder_.clear();
        }
        return this;
      }
      public Builder removeEmp(int index) {
        if (empBuilder_ == null) {
          ensureEmpIsMutable();
          emp_.remove(index);
          onChanged();
        } else {
          empBuilder_.remove(index);
        }
        return this;
      }
      public EAddressBook.Employee.Builder getEmpBuilder(
          int index) {
        return getEmpFieldBuilder().getBuilder(index);
      }
      public EAddressBook.EmployeeOrBuilder getEmpOrBuilder(
          int index) {
        if (empBuilder_ == null) {
          return emp_.get(index);  } else {
          return empBuilder_.getMessageOrBuilder(index);
        }
      }
      public java.util.List 
           getEmpOrBuilderList() {
        if (empBuilder_ != null) {
          return empBuilder_.getMessageOrBuilderList();
        } else {
          return java.util.Collections.unmodifiableList(emp_);
        }
      }
      public EAddressBook.Employee.Builder addEmpBuilder() {
        return getEmpFieldBuilder().addBuilder(
            EAddressBook.Employee.getDefaultInstance());
      }
      public EAddressBook.Employee.Builder addEmpBuilder(
          int index) {
        return getEmpFieldBuilder().addBuilder(
            index, EAddressBook.Employee.getDefaultInstance());
      }
      public java.util.List 
           getEmpBuilderList() {
        return getEmpFieldBuilder().getBuilderList();
      }
      private com.google.protobuf.RepeatedFieldBuilder 
          getEmpFieldBuilder() {
        if (empBuilder_ == null) {
          empBuilder_ = new com.google.protobuf.RepeatedFieldBuilder(
                  emp_,
                  ((bitField0_ & 0x00000001) == 0x00000001),
                  getParentForChildren(),
                  isClean());
          emp_ = null;
        }
        return empBuilder_;
      }
      
      // @@protoc_insertion_point(builder_scope:EmplyeeBook)
    }
    
    static {
      defaultInstance = new EmplyeeBook(true);
      defaultInstance.initFields();
    }
    
    // @@protoc_insertion_point(class_scope:EmplyeeBook)
  }
  
  private static com.google.protobuf.Descriptors.Descriptor
    internal_static_Employee_descriptor;
  private static
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internal_static_Employee_fieldAccessorTable;
  private static com.google.protobuf.Descriptors.Descriptor
    internal_static_Employee_PhoneNumber_descriptor;
  private static
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internal_static_Employee_PhoneNumber_fieldAccessorTable;
  private static com.google.protobuf.Descriptors.Descriptor
    internal_static_EmplyeeBook_descriptor;
  private static
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internal_static_EmplyeeBook_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\016Employee.proto\"\300\001\n\010Employee\022\014\n\004name\030\001 " +
      "\002(\t\022\n\n\002id\030\002 \002(\005\022$\n\005phone\030\004 \003(\0132\025.Employe" +
      "e.PhoneNumber\032G\n\013PhoneNumber\022\016\n\006number\030\001" +
      " \002(\t\022(\n\005ptype\030\002 \001(\0162\023.Employee.PhoneType" +
      ":\004HOME\"+\n\tPhoneType\022\n\n\006MOBILE\020\000\022\010\n\004WORK\020" +
      "\001\022\010\n\004HOME\020\002\"%\n\013EmplyeeBook\022\026\n\003emp\030\001 \003(\0132" +
      "\t.EmployeeB\016B\014EAddressBook"
    };
    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_Employee_descriptor =
            getDescriptor().getMessageTypes().get(0);
          internal_static_Employee_fieldAccessorTable = new
            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
              internal_static_Employee_descriptor,
              new java.lang.String[] { "Name", "Id", "Phone", },
              EAddressBook.Employee.class,
              EAddressBook.Employee.Builder.class);
          internal_static_Employee_PhoneNumber_descriptor =
            internal_static_Employee_descriptor.getNestedTypes().get(0);
          internal_static_Employee_PhoneNumber_fieldAccessorTable = new
            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
              internal_static_Employee_PhoneNumber_descriptor,
              new java.lang.String[] { "Number", "Ptype", },
              EAddressBook.Employee.PhoneNumber.class,
              EAddressBook.Employee.PhoneNumber.Builder.class);
          internal_static_EmplyeeBook_descriptor =
            getDescriptor().getMessageTypes().get(1);
          internal_static_EmplyeeBook_fieldAccessorTable = new
            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
              internal_static_EmplyeeBook_descriptor,
              new java.lang.String[] { "Emp", },
              EAddressBook.EmplyeeBook.class,
              EAddressBook.EmplyeeBook.Builder.class);
          return null;
        }
      };
    com.google.protobuf.Descriptors.FileDescriptor
      .internalBuildGeneratedFileFrom(descriptorData,
        new com.google.protobuf.Descriptors.FileDescriptor[] {
        }, assigner);
  }
  
  // @@protoc_insertion_point(outer_class_scope)
}


Connect with

3 thoughts on “Java with Google protocol buffer

Leave a Reply

Your email address will not be published. Required fields are marked *