protected static byte[] toByteArray(final ReplicationProtos.ReplicationState.State state) {
    ReplicationProtos.ReplicationState msg =
      ReplicationProtos.ReplicationState.newBuilder().setState(state).build();
    // There is no toByteArray on this pb Message?
    // 32 bytes is default which seems fair enough here.
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      CodedOutputStream cos = CodedOutputStream.newInstance(baos, 16);
      msg.writeTo(cos);
      cos.flush();
      baos.flush();
      return ProtobufUtil.prependPBMagic(baos.toByteArray());
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Serialized protobuf of <code>state</code> with pb magic prefix prepended suitable for use as
content of a peer-state znode under a peer cluster id as in
/hbase/replication/peers/PEER_ID/peer-state.
hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ZKReplicationStorageBase.java