public class CmRaftConfiguration implements Configuration {
  static final Log LOG = LogFactory.getLog(CmRaftConfiguration.class);
  private PropertiesConfiguration conf;
  
  public CmRaftConfiguration() throws ConfigurationException {
    conf = new PropertiesConfiguration("cmraft.properties");
    
  }
  
  public static Configuration create() {
    try {
      CmRaftConfiguration raftConfig = new CmRaftConfiguration();
      return raftConfig;
    } catch(ConfigurationException e) {
      return null;
    }
  }
  
  @Override
  public void useResource(String resourceName) {
    try {
      conf = new PropertiesConfiguration(resourceName);
    } catch(ConfigurationException e) {
      LOG.error("load resource exception", e);
    }
  }
  
  @Override
  public Object clone() {
    Configuration obj = CmRaftConfiguration.create();
    obj.clear();
    for(String key: this.getKeys()) {
      obj.set(key, this.getString(key));
    }
    return (Object)obj;
  }
  
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    for(String key: this.getKeys()) {
      sb.append(key + ":" + conf.getString(key)+"\n");
    }
    return sb.toString();
  }
  
  @Override
  public String getString(String key) {
    return conf.getString(key);
  }
  
  @Override
  public String getString(String key, String defaultValue) {
    return conf.getString(key, defaultValue);
  }

  @Override
  public int getInt(String key) {
    return conf.getInt(key);
  }
  
  @Override
  public int getInt(String key, int defaultValue) {
    return conf.getInt(key, defaultValue);
  }
  @Override
  public Iterable<String> getKeys() {
    return this.new ConfigurationIterableImpl();
  }
  
  @Override
  public Iterable<String> getKeys(String prefix) {
    return this.new ConfigurationIterableImplForPrefix(prefix);
  }
  
  @Override
  public void set(String key, String value) {
    conf.setProperty(key, value);
  }
  
  @Override
  public void clear() {
    conf.clear();
  }
  
  @Override
  public void remove(String key) {
    conf.clearProperty(key);
  }
  
  private class ConfigurationIterableImpl implements Iterable<String> {
    public Iterator<String> iterator() {
      return conf.getKeys();
    }
  }
  
  private class ConfigurationIterableImplForPrefix implements Iterable<String> {
    private String prefix ;
    ConfigurationIterableImplForPrefix(String prefix) {
      this.prefix = prefix;
    }
    public Iterator<String> iterator() {
      return conf.getKeys(prefix);
    }
  }
} public interface Configuration {
  
  void useResource(String resourceName);
  
  String getString(String key);
  
  String getString(String key, String defaultValue);
  
  int getInt(String key);
  
  int getInt(String key, int defaultValue);
  
  void set(String key, String value);
  
  void clear();
  
  void remove(String key);
  
  Iterable<String> getKeys();
  
  Iterable<String> getKeys(String prefix);
} public class ServerInfo {
  static final Log LOG = LogFactory.getLog(ServerInfo.class);
  private final String host;
  private final int port;
  
  public ServerInfo(String host, int port) {
    this.host = host;
    this.port = port;
  }
  
  /**
   * @return the host
   */
  public String getHost() {
    return host;
  }

  /**
   * @return the port
   */
  public int getPort() {
    return port;
  }
  
  public static ServerInfo parseFromString(String hostAddress) {
    if(hostAddress == null)
      return null;
    String[] results = hostAddress.split(":");
    if(results == null || results.length != 2)
      return null;
    int port;
    try {
      port = Integer.parseInt(results[1]);
    } catch(Exception e) {
      LOG.error("parse port form configuration exception", e);
      return null;
    }
    return new ServerInfo(results[0], port);
  }
  /*
  public static List<ServerInfo> getRemoteServersFromConfiguration(Configuration conf) {
    List<ServerInfo> servers = new ArrayList<ServerInfo>();
    for (String key: conf.getKeys("raft.server.remote")) {
      ServerInfo server = ServerInfo.parseFromString(conf.getString(key));
      servers.add(server);
    }
    return servers;
  }*/
  
  public ServerId toServerId() {
    ServerId.Builder builder = ServerId.newBuilder();
    if(getHost() != null)
      builder.setHostName(getHost());
    builder.setPort(getPort());
    
    return builder.build();
  }
  
  public static ServerInfo copyFrom(ServerId serverId) {
    if(serverId == null)
      return null;
    ServerInfo server = new ServerInfo(serverId.getHostName(), serverId.getPort());
    return server;
  }
  
  @Override
  public String toString() {
    return String.format("[%s:%d]", getHost(), getPort());
  }

  
  private int memoizedHashCode = 0;
  
  @Override
  public int hashCode() {
    if (memoizedHashCode != 0) {
      return memoizedHashCode;
    }
    int hash = 41;
    hash = (19 * hash) + getPort();
    if(getHost()!=null) {
      hash = (53 * hash) + getHost().hashCode();
    }
    memoizedHashCode = hash;
    return hash;
  }
  
  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if(obj == null) {
      LOG.debug("equals (null)");
      return false;
    }
    if (!(obj instanceof ServerInfo)) {
       return super.equals(obj);
    }
    ServerInfo other = (ServerInfo)obj;
    boolean result = true;
    result = result && ((getHost()!=null) == (other.getHost()!=null));
    if (getHost()!=null) {
      result = result && getHost()
          .equals(other.getHost());
    }
    
    result = result && (getPort()==other.getPort());
    
    return result;
  }
} public class ClusterMemberManager {
  static final Log LOG = LogFactory.getLog(ClusterMemberManager.class);
  private static final String RAFT_SERVER_KEY_PREFIX = "raft.server";
  private static final String RAFT_LOCAL_SERVER_KEY = "raft.local.server";
  
  private Set<ServerInfo> remoteServers = new HashSet<ServerInfo>();
  private ServerInfo localServer;
  private Set<String> localAddresses = new HashSet<String>();
  
  public ClusterMemberManager(Configuration conf) {
    initLocalAddresses();
    LOG.debug("local addresses: " + localAddresses.toString());
    loadServerInfoFromConf(conf);
  }
  
  public ServerInfo getLocalServer() {
    return localServer;
  }
  
  public Set<ServerInfo> getRemoteServers() {
    return remoteServers;
  }
  
  // For Raft client to iterate all raft servers
  public static Set<ServerInfo> getRaftServers(Configuration conf) {
    Set<ServerInfo> servers = new HashSet<ServerInfo>();
    
    for (String key: conf.getKeys(RAFT_SERVER_KEY_PREFIX)) {
      ServerInfo server = ServerInfo.parseFromString(conf.getString(key));
      servers.add(server);
    }
    ServerInfo localServer = ServerInfo.parseFromString(conf.getString(RAFT_LOCAL_SERVER_KEY));
    if(localServer != null) {
      servers.add(localServer);
    }
    return servers;
  }
  
  private void loadServerInfoFromConf(Configuration conf) {
    List<ServerInfo> configuredServers = new ArrayList<ServerInfo>();
    int nLocalServers = 0;
    ServerInfo lastLocalServer = null;
    
    for (String key: conf.getKeys(RAFT_SERVER_KEY_PREFIX)) {
      ServerInfo server = ServerInfo.parseFromString(conf.getString(key));
      
      if(configuredServers.contains(server)) {
        String msg = "Duplicated server info in configuration:" + server;
        LOG.error(msg, new RuntimeException(msg));
      }
      
      configuredServers.add(server);
      if(isLocalAddress(server.getHost())) {
        nLocalServers ++;
        lastLocalServer = server;
      }
    }
    
    ServerInfo configuredLocalServer = ServerInfo.parseFromString(conf.getString(RAFT_LOCAL_SERVER_KEY));
    
    if(nLocalServers == 1) {
      localServer = configuredLocalServer == null ? lastLocalServer: configuredLocalServer;
    } else if(nLocalServers == 0 || nLocalServers > 1) {
      if(configuredLocalServer == null) {
        String msg = "Local host is not configured as a raft server, please check cmraft.properties configuration file";
        RuntimeException e = new RuntimeException(msg);
        LOG.error("Configuration error", e);
        throw e;
      } else {
        localServer = configuredLocalServer;
      }
    } else {
      // nLocalServers < 0, should never be here.
      LOG.error("SHOULD NOT BE HERE.");
      return;
    }
    remoteServers.addAll(configuredServers);
    remoteServers.remove(localServer);
  }

  public boolean isLocalAddress(String hostAddress) {
    Preconditions.checkNotNull(hostAddress);
    
    return localAddresses.contains(hostAddress);
  }
  
  private void initLocalAddresses() {
    try {
      Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
      while(interfaces.hasMoreElements()) {
          NetworkInterface inet = (NetworkInterface) interfaces.nextElement();
          Enumeration<InetAddress> addrs = inet.getInetAddresses();
          while (addrs.hasMoreElements()) {
              InetAddress addr = (InetAddress) addrs.nextElement();
              LOG.debug("local address:" + addr.getHostAddress());
              LOG.debug("local address:" + addr.getHostName());
              if(!addr.getHostAddress().isEmpty()) {
                localAddresses.add(addr.getHostAddress());
              }
              if(!addr.getHostName().isEmpty()) {
                localAddresses.add(addr.getHostName());
              }
          }
      }
      
      InetAddress inetAddress = InetAddress.getLocalHost();
      localAddresses.add(inetAddress.getHostAddress());
      localAddresses.add(inetAddress.getCanonicalHostName()); 
      localAddresses.add(inetAddress.getHostName()); 
      
      inetAddress = InetAddress.getLoopbackAddress();
      localAddresses.add(inetAddress.getHostAddress());
      localAddresses.add(inetAddress.getCanonicalHostName()); 
      localAddresses.add(inetAddress.getHostName()); 
    } catch(SocketException | UnknownHostException e ) {
      LOG.error("", e);
    }
  }
} public static final class DeleteRequest extends
    com.google.protobuf.GeneratedMessage
    implements DeleteRequestOrBuilder {
  // Use DeleteRequest.newBuilder() to construct.
  private DeleteRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private DeleteRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final DeleteRequest defaultInstance;
  public static DeleteRequest getDefaultInstance() {
    return defaultInstance;
  }

  public DeleteRequest getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private DeleteRequest(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 10: {
            bitField0_ |= 0x00000001;
            key_ = input.readBytes();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteRequest_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteRequest_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.Builder.class);
  }

  public static com.google.protobuf.Parser<DeleteRequest> PARSER =
      new com.google.protobuf.AbstractParser<DeleteRequest>() {
    public DeleteRequest parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new DeleteRequest(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<DeleteRequest> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bytes key = 1;
  public static final int KEY_FIELD_NUMBER = 1;
  private com.google.protobuf.ByteString key_;
  /**
   * <code>optional bytes key = 1;</code>
   */
  public boolean hasKey() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bytes key = 1;</code>
   */
  public com.google.protobuf.ByteString getKey() {
    return key_;
  }

  private void initFields() {
    key_ = com.google.protobuf.ByteString.EMPTY;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBytes(1, key_);
    }
    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, key_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest 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;
  }
  /**
   * Protobuf type {@code DeleteRequest}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequestOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteRequest_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteRequest_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      key_ = com.google.protobuf.ByteString.EMPTY;
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteRequest_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest result = new com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.key_ = key_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest.getDefaultInstance()) return this;
      if (other.hasKey()) {
        setKey(other.getKey());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bytes key = 1;
    private com.google.protobuf.ByteString key_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <code>optional bytes key = 1;</code>
     */
    public boolean hasKey() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public com.google.protobuf.ByteString getKey() {
      return key_;
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public Builder setKey(com.google.protobuf.ByteString value) {
      if (value == null) {
  throw new NullPointerException();
}
bitField0_ |= 0x00000001;
      key_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public Builder clearKey() {
      bitField0_ = (bitField0_ & ~0x00000001);
      key_ = getDefaultInstance().getKey();
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:DeleteRequest)
  }

  static {
    defaultInstance = new DeleteRequest(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:DeleteRequest)
} public static final class DeleteResponse extends
    com.google.protobuf.GeneratedMessage
    implements DeleteResponseOrBuilder {
  // Use DeleteResponse.newBuilder() to construct.
  private DeleteResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private DeleteResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final DeleteResponse defaultInstance;
  public static DeleteResponse getDefaultInstance() {
    return defaultInstance;
  }

  public DeleteResponse getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private DeleteResponse(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 8: {
            bitField0_ |= 0x00000001;
            success_ = input.readBool();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteResponse_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteResponse_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.Builder.class);
  }

  public static com.google.protobuf.Parser<DeleteResponse> PARSER =
      new com.google.protobuf.AbstractParser<DeleteResponse>() {
    public DeleteResponse parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new DeleteResponse(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<DeleteResponse> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bool success = 1;
  public static final int SUCCESS_FIELD_NUMBER = 1;
  private boolean success_;
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean hasSuccess() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean getSuccess() {
    return success_;
  }

  private void initFields() {
    success_ = false;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBool(1, success_);
    }
    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
        .computeBoolSize(1, success_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse 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;
  }
  /**
   * Protobuf type {@code DeleteResponse}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponseOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteResponse_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteResponse_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      success_ = false;
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_DeleteResponse_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse result = new com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.success_ = success_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse.getDefaultInstance()) return this;
      if (other.hasSuccess()) {
        setSuccess(other.getSuccess());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bool success = 1;
    private boolean success_ ;
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean hasSuccess() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean getSuccess() {
      return success_;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder setSuccess(boolean value) {
      bitField0_ |= 0x00000001;
      success_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder clearSuccess() {
      bitField0_ = (bitField0_ & ~0x00000001);
      success_ = false;
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:DeleteResponse)
  }

  static {
    defaultInstance = new DeleteResponse(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:DeleteResponse)
} public static final class GetRequest extends
    com.google.protobuf.GeneratedMessage
    implements GetRequestOrBuilder {
  // Use GetRequest.newBuilder() to construct.
  private GetRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private GetRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final GetRequest defaultInstance;
  public static GetRequest getDefaultInstance() {
    return defaultInstance;
  }

  public GetRequest getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private GetRequest(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 10: {
            bitField0_ |= 0x00000001;
            key_ = input.readBytes();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetRequest_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetRequest_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.Builder.class);
  }

  public static com.google.protobuf.Parser<GetRequest> PARSER =
      new com.google.protobuf.AbstractParser<GetRequest>() {
    public GetRequest parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new GetRequest(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<GetRequest> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bytes key = 1;
  public static final int KEY_FIELD_NUMBER = 1;
  private com.google.protobuf.ByteString key_;
  /**
   * <code>optional bytes key = 1;</code>
   */
  public boolean hasKey() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bytes key = 1;</code>
   */
  public com.google.protobuf.ByteString getKey() {
    return key_;
  }

  private void initFields() {
    key_ = com.google.protobuf.ByteString.EMPTY;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBytes(1, key_);
    }
    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, key_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest 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;
  }
  /**
   * Protobuf type {@code GetRequest}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequestOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetRequest_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetRequest_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      key_ = com.google.protobuf.ByteString.EMPTY;
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetRequest_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest result = new com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.key_ = key_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest.getDefaultInstance()) return this;
      if (other.hasKey()) {
        setKey(other.getKey());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bytes key = 1;
    private com.google.protobuf.ByteString key_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <code>optional bytes key = 1;</code>
     */
    public boolean hasKey() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public com.google.protobuf.ByteString getKey() {
      return key_;
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public Builder setKey(com.google.protobuf.ByteString value) {
      if (value == null) {
  throw new NullPointerException();
}
bitField0_ |= 0x00000001;
      key_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public Builder clearKey() {
      bitField0_ = (bitField0_ & ~0x00000001);
      key_ = getDefaultInstance().getKey();
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:GetRequest)
  }

  static {
    defaultInstance = new GetRequest(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:GetRequest)
} public static final class GetResponse extends
    com.google.protobuf.GeneratedMessage
    implements GetResponseOrBuilder {
  // Use GetResponse.newBuilder() to construct.
  private GetResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private GetResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final GetResponse defaultInstance;
  public static GetResponse getDefaultInstance() {
    return defaultInstance;
  }

  public GetResponse getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private GetResponse(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 10: {
            bitField0_ |= 0x00000001;
            value_ = input.readBytes();
            break;
          }
          case 16: {
            bitField0_ |= 0x00000002;
            success_ = input.readBool();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetResponse_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetResponse_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.Builder.class);
  }

  public static com.google.protobuf.Parser<GetResponse> PARSER =
      new com.google.protobuf.AbstractParser<GetResponse>() {
    public GetResponse parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new GetResponse(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<GetResponse> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bytes value = 1;
  public static final int VALUE_FIELD_NUMBER = 1;
  private com.google.protobuf.ByteString value_;
  /**
   * <code>optional bytes value = 1;</code>
   */
  public boolean hasValue() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bytes value = 1;</code>
   */
  public com.google.protobuf.ByteString getValue() {
    return value_;
  }

  // optional bool success = 2;
  public static final int SUCCESS_FIELD_NUMBER = 2;
  private boolean success_;
  /**
   * <code>optional bool success = 2;</code>
   */
  public boolean hasSuccess() {
    return ((bitField0_ & 0x00000002) == 0x00000002);
  }
  /**
   * <code>optional bool success = 2;</code>
   */
  public boolean getSuccess() {
    return success_;
  }

  private void initFields() {
    value_ = com.google.protobuf.ByteString.EMPTY;
    success_ = false;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBytes(1, value_);
    }
    if (((bitField0_ & 0x00000002) == 0x00000002)) {
      output.writeBool(2, success_);
    }
    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, value_);
    }
    if (((bitField0_ & 0x00000002) == 0x00000002)) {
      size += com.google.protobuf.CodedOutputStream
        .computeBoolSize(2, success_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse 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;
  }
  /**
   * Protobuf type {@code GetResponse}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponseOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetResponse_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetResponse_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      value_ = com.google.protobuf.ByteString.EMPTY;
      bitField0_ = (bitField0_ & ~0x00000001);
      success_ = false;
      bitField0_ = (bitField0_ & ~0x00000002);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_GetResponse_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse result = new com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.value_ = value_;
      if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
        to_bitField0_ |= 0x00000002;
      }
      result.success_ = success_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse.getDefaultInstance()) return this;
      if (other.hasValue()) {
        setValue(other.getValue());
      }
      if (other.hasSuccess()) {
        setSuccess(other.getSuccess());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bytes value = 1;
    private com.google.protobuf.ByteString value_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <code>optional bytes value = 1;</code>
     */
    public boolean hasValue() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bytes value = 1;</code>
     */
    public com.google.protobuf.ByteString getValue() {
      return value_;
    }
    /**
     * <code>optional bytes value = 1;</code>
     */
    public Builder setValue(com.google.protobuf.ByteString value) {
      if (value == null) {
  throw new NullPointerException();
}
bitField0_ |= 0x00000001;
      value_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bytes value = 1;</code>
     */
    public Builder clearValue() {
      bitField0_ = (bitField0_ & ~0x00000001);
      value_ = getDefaultInstance().getValue();
      onChanged();
      return this;
    }

    // optional bool success = 2;
    private boolean success_ ;
    /**
     * <code>optional bool success = 2;</code>
     */
    public boolean hasSuccess() {
      return ((bitField0_ & 0x00000002) == 0x00000002);
    }
    /**
     * <code>optional bool success = 2;</code>
     */
    public boolean getSuccess() {
      return success_;
    }
    /**
     * <code>optional bool success = 2;</code>
     */
    public Builder setSuccess(boolean value) {
      bitField0_ |= 0x00000002;
      success_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bool success = 2;</code>
     */
    public Builder clearSuccess() {
      bitField0_ = (bitField0_ & ~0x00000002);
      success_ = false;
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:GetResponse)
  }

  static {
    defaultInstance = new GetResponse(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:GetResponse)
} public static final class KeyValuePair extends
    com.google.protobuf.GeneratedMessage
    implements KeyValuePairOrBuilder {
  // Use KeyValuePair.newBuilder() to construct.
  private KeyValuePair(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private KeyValuePair(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final KeyValuePair defaultInstance;
  public static KeyValuePair getDefaultInstance() {
    return defaultInstance;
  }

  public KeyValuePair getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private KeyValuePair(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 10: {
            bitField0_ |= 0x00000001;
            key_ = input.readBytes();
            break;
          }
          case 18: {
            bitField0_ |= 0x00000002;
            value_ = input.readBytes();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_KeyValuePair_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_KeyValuePair_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.class, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder.class);
  }

  public static com.google.protobuf.Parser<KeyValuePair> PARSER =
      new com.google.protobuf.AbstractParser<KeyValuePair>() {
    public KeyValuePair parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new KeyValuePair(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<KeyValuePair> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bytes key = 1;
  public static final int KEY_FIELD_NUMBER = 1;
  private com.google.protobuf.ByteString key_;
  /**
   * <code>optional bytes key = 1;</code>
   */
  public boolean hasKey() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bytes key = 1;</code>
   */
  public com.google.protobuf.ByteString getKey() {
    return key_;
  }

  // optional bytes value = 2;
  public static final int VALUE_FIELD_NUMBER = 2;
  private com.google.protobuf.ByteString value_;
  /**
   * <code>optional bytes value = 2;</code>
   */
  public boolean hasValue() {
    return ((bitField0_ & 0x00000002) == 0x00000002);
  }
  /**
   * <code>optional bytes value = 2;</code>
   */
  public com.google.protobuf.ByteString getValue() {
    return value_;
  }

  private void initFields() {
    key_ = com.google.protobuf.ByteString.EMPTY;
    value_ = com.google.protobuf.ByteString.EMPTY;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBytes(1, key_);
    }
    if (((bitField0_ & 0x00000002) == 0x00000002)) {
      output.writeBytes(2, value_);
    }
    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, key_);
    }
    if (((bitField0_ & 0x00000002) == 0x00000002)) {
      size += com.google.protobuf.CodedOutputStream
        .computeBytesSize(2, value_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair 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;
  }
  /**
   * Protobuf type {@code KeyValuePair}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_KeyValuePair_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_KeyValuePair_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.class, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      key_ = com.google.protobuf.ByteString.EMPTY;
      bitField0_ = (bitField0_ & ~0x00000001);
      value_ = com.google.protobuf.ByteString.EMPTY;
      bitField0_ = (bitField0_ & ~0x00000002);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_KeyValuePair_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair result = new com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.key_ = key_;
      if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
        to_bitField0_ |= 0x00000002;
      }
      result.value_ = value_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance()) return this;
      if (other.hasKey()) {
        setKey(other.getKey());
      }
      if (other.hasValue()) {
        setValue(other.getValue());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bytes key = 1;
    private com.google.protobuf.ByteString key_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <code>optional bytes key = 1;</code>
     */
    public boolean hasKey() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public com.google.protobuf.ByteString getKey() {
      return key_;
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public Builder setKey(com.google.protobuf.ByteString value) {
      if (value == null) {
  throw new NullPointerException();
}
bitField0_ |= 0x00000001;
      key_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bytes key = 1;</code>
     */
    public Builder clearKey() {
      bitField0_ = (bitField0_ & ~0x00000001);
      key_ = getDefaultInstance().getKey();
      onChanged();
      return this;
    }

    // optional bytes value = 2;
    private com.google.protobuf.ByteString value_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <code>optional bytes value = 2;</code>
     */
    public boolean hasValue() {
      return ((bitField0_ & 0x00000002) == 0x00000002);
    }
    /**
     * <code>optional bytes value = 2;</code>
     */
    public com.google.protobuf.ByteString getValue() {
      return value_;
    }
    /**
     * <code>optional bytes value = 2;</code>
     */
    public Builder setValue(com.google.protobuf.ByteString value) {
      if (value == null) {
  throw new NullPointerException();
}
bitField0_ |= 0x00000002;
      value_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bytes value = 2;</code>
     */
    public Builder clearValue() {
      bitField0_ = (bitField0_ & ~0x00000002);
      value_ = getDefaultInstance().getValue();
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:KeyValuePair)
  }

  static {
    defaultInstance = new KeyValuePair(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:KeyValuePair)
} public static final class ListRequest extends
    com.google.protobuf.GeneratedMessage
    implements ListRequestOrBuilder {
  // Use ListRequest.newBuilder() to construct.
  private ListRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private ListRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final ListRequest defaultInstance;
  public static ListRequest getDefaultInstance() {
    return defaultInstance;
  }

  public ListRequest getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private ListRequest(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 10: {
            bitField0_ |= 0x00000001;
            pattern_ = input.readBytes();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListRequest_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListRequest_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.Builder.class);
  }

  public static com.google.protobuf.Parser<ListRequest> PARSER =
      new com.google.protobuf.AbstractParser<ListRequest>() {
    public ListRequest parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new ListRequest(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<ListRequest> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bytes pattern = 1;
  public static final int PATTERN_FIELD_NUMBER = 1;
  private com.google.protobuf.ByteString pattern_;
  /**
   * <code>optional bytes pattern = 1;</code>
   */
  public boolean hasPattern() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bytes pattern = 1;</code>
   */
  public com.google.protobuf.ByteString getPattern() {
    return pattern_;
  }

  private void initFields() {
    pattern_ = com.google.protobuf.ByteString.EMPTY;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBytes(1, pattern_);
    }
    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, pattern_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest 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;
  }
  /**
   * Protobuf type {@code ListRequest}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequestOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListRequest_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListRequest_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      pattern_ = com.google.protobuf.ByteString.EMPTY;
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListRequest_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest result = new com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.pattern_ = pattern_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest.getDefaultInstance()) return this;
      if (other.hasPattern()) {
        setPattern(other.getPattern());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bytes pattern = 1;
    private com.google.protobuf.ByteString pattern_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <code>optional bytes pattern = 1;</code>
     */
    public boolean hasPattern() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bytes pattern = 1;</code>
     */
    public com.google.protobuf.ByteString getPattern() {
      return pattern_;
    }
    /**
     * <code>optional bytes pattern = 1;</code>
     */
    public Builder setPattern(com.google.protobuf.ByteString value) {
      if (value == null) {
  throw new NullPointerException();
}
bitField0_ |= 0x00000001;
      pattern_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bytes pattern = 1;</code>
     */
    public Builder clearPattern() {
      bitField0_ = (bitField0_ & ~0x00000001);
      pattern_ = getDefaultInstance().getPattern();
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:ListRequest)
  }

  static {
    defaultInstance = new ListRequest(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:ListRequest)
} public static final class ListResponse extends
    com.google.protobuf.GeneratedMessage
    implements ListResponseOrBuilder {
  // Use ListResponse.newBuilder() to construct.
  private ListResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private ListResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final ListResponse defaultInstance;
  public static ListResponse getDefaultInstance() {
    return defaultInstance;
  }

  public ListResponse getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private ListResponse(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 8: {
            bitField0_ |= 0x00000001;
            success_ = input.readBool();
            break;
          }
          case 18: {
            if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
              results_ = new java.util.ArrayList<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair>();
              mutable_bitField0_ |= 0x00000002;
            }
            results_.add(input.readMessage(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.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.getMessage()).setUnfinishedMessage(this);
    } finally {
      if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
        results_ = java.util.Collections.unmodifiableList(results_);
      }
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListResponse_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListResponse_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.Builder.class);
  }

  public static com.google.protobuf.Parser<ListResponse> PARSER =
      new com.google.protobuf.AbstractParser<ListResponse>() {
    public ListResponse parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new ListResponse(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<ListResponse> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bool success = 1;
  public static final int SUCCESS_FIELD_NUMBER = 1;
  private boolean success_;
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean hasSuccess() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean getSuccess() {
    return success_;
  }

  // repeated .KeyValuePair results = 2;
  public static final int RESULTS_FIELD_NUMBER = 2;
  private java.util.List<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair> results_;
  /**
   * <code>repeated .KeyValuePair results = 2;</code>
   */
  public java.util.List<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair> getResultsList() {
    return results_;
  }
  /**
   * <code>repeated .KeyValuePair results = 2;</code>
   */
  public java.util.List<? extends com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder> 
      getResultsOrBuilderList() {
    return results_;
  }
  /**
   * <code>repeated .KeyValuePair results = 2;</code>
   */
  public int getResultsCount() {
    return results_.size();
  }
  /**
   * <code>repeated .KeyValuePair results = 2;</code>
   */
  public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair getResults(int index) {
    return results_.get(index);
  }
  /**
   * <code>repeated .KeyValuePair results = 2;</code>
   */
  public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder getResultsOrBuilder(
      int index) {
    return results_.get(index);
  }

  private void initFields() {
    success_ = false;
    results_ = java.util.Collections.emptyList();
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBool(1, success_);
    }
    for (int i = 0; i < results_.size(); i++) {
      output.writeMessage(2, results_.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
        .computeBoolSize(1, success_);
    }
    for (int i = 0; i < results_.size(); i++) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(2, results_.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 com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse 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;
  }
  /**
   * Protobuf type {@code ListResponse}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponseOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListResponse_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListResponse_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      super(parent);
      maybeForceBuilderInitialization();
    }
    private void maybeForceBuilderInitialization() {
      if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
        getResultsFieldBuilder();
      }
    }
    private static Builder create() {
      return new Builder();
    }

    public Builder clear() {
      super.clear();
      success_ = false;
      bitField0_ = (bitField0_ & ~0x00000001);
      if (resultsBuilder_ == null) {
        results_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000002);
      } else {
        resultsBuilder_.clear();
      }
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_ListResponse_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse result = new com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.success_ = success_;
      if (resultsBuilder_ == null) {
        if (((bitField0_ & 0x00000002) == 0x00000002)) {
          results_ = java.util.Collections.unmodifiableList(results_);
          bitField0_ = (bitField0_ & ~0x00000002);
        }
        result.results_ = results_;
      } else {
        result.results_ = resultsBuilder_.build();
      }
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse.getDefaultInstance()) return this;
      if (other.hasSuccess()) {
        setSuccess(other.getSuccess());
      }
      if (resultsBuilder_ == null) {
        if (!other.results_.isEmpty()) {
          if (results_.isEmpty()) {
            results_ = other.results_;
            bitField0_ = (bitField0_ & ~0x00000002);
          } else {
            ensureResultsIsMutable();
            results_.addAll(other.results_);
          }
          onChanged();
        }
      } else {
        if (!other.results_.isEmpty()) {
          if (resultsBuilder_.isEmpty()) {
            resultsBuilder_.dispose();
            resultsBuilder_ = null;
            results_ = other.results_;
            bitField0_ = (bitField0_ & ~0x00000002);
            resultsBuilder_ = 
              com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
                 getResultsFieldBuilder() : null;
          } else {
            resultsBuilder_.addAllMessages(other.results_);
          }
        }
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bool success = 1;
    private boolean success_ ;
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean hasSuccess() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean getSuccess() {
      return success_;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder setSuccess(boolean value) {
      bitField0_ |= 0x00000001;
      success_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder clearSuccess() {
      bitField0_ = (bitField0_ & ~0x00000001);
      success_ = false;
      onChanged();
      return this;
    }

    // repeated .KeyValuePair results = 2;
    private java.util.List<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair> results_ =
      java.util.Collections.emptyList();
    private void ensureResultsIsMutable() {
      if (!((bitField0_ & 0x00000002) == 0x00000002)) {
        results_ = new java.util.ArrayList<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair>(results_);
        bitField0_ |= 0x00000002;
       }
    }

    private com.google.protobuf.RepeatedFieldBuilder<
        com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder> resultsBuilder_;

    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public java.util.List<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair> getResultsList() {
      if (resultsBuilder_ == null) {
        return java.util.Collections.unmodifiableList(results_);
      } else {
        return resultsBuilder_.getMessageList();
      }
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public int getResultsCount() {
      if (resultsBuilder_ == null) {
        return results_.size();
      } else {
        return resultsBuilder_.getCount();
      }
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair getResults(int index) {
      if (resultsBuilder_ == null) {
        return results_.get(index);
      } else {
        return resultsBuilder_.getMessage(index);
      }
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder setResults(
        int index, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair value) {
      if (resultsBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureResultsIsMutable();
        results_.set(index, value);
        onChanged();
      } else {
        resultsBuilder_.setMessage(index, value);
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder setResults(
        int index, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder builderForValue) {
      if (resultsBuilder_ == null) {
        ensureResultsIsMutable();
        results_.set(index, builderForValue.build());
        onChanged();
      } else {
        resultsBuilder_.setMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder addResults(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair value) {
      if (resultsBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureResultsIsMutable();
        results_.add(value);
        onChanged();
      } else {
        resultsBuilder_.addMessage(value);
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder addResults(
        int index, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair value) {
      if (resultsBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureResultsIsMutable();
        results_.add(index, value);
        onChanged();
      } else {
        resultsBuilder_.addMessage(index, value);
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder addResults(
        com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder builderForValue) {
      if (resultsBuilder_ == null) {
        ensureResultsIsMutable();
        results_.add(builderForValue.build());
        onChanged();
      } else {
        resultsBuilder_.addMessage(builderForValue.build());
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder addResults(
        int index, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder builderForValue) {
      if (resultsBuilder_ == null) {
        ensureResultsIsMutable();
        results_.add(index, builderForValue.build());
        onChanged();
      } else {
        resultsBuilder_.addMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder addAllResults(
        java.lang.Iterable<? extends com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair> values) {
      if (resultsBuilder_ == null) {
        ensureResultsIsMutable();
        super.addAll(values, results_);
        onChanged();
      } else {
        resultsBuilder_.addAllMessages(values);
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder clearResults() {
      if (resultsBuilder_ == null) {
        results_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000002);
        onChanged();
      } else {
        resultsBuilder_.clear();
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public Builder removeResults(int index) {
      if (resultsBuilder_ == null) {
        ensureResultsIsMutable();
        results_.remove(index);
        onChanged();
      } else {
        resultsBuilder_.remove(index);
      }
      return this;
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder getResultsBuilder(
        int index) {
      return getResultsFieldBuilder().getBuilder(index);
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder getResultsOrBuilder(
        int index) {
      if (resultsBuilder_ == null) {
        return results_.get(index);  } else {
        return resultsBuilder_.getMessageOrBuilder(index);
      }
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public java.util.List<? extends com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder> 
         getResultsOrBuilderList() {
      if (resultsBuilder_ != null) {
        return resultsBuilder_.getMessageOrBuilderList();
      } else {
        return java.util.Collections.unmodifiableList(results_);
      }
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder addResultsBuilder() {
      return getResultsFieldBuilder().addBuilder(
          com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance());
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder addResultsBuilder(
        int index) {
      return getResultsFieldBuilder().addBuilder(
          index, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance());
    }
    /**
     * <code>repeated .KeyValuePair results = 2;</code>
     */
    public java.util.List<com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder> 
         getResultsBuilderList() {
      return getResultsFieldBuilder().getBuilderList();
    }
    private com.google.protobuf.RepeatedFieldBuilder<
        com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder> 
        getResultsFieldBuilder() {
      if (resultsBuilder_ == null) {
        resultsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
            com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder>(
                results_,
                ((bitField0_ & 0x00000002) == 0x00000002),
                getParentForChildren(),
                isClean());
        results_ = null;
      }
      return resultsBuilder_;
    }

    // @@protoc_insertion_point(builder_scope:ListResponse)
  }

  static {
    defaultInstance = new ListResponse(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:ListResponse)
} public static final class LookupLeaderRequest extends
    com.google.protobuf.GeneratedMessage
    implements LookupLeaderRequestOrBuilder {
  // Use LookupLeaderRequest.newBuilder() to construct.
  private LookupLeaderRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private LookupLeaderRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final LookupLeaderRequest defaultInstance;
  public static LookupLeaderRequest getDefaultInstance() {
    return defaultInstance;
  }

  public LookupLeaderRequest getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private LookupLeaderRequest(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderRequest_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderRequest_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.Builder.class);
  }

  public static com.google.protobuf.Parser<LookupLeaderRequest> PARSER =
      new com.google.protobuf.AbstractParser<LookupLeaderRequest>() {
    public LookupLeaderRequest parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new LookupLeaderRequest(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<LookupLeaderRequest> getParserForType() {
    return PARSER;
  }

  private void initFields() {
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    getUnknownFields().writeTo(output);
  }

  private int memoizedSerializedSize = -1;
  public int getSerializedSize() {
    int size = memoizedSerializedSize;
    if (size != -1) return size;

    size = 0;
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest 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;
  }
  /**
   * Protobuf type {@code LookupLeaderRequest}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequestOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderRequest_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderRequest_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderRequest_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest result = new com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest(this);
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest.getDefaultInstance()) return this;
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }

    // @@protoc_insertion_point(builder_scope:LookupLeaderRequest)
  }

  static {
    defaultInstance = new LookupLeaderRequest(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:LookupLeaderRequest)
} public static final class LookupLeaderResponse extends
    com.google.protobuf.GeneratedMessage
    implements LookupLeaderResponseOrBuilder {
  // Use LookupLeaderResponse.newBuilder() to construct.
  private LookupLeaderResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private LookupLeaderResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final LookupLeaderResponse defaultInstance;
  public static LookupLeaderResponse getDefaultInstance() {
    return defaultInstance;
  }

  public LookupLeaderResponse getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private LookupLeaderResponse(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 8: {
            bitField0_ |= 0x00000001;
            success_ = input.readBool();
            break;
          }
          case 18: {
            com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.Builder subBuilder = null;
            if (((bitField0_ & 0x00000002) == 0x00000002)) {
              subBuilder = leader_.toBuilder();
            }
            leader_ = input.readMessage(com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.PARSER, extensionRegistry);
            if (subBuilder != null) {
              subBuilder.mergeFrom(leader_);
              leader_ = subBuilder.buildPartial();
            }
            bitField0_ |= 0x00000002;
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderResponse_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderResponse_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.Builder.class);
  }

  public static com.google.protobuf.Parser<LookupLeaderResponse> PARSER =
      new com.google.protobuf.AbstractParser<LookupLeaderResponse>() {
    public LookupLeaderResponse parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new LookupLeaderResponse(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<LookupLeaderResponse> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bool success = 1;
  public static final int SUCCESS_FIELD_NUMBER = 1;
  private boolean success_;
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean hasSuccess() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean getSuccess() {
    return success_;
  }

  // optional .ServerId leader = 2;
  public static final int LEADER_FIELD_NUMBER = 2;
  private com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId leader_;
  /**
   * <code>optional .ServerId leader = 2;</code>
   */
  public boolean hasLeader() {
    return ((bitField0_ & 0x00000002) == 0x00000002);
  }
  /**
   * <code>optional .ServerId leader = 2;</code>
   */
  public com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId getLeader() {
    return leader_;
  }
  /**
   * <code>optional .ServerId leader = 2;</code>
   */
  public com.chicm.cmraft.protobuf.generated.RaftProtos.ServerIdOrBuilder getLeaderOrBuilder() {
    return leader_;
  }

  private void initFields() {
    success_ = false;
    leader_ = com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.getDefaultInstance();
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    if (hasLeader()) {
      if (!getLeader().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.writeBool(1, success_);
    }
    if (((bitField0_ & 0x00000002) == 0x00000002)) {
      output.writeMessage(2, leader_);
    }
    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
        .computeBoolSize(1, success_);
    }
    if (((bitField0_ & 0x00000002) == 0x00000002)) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(2, leader_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse 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;
  }
  /**
   * Protobuf type {@code LookupLeaderResponse}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponseOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderResponse_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderResponse_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      super(parent);
      maybeForceBuilderInitialization();
    }
    private void maybeForceBuilderInitialization() {
      if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
        getLeaderFieldBuilder();
      }
    }
    private static Builder create() {
      return new Builder();
    }

    public Builder clear() {
      super.clear();
      success_ = false;
      bitField0_ = (bitField0_ & ~0x00000001);
      if (leaderBuilder_ == null) {
        leader_ = com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.getDefaultInstance();
      } else {
        leaderBuilder_.clear();
      }
      bitField0_ = (bitField0_ & ~0x00000002);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_LookupLeaderResponse_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse result = new com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.success_ = success_;
      if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
        to_bitField0_ |= 0x00000002;
      }
      if (leaderBuilder_ == null) {
        result.leader_ = leader_;
      } else {
        result.leader_ = leaderBuilder_.build();
      }
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse.getDefaultInstance()) return this;
      if (other.hasSuccess()) {
        setSuccess(other.getSuccess());
      }
      if (other.hasLeader()) {
        mergeLeader(other.getLeader());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      return this;
    }

    public final boolean isInitialized() {
      if (hasLeader()) {
        if (!getLeader().isInitialized()) {
            
          return false;
        }
      }
      return true;
    }

    public Builder mergeFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bool success = 1;
    private boolean success_ ;
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean hasSuccess() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean getSuccess() {
      return success_;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder setSuccess(boolean value) {
      bitField0_ |= 0x00000001;
      success_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder clearSuccess() {
      bitField0_ = (bitField0_ & ~0x00000001);
      success_ = false;
      onChanged();
      return this;
    }

    // optional .ServerId leader = 2;
    private com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId leader_ = com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.getDefaultInstance();
    private com.google.protobuf.SingleFieldBuilder<
        com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId, com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.ServerIdOrBuilder> leaderBuilder_;
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public boolean hasLeader() {
      return ((bitField0_ & 0x00000002) == 0x00000002);
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId getLeader() {
      if (leaderBuilder_ == null) {
        return leader_;
      } else {
        return leaderBuilder_.getMessage();
      }
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public Builder setLeader(com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId value) {
      if (leaderBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        leader_ = value;
        onChanged();
      } else {
        leaderBuilder_.setMessage(value);
      }
      bitField0_ |= 0x00000002;
      return this;
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public Builder setLeader(
        com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.Builder builderForValue) {
      if (leaderBuilder_ == null) {
        leader_ = builderForValue.build();
        onChanged();
      } else {
        leaderBuilder_.setMessage(builderForValue.build());
      }
      bitField0_ |= 0x00000002;
      return this;
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public Builder mergeLeader(com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId value) {
      if (leaderBuilder_ == null) {
        if (((bitField0_ & 0x00000002) == 0x00000002) &&
            leader_ != com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.getDefaultInstance()) {
          leader_ =
            com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.newBuilder(leader_).mergeFrom(value).buildPartial();
        } else {
          leader_ = value;
        }
        onChanged();
      } else {
        leaderBuilder_.mergeFrom(value);
      }
      bitField0_ |= 0x00000002;
      return this;
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public Builder clearLeader() {
      if (leaderBuilder_ == null) {
        leader_ = com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.getDefaultInstance();
        onChanged();
      } else {
        leaderBuilder_.clear();
      }
      bitField0_ = (bitField0_ & ~0x00000002);
      return this;
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.Builder getLeaderBuilder() {
      bitField0_ |= 0x00000002;
      onChanged();
      return getLeaderFieldBuilder().getBuilder();
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.ServerIdOrBuilder getLeaderOrBuilder() {
      if (leaderBuilder_ != null) {
        return leaderBuilder_.getMessageOrBuilder();
      } else {
        return leader_;
      }
    }
    /**
     * <code>optional .ServerId leader = 2;</code>
     */
    private com.google.protobuf.SingleFieldBuilder<
        com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId, com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.ServerIdOrBuilder> 
        getLeaderFieldBuilder() {
      if (leaderBuilder_ == null) {
        leaderBuilder_ = new com.google.protobuf.SingleFieldBuilder<
            com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId, com.chicm.cmraft.protobuf.generated.RaftProtos.ServerId.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.ServerIdOrBuilder>(
                leader_,
                getParentForChildren(),
                isClean());
        leader_ = null;
      }
      return leaderBuilder_;
    }

    // @@protoc_insertion_point(builder_scope:LookupLeaderResponse)
  }

  static {
    defaultInstance = new LookupLeaderResponse(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:LookupLeaderResponse)
} public static final class SetRequest extends
    com.google.protobuf.GeneratedMessage
    implements SetRequestOrBuilder {
  // Use SetRequest.newBuilder() to construct.
  private SetRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private SetRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final SetRequest defaultInstance;
  public static SetRequest getDefaultInstance() {
    return defaultInstance;
  }

  public SetRequest getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private SetRequest(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 10: {
            com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder subBuilder = null;
            if (((bitField0_ & 0x00000001) == 0x00000001)) {
              subBuilder = kv_.toBuilder();
            }
            kv_ = input.readMessage(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.PARSER, extensionRegistry);
            if (subBuilder != null) {
              subBuilder.mergeFrom(kv_);
              kv_ = subBuilder.buildPartial();
            }
            bitField0_ |= 0x00000001;
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetRequest_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetRequest_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.Builder.class);
  }

  public static com.google.protobuf.Parser<SetRequest> PARSER =
      new com.google.protobuf.AbstractParser<SetRequest>() {
    public SetRequest parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new SetRequest(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<SetRequest> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional .KeyValuePair kv = 1;
  public static final int KV_FIELD_NUMBER = 1;
  private com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair kv_;
  /**
   * <code>optional .KeyValuePair kv = 1;</code>
   */
  public boolean hasKv() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional .KeyValuePair kv = 1;</code>
   */
  public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair getKv() {
    return kv_;
  }
  /**
   * <code>optional .KeyValuePair kv = 1;</code>
   */
  public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder getKvOrBuilder() {
    return kv_;
  }

  private void initFields() {
    kv_ = com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance();
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeMessage(1, kv_);
    }
    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
        .computeMessageSize(1, kv_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest 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;
  }
  /**
   * Protobuf type {@code SetRequest}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequestOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetRequest_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetRequest_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.class, com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      super(parent);
      maybeForceBuilderInitialization();
    }
    private void maybeForceBuilderInitialization() {
      if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
        getKvFieldBuilder();
      }
    }
    private static Builder create() {
      return new Builder();
    }

    public Builder clear() {
      super.clear();
      if (kvBuilder_ == null) {
        kv_ = com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance();
      } else {
        kvBuilder_.clear();
      }
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetRequest_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest result = new com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      if (kvBuilder_ == null) {
        result.kv_ = kv_;
      } else {
        result.kv_ = kvBuilder_.build();
      }
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest.getDefaultInstance()) return this;
      if (other.hasKv()) {
        mergeKv(other.getKv());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional .KeyValuePair kv = 1;
    private com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair kv_ = com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance();
    private com.google.protobuf.SingleFieldBuilder<
        com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder> kvBuilder_;
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public boolean hasKv() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair getKv() {
      if (kvBuilder_ == null) {
        return kv_;
      } else {
        return kvBuilder_.getMessage();
      }
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public Builder setKv(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair value) {
      if (kvBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        kv_ = value;
        onChanged();
      } else {
        kvBuilder_.setMessage(value);
      }
      bitField0_ |= 0x00000001;
      return this;
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public Builder setKv(
        com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder builderForValue) {
      if (kvBuilder_ == null) {
        kv_ = builderForValue.build();
        onChanged();
      } else {
        kvBuilder_.setMessage(builderForValue.build());
      }
      bitField0_ |= 0x00000001;
      return this;
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public Builder mergeKv(com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair value) {
      if (kvBuilder_ == null) {
        if (((bitField0_ & 0x00000001) == 0x00000001) &&
            kv_ != com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance()) {
          kv_ =
            com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.newBuilder(kv_).mergeFrom(value).buildPartial();
        } else {
          kv_ = value;
        }
        onChanged();
      } else {
        kvBuilder_.mergeFrom(value);
      }
      bitField0_ |= 0x00000001;
      return this;
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public Builder clearKv() {
      if (kvBuilder_ == null) {
        kv_ = com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.getDefaultInstance();
        onChanged();
      } else {
        kvBuilder_.clear();
      }
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder getKvBuilder() {
      bitField0_ |= 0x00000001;
      onChanged();
      return getKvFieldBuilder().getBuilder();
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    public com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder getKvOrBuilder() {
      if (kvBuilder_ != null) {
        return kvBuilder_.getMessageOrBuilder();
      } else {
        return kv_;
      }
    }
    /**
     * <code>optional .KeyValuePair kv = 1;</code>
     */
    private com.google.protobuf.SingleFieldBuilder<
        com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder> 
        getKvFieldBuilder() {
      if (kvBuilder_ == null) {
        kvBuilder_ = new com.google.protobuf.SingleFieldBuilder<
            com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair.Builder, com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePairOrBuilder>(
                kv_,
                getParentForChildren(),
                isClean());
        kv_ = null;
      }
      return kvBuilder_;
    }

    // @@protoc_insertion_point(builder_scope:SetRequest)
  }

  static {
    defaultInstance = new SetRequest(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:SetRequest)
} public static final class SetResponse extends
    com.google.protobuf.GeneratedMessage
    implements SetResponseOrBuilder {
  // Use SetResponse.newBuilder() to construct.
  private SetResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
    super(builder);
    this.unknownFields = builder.getUnknownFields();
  }
  private SetResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

  private static final SetResponse defaultInstance;
  public static SetResponse getDefaultInstance() {
    return defaultInstance;
  }

  public SetResponse getDefaultInstanceForType() {
    return defaultInstance;
  }

  private final com.google.protobuf.UnknownFieldSet unknownFields;
  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
      getUnknownFields() {
    return this.unknownFields;
  }
  private SetResponse(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    initFields();
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownField(input, unknownFields,
                                   extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 8: {
            bitField0_ |= 0x00000001;
            success_ = input.readBool();
            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e.getMessage()).setUnfinishedMessage(this);
    } finally {
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetResponse_descriptor;
  }

  protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetResponse_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.Builder.class);
  }

  public static com.google.protobuf.Parser<SetResponse> PARSER =
      new com.google.protobuf.AbstractParser<SetResponse>() {
    public SetResponse parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new SetResponse(input, extensionRegistry);
    }
  };

  @java.lang.Override
  public com.google.protobuf.Parser<SetResponse> getParserForType() {
    return PARSER;
  }

  private int bitField0_;
  // optional bool success = 1;
  public static final int SUCCESS_FIELD_NUMBER = 1;
  private boolean success_;
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean hasSuccess() {
    return ((bitField0_ & 0x00000001) == 0x00000001);
  }
  /**
   * <code>optional bool success = 1;</code>
   */
  public boolean getSuccess() {
    return success_;
  }

  private void initFields() {
    success_ = false;
  }
  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized != -1) return isInitialized == 1;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    getSerializedSize();
    if (((bitField0_ & 0x00000001) == 0x00000001)) {
      output.writeBool(1, success_);
    }
    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
        .computeBoolSize(1, success_);
    }
    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 com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseDelimitedFrom(input, extensionRegistry);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return PARSER.parseFrom(input);
  }
  public static com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return PARSER.parseFrom(input, extensionRegistry);
  }

  public static Builder newBuilder() { return Builder.create(); }
  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder(com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse 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;
  }
  /**
   * Protobuf type {@code SetResponse}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessage.Builder<Builder>
     implements com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponseOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetResponse_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetResponse_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.class, com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.Builder.class);
    }

    // Construct using com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessage.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();
      success_ = false;
      bitField0_ = (bitField0_ & ~0x00000001);
      return this;
    }

    public Builder clone() {
      return create().mergeFrom(buildPartial());
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.internal_static_SetResponse_descriptor;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse getDefaultInstanceForType() {
      return com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.getDefaultInstance();
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse build() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse buildPartial() {
      com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse result = new com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
        to_bitField0_ |= 0x00000001;
      }
      result.success_ = success_;
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse) {
        return mergeFrom((com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse other) {
      if (other == com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse.getDefaultInstance()) return this;
      if (other.hasSuccess()) {
        setSuccess(other.getSuccess());
      }
      this.mergeUnknownFields(other.getUnknownFields());
      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.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse) e.getUnfinishedMessage();
        throw e;
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    // optional bool success = 1;
    private boolean success_ ;
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean hasSuccess() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public boolean getSuccess() {
      return success_;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder setSuccess(boolean value) {
      bitField0_ |= 0x00000001;
      success_ = value;
      onChanged();
      return this;
    }
    /**
     * <code>optional bool success = 1;</code>
     */
    public Builder clearSuccess() {
      bitField0_ = (bitField0_ & ~0x00000001);
      success_ = false;
      onChanged();
      return this;
    }

    // @@protoc_insertion_point(builder_scope:SetResponse)
  }

  static {
    defaultInstance = new SetResponse(true);
    defaultInstance.initFields();
  }

  // @@protoc_insertion_point(class_scope:SetResponse)
} public class RpcClient {
  static final Log LOG = LogFactory.getLog(RpcClient.class);
  private final static String RPC_TIMEOUT_KEY = "raft.rpc.timeout";
  private final static int DEFAULT_RPC_TIMEOUT = 3000;
  private static volatile AtomicInteger client_call_id = new AtomicInteger(0);
  private BlockingInterface stub = null;
  private ChannelHandlerContext ctx = null;
  private BlockingHashMap<Integer, RpcCall> responsesMap = new BlockingHashMap<>();
  private RpcClientEventListener listener = new RpcClientEventListenerImpl();
  private volatile boolean connected = false;
  private int rpcTimeout;
  private ServerInfo remoteServer = null;
  
  public RpcClient(Configuration conf, ServerInfo remoteServer) {
    rpcTimeout = conf.getInt(RPC_TIMEOUT_KEY, DEFAULT_RPC_TIMEOUT);
    this.remoteServer = remoteServer;
    //todo: to change call id init value
    Random r = new Random();
    client_call_id.set(r.nextInt(1000) * 100);
  }
  
  public boolean isConnected() {
    if(ctx == null)
      return false;
    if(!ctx.channel().isActive())
      return false;
    return connected;
  }
  
  public synchronized boolean connect() 
      throws IOException, InterruptedException, ExecutionException {
    
    if(isConnected())
      return true;
    try {
      ctx = connectRemoteServer();
    } catch(Exception e) {
      LOG.error("Failed connecting to:" + getRemoteServer() + " : " + e.getMessage());
      try {
        if(ctx != null && ctx.channel().isOpen()) {
          ctx.close().sync();
        }
      } catch(Exception e2) {
        LOG.error("Failed closing ctx, " + e2.getMessage());
      }
      throw e;
    }
    
    BlockingRpcChannel c = createBlockingRpcChannel();
    stub =  RaftService.newBlockingStub(c);
    
    connected = true;
    return connected;
  }
  
  public ServerInfo getRemoteServer() {
    return remoteServer;
  }
  
  public synchronized void close() {
    try {
      LOG.info("Closing connection");
      ctx.close().sync();
      connected = false;
    } catch(Exception e) {
      LOG.error("Closing failed", e);
    }
  }
  
  public BlockingInterface getStub() throws Exception {
    if(!isConnected()) {
        if(!connect()) {
          return null;
        }
    }
    return stub;
  }
  
  private ChannelHandlerContext connectRemoteServer() throws InterruptedException  {
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    
    try {
      ClientChannelHandler channelHandler = new ClientChannelHandler(listener);
      Bootstrap b = new Bootstrap(); 
      b.group(workerGroup); 
      b.channel(NioSocketChannel.class); 
      b.option(ChannelOption.SO_KEEPALIVE, true); 
      b.handler(channelHandler);

      ChannelFuture f = b.connect(getRemoteServer().getHost(), getRemoteServer().getPort()).sync(); 
      LOG.debug("connected to: " + this.getRemoteServer() );
      return channelHandler.getCtx();
        // Wait until the connection is closed.
        //f.channel().closeFuture().sync();
    } finally {
        //workerGroup.shutdownGracefully();
    }
  }
  
  public static int generateCallId() {
    return client_call_id.incrementAndGet();
  }
  
  public static int getCallId() {
    return client_call_id.get();
  }
 
  private  BlockingRpcChannel createBlockingRpcChannel() {
    return new BlockingRpcChannelImplementation();
  }

  class BlockingRpcChannelImplementation implements BlockingRpcChannel {
    @Override
    public Message callBlockingMethod(MethodDescriptor md, RpcController controller,
                                      Message request, Message returnType) throws ServiceException {

      Message response = null;
      int callId = generateCallId();
      try {
        RequestHeader.Builder builder = RequestHeader.newBuilder();
        builder.setId(callId); 
        builder.setRequestName(md.getName());
        RequestHeader header = builder.build();
        
        LOG.debug("SENDING RPC, CALLID:" + header.getId());
        RpcCall call = new RpcCall(callId, header, request, md);
        long tm = System.currentTimeMillis();
        
        ctx.writeAndFlush(call);
        
        RpcCall result = responsesMap.take(callId, rpcTimeout);
        
        response = result != null? result.getMessage() : null;
        if(response != null) {
          LOG.debug("response taken: " + callId);
          LOG.debug(String.format("RPC[%d] round trip takes %d ms", header.getId(), (System.currentTimeMillis() - tm)));
        }
      } catch(RpcTimeoutException e) {
        LOG.error("Rpc Timeout, call ID:" + callId + ", remote server:" + getRemoteServer());
        LOG.error("Rpc Timeout, call:" + request);
        LOG.error("Rpc Timeout", e);
        ServiceException se = new ServiceException(e.getMessage(), e);
        throw se;
      } catch(Exception e) {
        LOG.error("ctx:" + ctx);
        LOG.error("callBlockingMethod exception", e);
        throw e;
      }
      return response;
    }
  }
  
 
  class RpcClientEventListenerImpl implements RpcClientEventListener {
    @Override
    public void channelClosed() {
      ctx.close();
      connected = false;
    }
    @Override
    public void onRpcResponse(RpcCall call) {
      Preconditions.checkNotNull(call);
      responsesMap.put(call.getCallId(), call);      
    }
  }
  
  /*
   * For testing purpose
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    if(args.length < 3) {
      System.out.println("usage: RpcClient <server host> <server port> <clients number> <threads number> <packetsize>");
      return;
    }
    String host = args[0];
    int port = Integer.parseInt(args[1]);
    int nclients = Integer.parseInt(args[2]);
    int nThreads = Integer.parseInt(args[3]);
    int nPacketSize = 1024;

    if(args.length >= 5) {
      nPacketSize = Integer.parseInt(args[4]);
    }
    
    for(int j =0; j < nclients; j++ ) {
      RpcClient client = new RpcClient(CmRaftConfiguration.create(), new ServerInfo(host, port));
      
      for(int i = 0; i < nThreads; i++) {
        new Thread(new TestRpcWorker(client, nPacketSize)).start();
      }
    }
  }
  
  static class TestRpcWorker implements Runnable{
    private RpcClient client;
    private int packetSize;
    
    public TestRpcWorker(RpcClient client, int size) {
      this.client = client;
      this.packetSize = size;
    }
    @Override
    public void run() {
      client.sendRequest(packetSize);
    }
  }
  
  public void testRpc(int packetSize) throws Exception {
    TestRpcRequest.Builder builder = TestRpcRequest.newBuilder();
    byte[] bytes = new byte[packetSize];
    builder.setData(ByteString.copyFrom(bytes));
    
    stub.testRpc(null, builder.build());
  }
  
  private ThreadLocal<Long> startTime = new ThreadLocal<>();
  
  /*
   * For testing purpose
   */
  public void sendRequest(int packetSize) {
    
    if(!this.isConnected()) {
      try {
        if(!connect()) {
          LOG.error("INIT error");
          return;
        }
      } catch(Exception e) {
        LOG.error("RpcClient init exception", e);
        return;
      }
    }
    
    LOG.info("client thread started");
    long starttime = System.currentTimeMillis();
    try {
      for(int i = 0; i < 5000000 ;i++) {
        startTime.set(System.currentTimeMillis());
        testRpc(packetSize);
        if(i != 0 && i %1000 == 0 ) {
          long ms = System.currentTimeMillis() - starttime;
          LOG.debug("RPC CALL[ " + i + "] round trip time: " + ms);
          
          long curtm = System.currentTimeMillis();
          long elipsetm = (curtm - starttime) /1000;
          if(elipsetm == 0)
            elipsetm =1;
          long tps = i / elipsetm;
          
          LOG.info("response id: " + i + " time: " + elipsetm + " TPS: " + tps);
        }
      }
    } catch (Exception e) {
      e.printStackTrace(System.out);
    } 
  }
}
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.chicm.cmraft.common.CmRaftConfiguration;
import com.chicm.cmraft.common.Configuration;
import com.chicm.cmraft.common.ServerInfo;
import com.chicm.cmraft.core.ClusterMemberManager;
import com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteRequest;
import com.chicm.cmraft.protobuf.generated.RaftProtos.DeleteResponse;
import com.chicm.cmraft.protobuf.generated.RaftProtos.GetRequest;
import com.chicm.cmraft.protobuf.generated.RaftProtos.GetResponse;
import com.chicm.cmraft.protobuf.generated.RaftProtos.KeyValuePair;
import com.chicm.cmraft.protobuf.generated.RaftProtos.ListRequest;
import com.chicm.cmraft.protobuf.generated.RaftProtos.ListResponse;
import com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderRequest;
import com.chicm.cmraft.protobuf.generated.RaftProtos.LookupLeaderResponse;
import com.chicm.cmraft.protobuf.generated.RaftProtos.SetRequest;
import com.chicm.cmraft.protobuf.generated.RaftProtos.SetResponse;
import com.chicm.cmraft.rpc.RpcClient;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.ServiceException;
/**
* Copyright 2014 The CmRaft Project
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.chicm.cmraft;




public class ConnectionManager {
  static final Log LOG = LogFactory.getLog(ConnectionManager.class);
  private RpcClient rpcClient;
  private ConnectionImpl userConnection;
  private KeyValueStore kvs;
  private ServerInfo remoteServer;
  
  private ConnectionManager(Configuration conf, Set<ServerInfo> servers) {
    Preconditions.checkNotNull(servers);
    Preconditions.checkArgument(!servers.isEmpty());
    boolean connected = false;
    LOG.info("Raft servers:" + servers);
    for(ServerInfo server: servers) {
      LOG.info("Trying connect to:" + server);
      try {
        RpcClient rpc = new RpcClient(conf, server);
        if(rpc.connect()) {
          rpcClient = rpc;
          remoteServer = server;
          connected = true;
          break;
        }
      } catch(Exception e) {
        LOG.error("Failed connecting to:" + server, e);
      }
    }
    
    if(!connected) {
      String msg = "Could not connect to all raft servers";
      LOG.error(msg);
      RuntimeException e = new RuntimeException(msg);
      throw e;
    } else {
      LOG.info("Connected to: " + remoteServer);
    }
    
    connected = false;
    ServerInfo leader = lookupLeader();
    LOG.info("lookupLeader:" + leader);
    if(leader != null && !leader.equals(remoteServer)) {
      LOG.info("closing connection to " + remoteServer + ", connecting to " + leader);
      try {
        rpcClient.close();
        RpcClient rpcLeader = new RpcClient(conf, leader);
        if(rpcLeader.connect()) {
          rpcClient = rpcLeader;
          remoteServer = leader;
          connected = true;
        }
      } catch(Exception e) {
        LOG.error("Failed connecting to:" + leader, e);
      }
    } else if(leader != null && leader.equals(remoteServer)) {
      LOG.info("This connected server is leader:" + leader);
      connected = true;
    } else if(leader == null) {
      LOG.error("Could not get Leader info");
    }
    
    if(!connected) {
      RuntimeException e = new RuntimeException("Could not connect to leader:" + leader);
      throw e;
    }
    Preconditions.checkArgument(rpcClient.isConnected());
    
    userConnection = new ConnectionImpl();
    kvs = new KeyValueStoreImpl();
  }
  
  public ServerInfo getRemoteServer() {
    return remoteServer;
  }
  
  public static Connection getConnection() {
    return getConnection(CmRaftConfiguration.create());
  }
  
  public static Connection getConnection(Configuration conf) {
    ConnectionManager mgr = new ConnectionManager(conf, ClusterMemberManager.getRaftServers(conf));