From db77f058c92ee3d0b531c474093d6a3d1d81cd25 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 26 May 2014 12:17:41 +0000
Subject: [PATCH] Ensured no accidental protocol break can happen by renaming all ByteArrayBuilder.append*() methods and getting rid of all method overloading.

---
 opends/src/server/org/opends/server/replication/protocol/InitializeRcvAckMsg.java                   |    8 
 opends/src/server/org/opends/server/replication/protocol/ServerStartECLMsg.java                     |   21 +-
 opends/src/server/org/opends/server/replication/protocol/StartMsg.java                              |   16 
 opends/src/server/org/opends/server/replication/protocol/AckMsg.java                                |   12 
 opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java                         |   26 +-
 opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java                  |   21 +-
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ByteArrayTest.java |   45 ++--
 opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java                             |   14 
 opends/src/server/org/opends/server/replication/protocol/MonitorMsg.java                            |   10 
 opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java                          |   10 
 opends/src/server/org/opends/server/replication/protocol/MonitorRequestMsg.java                     |    6 
 opends/src/server/org/opends/server/replication/protocol/DoneMsg.java                               |    6 
 opends/src/server/org/opends/server/replication/protocol/EntryMsg.java                              |   10 
 opends/src/server/org/opends/server/replication/protocol/WindowMsg.java                             |    4 
 opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java                   |   14 
 opends/src/server/org/opends/server/replication/protocol/ReplServerStartMsg.java                    |   30 +-
 opends/src/server/org/opends/server/replication/protocol/ServerStartMsg.java                        |   25 +-
 opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java                       |   12 
 opends/src/server/org/opends/server/replication/protocol/ErrorMsg.java                              |   12 
 opends/src/server/org/opends/server/replication/protocol/AddMsg.java                                |   18 +-
 opends/src/server/org/opends/server/replication/protocol/ByteArrayBuilder.java                      |   57 +++--
 opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java                  |    4 
 opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java                           |   36 ++--
 opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java                             |   12 
 opends/src/server/org/opends/server/replication/protocol/ByteArrayScanner.java                      |    9 
 opends/src/server/org/opends/server/replication/protocol/InitializeRequestMsg.java                  |   10 
 opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java                           |   34 +-
 opends/src/server/org/opends/server/replication/protocol/ChangeTimeHeartbeatMsg.java                |   10 
 opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java                             |    8 
 opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java                    |   18 +-
 30 files changed, 263 insertions(+), 255 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/protocol/AckMsg.java b/opends/src/server/org/opends/server/replication/protocol/AckMsg.java
index 853d589..128386f 100644
--- a/opends/src/server/org/opends/server/replication/protocol/AckMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/AckMsg.java
@@ -201,14 +201,14 @@
      * error><failed server ids>
      */
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_ACK);
-    builder.appendUTF8(csn);
-    builder.append(hasTimeout);
-    builder.append(hasWrongStatus);
-    builder.append(hasReplayError);
+    builder.appendByte(MSG_TYPE_ACK);
+    builder.appendCSNUTF8(csn);
+    builder.appendBoolean(hasTimeout);
+    builder.appendBoolean(hasWrongStatus);
+    builder.appendBoolean(hasReplayError);
     for (int serverId : failedServers)
     {
-      builder.appendUTF8(serverId);
+      builder.appendIntUTF8(serverId);
     }
     return builder.toByteArray();
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/AddMsg.java b/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
index fea3de7..ab5c770 100644
--- a/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
@@ -188,8 +188,8 @@
   public byte[] getBytes_V1()
   {
     final ByteArrayBuilder builder = encodeHeader_V1(MSG_TYPE_ADD_V1);
-    builder.append(parentEntryUUID);
-    builder.append(encodedAttributes);
+    builder.appendString(parentEntryUUID);
+    builder.appendByteArray(encodedAttributes);
     return builder.toByteArray();
   }
 
@@ -199,8 +199,8 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_ADD, ProtocolVersion.REPLICATION_PROTOCOL_V3);
-    builder.append(parentEntryUUID);
-    builder.append(encodedAttributes);
+    builder.appendString(parentEntryUUID);
+    builder.appendByteArray(encodedAttributes);
     return builder.toByteArray();
   }
 
@@ -210,11 +210,11 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_ADD, protocolVersion);
-    builder.append(parentEntryUUID);
-    builder.appendUTF8(encodedAttributes.length);
-    builder.appendZeroTerminated(encodedAttributes);
-    builder.appendUTF8(encodedEclIncludes.length);
-    builder.appendZeroTerminated(encodedEclIncludes);
+    builder.appendString(parentEntryUUID);
+    builder.appendIntUTF8(encodedAttributes.length);
+    builder.appendZeroTerminatedByteArray(encodedAttributes);
+    builder.appendIntUTF8(encodedEclIncludes.length);
+    builder.appendZeroTerminatedByteArray(encodedEclIncludes);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ByteArrayBuilder.java b/opends/src/server/org/opends/server/replication/protocol/ByteArrayBuilder.java
index faef4bf..62609e4 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ByteArrayBuilder.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ByteArrayBuilder.java
@@ -76,9 +76,9 @@
    *          the boolean to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(boolean b)
+  public ByteArrayBuilder appendBoolean(boolean b)
   {
-    append((byte) (b ? 1 : 0));
+    appendByte((byte) (b ? 1 : 0));
     return this;
   }
 
@@ -89,7 +89,7 @@
    *          the byte to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(byte b)
+  public ByteArrayBuilder appendByte(byte b)
   {
     builder.append(b);
     return this;
@@ -102,7 +102,7 @@
    *          the short to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(short s)
+  public ByteArrayBuilder appendShort(short s)
   {
     builder.append(s);
     return this;
@@ -115,7 +115,7 @@
    *          the long to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(int i)
+  public ByteArrayBuilder appendInt(int i)
   {
     builder.append(i);
     return this;
@@ -128,7 +128,7 @@
    *          the long to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(long l)
+  public ByteArrayBuilder appendLong(long l)
   {
     builder.append(l);
     return this;
@@ -142,9 +142,9 @@
    *          the int to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder appendUTF8(int i)
+  public ByteArrayBuilder appendIntUTF8(int i)
   {
-    return append(Integer.toString(i));
+    return appendString(Integer.toString(i));
   }
 
   /**
@@ -155,9 +155,9 @@
    *          the long to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder appendUTF8(long l)
+  public ByteArrayBuilder appendLongUTF8(long l)
   {
-    return append(Long.toString(l));
+    return appendString(Long.toString(l));
   }
 
   /**
@@ -169,11 +169,11 @@
    */
   public ByteArrayBuilder appendStrings(Collection<String> col)
   {
-    //append(int) would have been safer, but byte is compatible with legacy code
-    append((byte) col.size());
+    //appendInt() would have been safer, but byte is compatible with legacy code
+    appendByte((byte) col.size());
     for (String s : col)
     {
-      append(s);
+      appendString(s);
     }
     return this;
   }
@@ -187,13 +187,13 @@
    *          the String to append. Can be null.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(String s)
+  public ByteArrayBuilder appendString(String s)
   {
     try
     {
       if (s != null && s.length() > 0)
       {
-        append(s.getBytes("UTF-8"));
+        appendByteArray(s.getBytes("UTF-8"));
       }
       return appendZeroSeparator();
     }
@@ -210,7 +210,7 @@
    *          the CSN to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(CSN csn)
+  public ByteArrayBuilder appendCSN(CSN csn)
   {
     csn.toByteString(builder);
     return this;
@@ -224,9 +224,9 @@
    *          the CSN to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder appendUTF8(CSN csn)
+  public ByteArrayBuilder appendCSNUTF8(CSN csn)
   {
-    append(csn.toString());
+    appendString(csn.toString());
     return this;
   }
 
@@ -238,9 +238,9 @@
    *          the DN to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(DN dn)
+  public ByteArrayBuilder appendDN(DN dn)
   {
-    append(dn.toString());
+    appendString(dn.toString());
     return this;
   }
 
@@ -251,7 +251,7 @@
    *          the byte array to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder append(byte[] bytes)
+  public ByteArrayBuilder appendByteArray(byte[] bytes)
   {
     builder.append(bytes);
     return this;
@@ -261,12 +261,15 @@
    * Append all the bytes from the byte array to this ByteArrayBuilder
    * and then append a final zero byte separator for compatibility
    * with legacy implementations.
+   * <p>
+   * Note: the super long method name it is intentional:
+   * nobody will want to use it, which is good because nobody should.
    *
    * @param bytes
    *          the byte array to append.
    * @return this ByteArrayBuilder
    */
-  public ByteArrayBuilder appendZeroTerminated(byte[] bytes)
+  public ByteArrayBuilder appendZeroTerminatedByteArray(byte[] bytes)
   {
     builder.append(bytes);
     return appendZeroSeparator();
@@ -288,20 +291,24 @@
    * fields. The only way is to rely on the end of the input buffer: and that
    * forces the ServerState to be the last field. This should be changed if we
    * want to have more than one ServerState field.
+   * <p>
+   * Note: the super long method name it is intentional:
+   * nobody will want to use it, which is good because nobody should.
    *
    * @param serverState
    *          the ServerState to append.
    * @return this ByteArrayBuilder
+   * @see ByteArrayScanner#nextServerStateMustComeLast()
    */
-  public ByteArrayBuilder append(ServerState serverState)
+  public ByteArrayBuilder appendServerStateMustComeLast(ServerState serverState)
   {
     final Map<Integer, CSN> serverIdToCSN = serverState.getServerIdToCSNMap();
     for (Entry<Integer, CSN> entry : serverIdToCSN.entrySet())
     {
       // FIXME JNR: why append the serverId in addition to the CSN
       // since the CSN already contains the serverId?
-      appendUTF8(entry.getKey()); // serverId
-      appendUTF8(entry.getValue()); // CSN
+      appendIntUTF8(entry.getKey()); // serverId
+      appendCSNUTF8(entry.getValue()); // CSN
     }
     return appendZeroSeparator(); // stupid legacy zero separator
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/ByteArrayScanner.java b/opends/src/server/org/opends/server/replication/protocol/ByteArrayScanner.java
index f0a13ec..39df798 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ByteArrayScanner.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ByteArrayScanner.java
@@ -349,15 +349,18 @@
    * Reads the next ServerState.
    * <p>
    * Caution: ServerState MUST be the last field (see
-   * {@link ByteArrayBuilder#append(ServerState)} javadoc).
+   * {@link ByteArrayBuilder#appendServerStateMustComeLast(ServerState)} javadoc).
+   * <p>
+   * Note: the super long method name it is intentional:
+   * nobody will want to use it, which is good because nobody should.
    *
    * @return the next ServerState.
    * @throws DataFormatException
    *           if ServerState was incorrectly encoded or no more data can be
    *           read from the input
-   * @see ByteArrayBuilder#append(ServerState)
+   * @see ByteArrayBuilder#appendServerStateMustComeLast(ServerState)
    */
-  public ServerState nextServerState() throws DataFormatException
+  public ServerState nextServerStateMustComeLast() throws DataFormatException
   {
     final ServerState result = new ServerState();
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ChangeTimeHeartbeatMsg.java b/opends/src/server/org/opends/server/replication/protocol/ChangeTimeHeartbeatMsg.java
index 853262c..073d2eb 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ChangeTimeHeartbeatMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ChangeTimeHeartbeatMsg.java
@@ -155,17 +155,17 @@
     if (protocolVersion < ProtocolVersion.REPLICATION_PROTOCOL_V7)
     {
       ByteArrayBuilder builder = new ByteArrayBuilder(bytes(1) + csnsUTF8(1));
-      builder.append(MSG_TYPE_CT_HEARTBEAT);
-      builder.appendUTF8(csn);
+      builder.appendByte(MSG_TYPE_CT_HEARTBEAT);
+      builder.appendCSNUTF8(csn);
       return builder.toByteArray();
     }
 
     final ByteArrayBuilder builder = new ByteArrayBuilder(bytes(1) + csns(1));
-    builder.append(MSG_TYPE_CT_HEARTBEAT);
-    builder.append(csn);
+    builder.appendByte(MSG_TYPE_CT_HEARTBEAT);
+    builder.appendCSN(csn);
     if (protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V8)
     {
-      builder.append(eventType);
+      builder.appendByte(eventType);
     }
     return builder.toByteArray();
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java b/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
index 1f766e8..3beaf6d 100644
--- a/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
@@ -146,10 +146,10 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_DELETE, protocolVersion);
-    builder.append(initiatorsName);
-    builder.appendUTF8(encodedEclIncludes.length);
-    builder.appendZeroTerminated(encodedEclIncludes);
-    builder.append(isSubtreeDelete);
+    builder.appendString(initiatorsName);
+    builder.appendIntUTF8(encodedEclIncludes.length);
+    builder.appendZeroTerminatedByteArray(encodedEclIncludes);
+    builder.appendBoolean(isSubtreeDelete);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/DoneMsg.java b/opends/src/server/org/opends/server/replication/protocol/DoneMsg.java
index e8d7b74..a5014da 100644
--- a/opends/src/server/org/opends/server/replication/protocol/DoneMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/DoneMsg.java
@@ -70,9 +70,9 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_DONE);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(destination);
+    builder.appendByte(MSG_TYPE_DONE);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(destination);
     return builder.toByteArray();
   }
 }
diff --git a/opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java b/opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java
index 2173135..cebf245 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java
@@ -154,13 +154,13 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_ECL_UPDATE);
-    builder.append(String.valueOf(cookie));
-    builder.append(baseDN);
+    builder.appendByte(MSG_TYPE_ECL_UPDATE);
+    builder.appendString(String.valueOf(cookie));
+    builder.appendDN(baseDN);
     // FIXME JNR Changing the line below to use long would require a protocol
     // version change. Leave it like this for now until the need arises.
-    builder.appendUTF8((int) changeNumber);
-    builder.appendZeroTerminated(updateMsg.getBytes(protocolVersion));
+    builder.appendIntUTF8((int) changeNumber);
+    builder.appendZeroTerminatedByteArray(updateMsg.getBytes(protocolVersion));
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/EntryMsg.java b/opends/src/server/org/opends/server/replication/protocol/EntryMsg.java
index 6ee39ac..ebac0db 100644
--- a/opends/src/server/org/opends/server/replication/protocol/EntryMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/EntryMsg.java
@@ -112,14 +112,14 @@
   public byte[] getBytes(short version)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_ENTRY);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(destination);
+    builder.appendByte(MSG_TYPE_ENTRY);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(destination);
     if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
     {
-      builder.appendUTF8(msgId);
+      builder.appendIntUTF8(msgId);
     }
-    builder.appendZeroTerminated(entryByteArray);
+    builder.appendZeroTerminatedByteArray(entryByteArray);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ErrorMsg.java b/opends/src/server/org/opends/server/replication/protocol/ErrorMsg.java
index 87b6ef2..f9fe934 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ErrorMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ErrorMsg.java
@@ -153,14 +153,14 @@
   public byte[] getBytes(short version)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_ERROR);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(destination);
-    builder.appendUTF8(msgID);
-    builder.append(details.toString());
+    builder.appendByte(MSG_TYPE_ERROR);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(destination);
+    builder.appendIntUTF8(msgID);
+    builder.appendString(details.toString());
     if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
     {
-      builder.appendUTF8(creationTime);
+      builder.appendLongUTF8(creationTime);
     }
     return builder.toByteArray();
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/InitializeRcvAckMsg.java b/opends/src/server/org/opends/server/replication/protocol/InitializeRcvAckMsg.java
index c89e81e..834b27b 100644
--- a/opends/src/server/org/opends/server/replication/protocol/InitializeRcvAckMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/InitializeRcvAckMsg.java
@@ -81,10 +81,10 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_INITIALIZE_RCV_ACK);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(destination);
-    builder.appendUTF8(numAck);
+    builder.appendByte(MSG_TYPE_INITIALIZE_RCV_ACK);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(destination);
+    builder.appendIntUTF8(numAck);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/InitializeRequestMsg.java b/opends/src/server/org/opends/server/replication/protocol/InitializeRequestMsg.java
index 6a1a695..e9bacb6 100644
--- a/opends/src/server/org/opends/server/replication/protocol/InitializeRequestMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/InitializeRequestMsg.java
@@ -102,13 +102,13 @@
   public byte[] getBytes(short version)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_INITIALIZE_REQUEST);
-    builder.append(baseDN);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(destination);
+    builder.appendByte(MSG_TYPE_INITIALIZE_REQUEST);
+    builder.appendDN(baseDN);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(destination);
     if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
     {
-      builder.appendUTF8(initWindow);
+      builder.appendIntUTF8(initWindow);
     }
     return builder.toByteArray();
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java b/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java
index f528429..14495e7 100644
--- a/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/InitializeTargetMsg.java
@@ -149,15 +149,15 @@
   public byte[] getBytes(short version)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_INITIALIZE_TARGET);
-    builder.appendUTF8(destination);
-    builder.append(baseDN);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(requestorID);
-    builder.appendUTF8(entryCount);
+    builder.appendByte(MSG_TYPE_INITIALIZE_TARGET);
+    builder.appendIntUTF8(destination);
+    builder.appendDN(baseDN);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(requestorID);
+    builder.appendLongUTF8(entryCount);
     if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
     {
-      builder.appendUTF8(initWindow);
+      builder.appendIntUTF8(initWindow);
     }
     return builder.toByteArray();
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java b/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
index a47d015..43cb522 100644
--- a/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
@@ -216,14 +216,14 @@
      * <assured mode> <safe data level>
      */
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(msgType);
-    builder.append((byte) protocolVersion);
-    builder.appendUTF8(csn);
-    builder.append(dn);
-    builder.append(entryUUID);
-    builder.append(assuredFlag);
-    builder.append(assuredMode.getValue());
-    builder.append(safeDataLevel);
+    builder.appendByte(msgType);
+    builder.appendByte((byte) protocolVersion);
+    builder.appendCSNUTF8(csn);
+    builder.appendDN(dn);
+    builder.appendString(entryUUID);
+    builder.appendBoolean(assuredFlag);
+    builder.appendByte(assuredMode.getValue());
+    builder.appendByte(safeDataLevel);
     return builder;
   }
 
@@ -240,11 +240,11 @@
      * <operation type><CSN><dn><assured><entryuuid><change>
      */
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(msgType);
-    builder.appendUTF8(csn);
-    builder.append(assuredFlag);
-    builder.append(dn);
-    builder.append(entryUUID);
+    builder.appendByte(msgType);
+    builder.appendCSNUTF8(csn);
+    builder.appendBoolean(assuredFlag);
+    builder.appendDN(dn);
+    builder.appendString(entryUUID);
     return builder;
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java b/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
index d8da663..153e0c4 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
@@ -180,10 +180,10 @@
   public byte[] getBytes_V1()
   {
     final ByteArrayBuilder builder = encodeHeader_V1(MSG_TYPE_MODIFYDN_V1);
-    builder.append(newRDN);
-    builder.append(newSuperior);
-    builder.append(newSuperiorEntryUUID);
-    builder.append(deleteOldRdn);
+    builder.appendString(newRDN);
+    builder.appendString(newSuperior);
+    builder.appendString(newSuperiorEntryUUID);
+    builder.appendBoolean(deleteOldRdn);
     return builder.toByteArray();
   }
 
@@ -193,11 +193,11 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_MODIFYDN,ProtocolVersion.REPLICATION_PROTOCOL_V3);
-    builder.append(newRDN);
-    builder.append(newSuperior);
-    builder.append(newSuperiorEntryUUID);
-    builder.append(deleteOldRdn);
-    builder.appendZeroTerminated(encodedMods);
+    builder.appendString(newRDN);
+    builder.appendString(newSuperior);
+    builder.appendString(newSuperiorEntryUUID);
+    builder.appendBoolean(deleteOldRdn);
+    builder.appendZeroTerminatedByteArray(encodedMods);
     return builder.toByteArray();
   }
 
@@ -207,14 +207,14 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_MODIFYDN, protocolVersion);
-    builder.append(newRDN);
-    builder.append(newSuperior);
-    builder.append(newSuperiorEntryUUID);
-    builder.append(deleteOldRdn);
-    builder.appendUTF8(encodedMods.length);
-    builder.appendZeroTerminated(encodedMods);
-    builder.appendUTF8(encodedEclIncludes.length);
-    builder.appendZeroTerminated(encodedEclIncludes);
+    builder.appendString(newRDN);
+    builder.appendString(newSuperior);
+    builder.appendString(newSuperiorEntryUUID);
+    builder.appendBoolean(deleteOldRdn);
+    builder.appendIntUTF8(encodedMods.length);
+    builder.appendZeroTerminatedByteArray(encodedMods);
+    builder.appendIntUTF8(encodedEclIncludes.length);
+    builder.appendZeroTerminatedByteArray(encodedEclIncludes);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java b/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
index 33ec848..e37158e 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
@@ -176,7 +176,7 @@
   public byte[] getBytes_V1()
   {
     final ByteArrayBuilder builder = encodeHeader_V1(MSG_TYPE_MODIFY_V1);
-    builder.append(encodedMods);
+    builder.appendByteArray(encodedMods);
     return builder.toByteArray();
   }
 
@@ -186,7 +186,7 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_MODIFY, ProtocolVersion.REPLICATION_PROTOCOL_V3);
-    builder.append(encodedMods);
+    builder.appendByteArray(encodedMods);
     return builder.toByteArray();
   }
 
@@ -196,10 +196,10 @@
   {
     final ByteArrayBuilder builder =
         encodeHeader(MSG_TYPE_MODIFY, protocolVersion);
-    builder.appendUTF8(encodedMods.length);
-    builder.append(encodedMods);
-    builder.appendUTF8(encodedEclIncludes.length);
-    builder.append(encodedEclIncludes);
+    builder.appendIntUTF8(encodedMods.length);
+    builder.appendByteArray(encodedMods);
+    builder.appendIntUTF8(encodedEclIncludes.length);
+    builder.appendByteArray(encodedEclIncludes);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/MonitorMsg.java b/opends/src/server/org/opends/server/replication/protocol/MonitorMsg.java
index 470ed18..05a0143 100644
--- a/opends/src/server/org/opends/server/replication/protocol/MonitorMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/MonitorMsg.java
@@ -274,7 +274,7 @@
     try
     {
       final ByteArrayBuilder builder = new ByteArrayBuilder();
-      builder.append(MSG_TYPE_REPL_SERVER_MONITOR);
+      builder.appendByte(MSG_TYPE_REPL_SERVER_MONITOR);
       append(builder, senderID, protocolVersion);
       append(builder, destination, protocolVersion);
 
@@ -298,7 +298,7 @@
       if (protocolVersion == ProtocolVersion.REPLICATION_PROTOCOL_V1)
       {
         // legacy coding mistake
-        builder.append((byte) 0);
+        builder.appendByte((byte) 0);
       }
       return builder.toByteArray();
     }
@@ -313,15 +313,15 @@
   {
     if (protocolVersion == ProtocolVersion.REPLICATION_PROTOCOL_V1)
     {
-      builder.appendUTF8(data);
+      builder.appendIntUTF8(data);
     }
     else if (protocolVersion <= ProtocolVersion.REPLICATION_PROTOCOL_V3)
     {
-      builder.append((short) data);
+      builder.appendShort((short) data);
     }
     else // protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V4
     {
-      builder.append(data);
+      builder.appendInt(data);
     }
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/MonitorRequestMsg.java b/opends/src/server/org/opends/server/replication/protocol/MonitorRequestMsg.java
index a0f0bca..98c6b12 100644
--- a/opends/src/server/org/opends/server/replication/protocol/MonitorRequestMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/MonitorRequestMsg.java
@@ -85,9 +85,9 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_REPL_SERVER_MONITOR_REQUEST);
-    builder.appendUTF8(senderID);
-    builder.appendUTF8(destination);
+    builder.appendByte(MSG_TYPE_REPL_SERVER_MONITOR_REQUEST);
+    builder.appendIntUTF8(senderID);
+    builder.appendIntUTF8(destination);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java b/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java
index ed64711..d36467f 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ReplServerStartDSMsg.java
@@ -131,7 +131,7 @@
     degradedStatusThreshold =scanner.nextIntUTF8();
     weight = scanner.nextIntUTF8();
     connectedDSNumber = scanner.nextIntUTF8();
-    serverState = scanner.nextServerState();
+    serverState = scanner.nextServerStateMustComeLast();
   }
 
   /**
@@ -182,16 +182,15 @@
      */
     final ByteArrayBuilder builder = new ByteArrayBuilder();
     encodeHeader(MSG_TYPE_REPL_SERVER_START_DS, builder, protocolVersion);
-    builder.append(baseDN);
-    builder.appendUTF8(serverId);
-    builder.append(serverURL);
-    builder.appendUTF8(windowSize);
-    builder.append(Boolean.toString(sslEncryption));
-    builder.appendUTF8(degradedStatusThreshold);
-    builder.appendUTF8(weight);
-    builder.appendUTF8(connectedDSNumber);
-    // Caution: ServerState MUST be the last field.
-    builder.append(serverState);
+    builder.appendDN(baseDN);
+    builder.appendIntUTF8(serverId);
+    builder.appendString(serverURL);
+    builder.appendIntUTF8(windowSize);
+    builder.appendString(Boolean.toString(sslEncryption));
+    builder.appendIntUTF8(degradedStatusThreshold);
+    builder.appendIntUTF8(weight);
+    builder.appendIntUTF8(connectedDSNumber);
+    builder.appendServerStateMustComeLast(serverState);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ReplServerStartMsg.java b/opends/src/server/org/opends/server/replication/protocol/ReplServerStartMsg.java
index 5a58fd6..7a09ba5 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ReplServerStartMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ReplServerStartMsg.java
@@ -125,7 +125,7 @@
       degradedStatusThreshold = scanner.nextIntUTF8();
     }
 
-    serverState = scanner.nextServerState();
+    serverState = scanner.nextServerStateMustComeLast();
   }
 
   /**
@@ -177,13 +177,12 @@
        * <operation type><basedn><serverid><serverURL><windowsize><serverState>
        */
       encodeHeader_V1(MSG_TYPE_REPL_SERVER_START_V1, builder);
-      builder.append(baseDN);
-      builder.appendUTF8(serverId);
-      builder.append(serverURL);
-      builder.appendUTF8(windowSize);
-      builder.append(Boolean.toString(sslEncryption));
-      // Caution: ServerState MUST be the last field.
-      builder.append(serverState);
+      builder.appendDN(baseDN);
+      builder.appendIntUTF8(serverId);
+      builder.appendString(serverURL);
+      builder.appendIntUTF8(windowSize);
+      builder.appendString(Boolean.toString(sslEncryption));
+      builder.appendServerStateMustComeLast(serverState);
     }
     else
     {
@@ -192,14 +191,13 @@
        * <degradedStatusThreshold><serverState>
        */
       encodeHeader(MSG_TYPE_REPL_SERVER_START, builder, protocolVersion);
-      builder.append(baseDN);
-      builder.appendUTF8(serverId);
-      builder.append(serverURL);
-      builder.appendUTF8(windowSize);
-      builder.append(Boolean.toString(sslEncryption));
-      builder.appendUTF8(degradedStatusThreshold);
-      // Caution: ServerState MUST be the last field.
-      builder.append(serverState);
+      builder.appendDN(baseDN);
+      builder.appendIntUTF8(serverId);
+      builder.appendString(serverURL);
+      builder.appendIntUTF8(windowSize);
+      builder.appendString(Boolean.toString(sslEncryption));
+      builder.appendIntUTF8(degradedStatusThreshold);
+      builder.appendServerStateMustComeLast(serverState);
     }
     return builder.toByteArray();
   }
diff --git a/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java b/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java
index 657fcf9..413741b 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java
@@ -69,8 +69,8 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_RESET_GENERATION_ID);
-    builder.appendUTF8(generationId);
+    builder.appendByte(MSG_TYPE_RESET_GENERATION_ID);
+    builder.appendLongUTF8(generationId);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ServerStartECLMsg.java b/opends/src/server/org/opends/server/replication/protocol/ServerStartECLMsg.java
index d66aba2..d59f01c 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ServerStartECLMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ServerStartECLMsg.java
@@ -120,7 +120,7 @@
     heartbeatInterval = scanner.nextIntUTF8();
     // FIXME awful encoding
     sslEncryption = Boolean.valueOf(scanner.nextString());
-    serverState = scanner.nextServerState();
+    serverState = scanner.nextServerStateMustComeLast();
   }
 
   /**
@@ -183,17 +183,16 @@
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
     encodeHeader(MSG_TYPE_START_ECL, builder, sessionProtocolVersion);
-    builder.append(serverURL);
-    builder.appendUTF8(maxReceiveDelay);
-    builder.appendUTF8(maxReceiveQueue);
-    builder.appendUTF8(maxSendDelay);
-    builder.appendUTF8(maxSendQueue);
-    builder.appendUTF8(windowSize);
-    builder.appendUTF8(heartbeatInterval);
+    builder.appendString(serverURL);
+    builder.appendIntUTF8(maxReceiveDelay);
+    builder.appendIntUTF8(maxReceiveQueue);
+    builder.appendIntUTF8(maxSendDelay);
+    builder.appendIntUTF8(maxSendQueue);
+    builder.appendIntUTF8(windowSize);
+    builder.appendLongUTF8(heartbeatInterval);
     // FIXME awful encoding
-    builder.append(Boolean.toString(sslEncryption));
-    // Caution: ServerState MUST be the last field.
-    builder.append(serverState);
+    builder.appendString(Boolean.toString(sslEncryption));
+    builder.appendServerStateMustComeLast(serverState);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/ServerStartMsg.java b/opends/src/server/org/opends/server/replication/protocol/ServerStartMsg.java
index f6870dd..8b65188 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ServerStartMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ServerStartMsg.java
@@ -122,7 +122,7 @@
     windowSize = scanner.nextIntUTF8();
     heartbeatInterval = scanner.nextIntUTF8();
     sslEncryption = Boolean.valueOf(scanner.nextString());
-    serverState = scanner.nextServerState();
+    serverState = scanner.nextServerStateMustComeLast();
   }
 
   /**
@@ -205,18 +205,17 @@
     final ByteArrayBuilder builder = new ByteArrayBuilder();
     encodeHeader(MSG_TYPE_SERVER_START, builder, protocolVersion);
 
-    builder.append(baseDN);
-    builder.appendUTF8(serverId);
-    builder.append(serverURL);
-    builder.appendUTF8(maxReceiveDelay);
-    builder.appendUTF8(maxReceiveQueue);
-    builder.appendUTF8(maxSendDelay);
-    builder.appendUTF8(maxSendQueue);
-    builder.appendUTF8(windowSize);
-    builder.appendUTF8(heartbeatInterval);
-    builder.append(Boolean.toString(sslEncryption));
-    // Caution: ServerState MUST be the last field.
-    builder.append(serverState);
+    builder.appendDN(baseDN);
+    builder.appendIntUTF8(serverId);
+    builder.appendString(serverURL);
+    builder.appendIntUTF8(maxReceiveDelay);
+    builder.appendIntUTF8(maxReceiveQueue);
+    builder.appendIntUTF8(maxSendDelay);
+    builder.appendIntUTF8(maxSendQueue);
+    builder.appendIntUTF8(windowSize);
+    builder.appendLongUTF8(heartbeatInterval);
+    builder.appendString(Boolean.toString(sslEncryption));
+    builder.appendServerStateMustComeLast(serverState);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java b/opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java
index 694c2f5..d62c9e9 100644
--- a/opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java
@@ -198,17 +198,17 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_START_ECL_SESSION);
-    builder.appendUTF8(eclRequestType.ordinal());
+    builder.appendByte(MSG_TYPE_START_ECL_SESSION);
+    builder.appendIntUTF8(eclRequestType.ordinal());
     // FIXME JNR Changing the lines below to use long would require a protocol
     // version change. Leave it like this for now until the need arises.
-    builder.appendUTF8((int) firstChangeNumber);
-    builder.appendUTF8((int) lastChangeNumber);
-    builder.appendUTF8(csn);
-    builder.appendUTF8(isPersistent.ordinal());
-    builder.append(crossDomainServerState);
-    builder.append(operationId);
-    builder.append(StaticUtils.collectionToString(excludedBaseDNs, ";"));
+    builder.appendIntUTF8((int) firstChangeNumber);
+    builder.appendIntUTF8((int) lastChangeNumber);
+    builder.appendCSNUTF8(csn);
+    builder.appendIntUTF8(isPersistent.ordinal());
+    builder.appendString(crossDomainServerState);
+    builder.appendString(operationId);
+    builder.appendString(StaticUtils.collectionToString(excludedBaseDNs, ";"));
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/StartMsg.java b/opends/src/server/org/opends/server/replication/protocol/StartMsg.java
index 9cc0aad..30b6bfa 100644
--- a/opends/src/server/org/opends/server/replication/protocol/StartMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/StartMsg.java
@@ -78,10 +78,10 @@
     /* The message header is stored in the form :
      * <message type><protocol version><generation id><group id>
      */
-    builder.append(msgType);
-    builder.append((byte) protocolVersion);
-    builder.appendUTF8(generationId);
-    builder.append(groupId);
+    builder.appendByte(msgType);
+    builder.appendByte((byte) protocolVersion);
+    builder.appendLongUTF8(generationId);
+    builder.appendByte(groupId);
   }
 
   /**
@@ -97,10 +97,10 @@
     /* The message header is stored in the form :
      * <message type><protocol version><generation id>
      */
-    builder.append(msgType);
-    builder.append((byte) ProtocolVersion.REPLICATION_PROTOCOL_V1_REAL);
-    builder.append((byte) 0);
-    builder.appendUTF8(generationId);
+    builder.appendByte(msgType);
+    builder.appendByte((byte) ProtocolVersion.REPLICATION_PROTOCOL_V1_REAL);
+    builder.appendByte((byte) 0);
+    builder.appendLongUTF8(generationId);
   }
 
   /**
diff --git a/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java b/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
index 7d0370c..6f51ff1 100644
--- a/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
@@ -179,17 +179,17 @@
      * (each referral url terminates with 0)
      */
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_START_SESSION);
-    builder.append(status.getValue());
-    builder.append(assuredFlag);
-    builder.append(assuredMode.getValue());
-    builder.append(safeDataLevel);
+    builder.appendByte(MSG_TYPE_START_SESSION);
+    builder.appendByte(status.getValue());
+    builder.appendBoolean(assuredFlag);
+    builder.appendByte(assuredMode.getValue());
+    builder.appendByte(safeDataLevel);
 
     if (referralsURLs.size() >= 1)
     {
       for (String url : referralsURLs)
       {
-        builder.append(url);
+        builder.appendString(url);
       }
     }
     return builder.toByteArray();
diff --git a/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java b/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java
index 56a1bbf..20ea943 100644
--- a/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java
@@ -208,24 +208,24 @@
      * <number of following RSInfo entries>[<RSInfo>]*
      */
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_TOPOLOGY);
+    builder.appendByte(MSG_TYPE_TOPOLOGY);
 
     // Put DS infos
-    builder.append((byte) replicaInfos.size());
+    builder.appendByte((byte) replicaInfos.size());
     for (DSInfo dsInfo : replicaInfos.values())
     {
-      builder.appendUTF8(dsInfo.getDsId());
+      builder.appendIntUTF8(dsInfo.getDsId());
       if (version >= REPLICATION_PROTOCOL_V6)
       {
-        builder.append(dsInfo.getDsUrl());
+        builder.appendString(dsInfo.getDsUrl());
       }
-      builder.appendUTF8(dsInfo.getRsId());
-      builder.appendUTF8(dsInfo.getGenerationId());
-      builder.append(dsInfo.getStatus().getValue());
-      builder.append(dsInfo.isAssured());
-      builder.append(dsInfo.getAssuredMode().getValue());
-      builder.append(dsInfo.getSafeDataLevel());
-      builder.append(dsInfo.getGroupId());
+      builder.appendIntUTF8(dsInfo.getRsId());
+      builder.appendLongUTF8(dsInfo.getGenerationId());
+      builder.appendByte(dsInfo.getStatus().getValue());
+      builder.appendBoolean(dsInfo.isAssured());
+      builder.appendByte(dsInfo.getAssuredMode().getValue());
+      builder.appendByte(dsInfo.getSafeDataLevel());
+      builder.appendByte(dsInfo.getGroupId());
 
       builder.appendStrings(dsInfo.getRefUrls());
 
@@ -236,22 +236,22 @@
         {
           builder.appendStrings(dsInfo.getEclIncludesForDeletes());
         }
-        builder.append((byte) dsInfo.getProtocolVersion());
+        builder.appendByte((byte) dsInfo.getProtocolVersion());
       }
     }
 
     // Put RS infos
-    builder.append((byte) rsInfos.size());
+    builder.appendByte((byte) rsInfos.size());
     for (RSInfo rsInfo : rsInfos)
     {
-      builder.appendUTF8(rsInfo.getId());
-      builder.appendUTF8(rsInfo.getGenerationId());
-      builder.append(rsInfo.getGroupId());
+      builder.appendIntUTF8(rsInfo.getId());
+      builder.appendLongUTF8(rsInfo.getGenerationId());
+      builder.appendByte(rsInfo.getGroupId());
 
       if (version >= REPLICATION_PROTOCOL_V4)
       {
-        builder.append(rsInfo.getServerUrl());
-        builder.appendUTF8(rsInfo.getWeight());
+        builder.appendString(rsInfo.getServerUrl());
+        builder.appendIntUTF8(rsInfo.getWeight());
       }
     }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java b/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java
index 28febb3..04ac885 100644
--- a/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/UpdateMsg.java
@@ -220,12 +220,12 @@
   {
     final ByteArrayBuilder builder =
         new ByteArrayBuilder(bytes(6) + csnsUTF8(1));
-    builder.append(msgType);
-    builder.append((byte) ProtocolVersion.getCurrentVersion());
-    builder.appendUTF8(getCSN());
-    builder.append(assuredFlag);
-    builder.append(assuredMode.getValue());
-    builder.append(safeDataLevel);
+    builder.appendByte(msgType);
+    builder.appendByte((byte) ProtocolVersion.getCurrentVersion());
+    builder.appendCSNUTF8(getCSN());
+    builder.appendBoolean(assuredFlag);
+    builder.appendByte(assuredMode.getValue());
+    builder.appendByte(safeDataLevel);
     return builder;
   }
 
@@ -281,7 +281,7 @@
   {
     final ByteArrayBuilder builder = encodeHeader(MSG_TYPE_GENERIC_UPDATE,
         ProtocolVersion.getCurrentVersion());
-    builder.append(payload);
+    builder.appendByteArray(payload);
     return builder.toByteArray();
   }
 
diff --git a/opends/src/server/org/opends/server/replication/protocol/WindowMsg.java b/opends/src/server/org/opends/server/replication/protocol/WindowMsg.java
index 1bcff24..2281ed3 100644
--- a/opends/src/server/org/opends/server/replication/protocol/WindowMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/WindowMsg.java
@@ -77,8 +77,8 @@
   public byte[] getBytes(short protocolVersion)
   {
     final ByteArrayBuilder builder = new ByteArrayBuilder();
-    builder.append(MSG_TYPE_WINDOW);
-    builder.appendUTF8(numAck);
+    builder.appendByte(MSG_TYPE_WINDOW);
+    builder.appendIntUTF8(numAck);
     return builder.toByteArray();
   }
 
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ByteArrayTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ByteArrayTest.java
index bce3eb3..d12ada5 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ByteArrayTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ByteArrayTest.java
@@ -109,23 +109,23 @@
     ss.update(csn);
 
     byte[] bytes = new ByteArrayBuilder()
-        .append(boTrue)
-        .append(boFalse)
-        .append(by)
-        .append(sh)
-        .append(i)
-        .append(l)
-        .append(nullStr)
-        .append(str)
+        .appendBoolean(boTrue)
+        .appendBoolean(boFalse)
+        .appendByte(by)
+        .appendShort(sh)
+        .appendInt(i)
+        .appendLong(l)
+        .appendString(nullStr)
+        .appendString(str)
         .appendStrings(col)
-        .appendUTF8(i)
-        .appendUTF8(l)
-        .append(csn)
-        .appendUTF8(csn)
-        .append(dn)
-        .appendZeroTerminated(byteArray)
-        .append(byteArray)
-        .append(ss)
+        .appendIntUTF8(i)
+        .appendLongUTF8(l)
+        .appendCSN(csn)
+        .appendCSNUTF8(csn)
+        .appendDN(dn)
+        .appendZeroTerminatedByteArray(byteArray)
+        .appendByteArray(byteArray)
+        .appendServerStateMustComeLast(ss)
         .toByteArray();
 
     final ByteArrayScanner scanner = new ByteArrayScanner(bytes);
@@ -147,14 +147,16 @@
     assertEquals(scanner.nextByteArray(byteArray.length), byteArray);
     scanner.skipZeroSeparator();
     assertEquals(scanner.nextByteArray(byteArray.length), byteArray);
-    assertEquals(scanner.nextServerState().toString(), ss.toString());
+    assertEquals(scanner.nextServerStateMustComeLast().toString(), ss.toString());
     assertTrue(scanner.isEmpty());
   }
 
   @Test
   public void testByteArrayScanner_remainingBytes() throws Exception
   {
-    final byte[] bytes = new ByteArrayBuilder().append(byteArray).toByteArray();
+    final byte[] bytes = new ByteArrayBuilder()
+        .appendByteArray(byteArray)
+        .toByteArray();
 
     final ByteArrayScanner scanner = new ByteArrayScanner(bytes);
     assertEquals(scanner.remainingBytes(), byteArray);
@@ -164,8 +166,9 @@
   @Test
   public void testByteArrayScanner_remainingBytesZeroTerminated() throws Exception
   {
-    final byte[] bytes =
-        new ByteArrayBuilder().appendZeroTerminated(byteArray).toByteArray();
+    final byte[] bytes = new ByteArrayBuilder()
+        .appendZeroTerminatedByteArray(byteArray)
+        .toByteArray();
 
     final ByteArrayScanner scanner = new ByteArrayScanner(bytes);
     assertEquals(scanner.remainingBytesZeroTerminated(), byteArray);
@@ -236,7 +239,7 @@
   @Test(expectedExceptions = DataFormatException.class)
   public void testByteArrayScanner_nextDN_throwsExceptionWhenInvalidDN() throws Exception
   {
-    final byte[] bytes = new ByteArrayBuilder().append("this is not a valid DN").toByteArray();
+    final byte[] bytes = new ByteArrayBuilder().appendString("this is not a valid DN").toByteArray();
     new ByteArrayScanner(bytes).nextDN();
   }
 

--
Gitblit v1.10.0