anchor.diff:  
   (*
                                                                          |<- 8 byte aligned
  -+------+-------+-------+------------+----------+-- ................ ---+---------+- ..... -+
  -| Size | TxID  | Field | F(0) Start | F(0) End | F(n) Start | F(n) End | F(0)    | F(n)    |
  -|      |       | Count | Position   | Position | Position   | Position | Content | Content |
  -+------+-------+-------+------------+----------+-- ................ ---+---------+- ..... -+
  ++------+-------+-------+------------+--------- -+-- ................ ---+---------+- ..... -+
  +| Size | TxID  | Field | F(0) Start | F(0)      | F(n) Start | F(n)     | F(0)    | F(n)    |
  +|      |       | Count | Position   | Length    | Position   | Length   | Content | Content |
  ++------+-------+-------+------------+-----------+-- ................ ---+---------+- ..... -+
   <- 4B->|<- 8B ->|<- 4B->|<--- 4B --->|<-- 4B -->|                       |<- Var ->|
   
     TxID = Transaction ID
  
positive.code:   Var = Variable length
  *)
  module DocumentProtocol = 
      /// Encode the transaction Id
      let encodeTransactionId (txId : int64) (t : T) = 
          // Transaction ID should always be at the beginning of the message
          t.Position <- 0
          encodeInt64 txId t
      
      /// Returns the Transaction ID encoded in the message
      let decodeTransactionId (t : T) = 
          t.Position <- 0
          decodeInt64 t
      
      let intialize (txId : int64) (fieldCount : int32) (t : T) = 
          // Add the transaction log id
          encodeInt64 txId t
          encodeInt32 fieldCount t
          // Add a default location for each field
          for i = 0 to fieldCount do
              append ZeroIntEncoded t
      
      /// Update the starting position of an item in the document
      let updatePos (fieldPos : int) (location : int) (t : T) = 
          let src = BitConverter.GetBytes(location)
          // Copy the 4 bytes directly rather than using buffer copy
          src |> Array.iteri (fun i value -> t.Buffer.[8 + 4 * fieldPos + i] <- value)
      
      let encodeDocument (txId : int64, document : Dictionary<string, string>) = 
          let message = DocumentBuffer.create (BufferSize.Small)
          intialize txId document.Count message
          let mutable count = 1
          for pair in document do
              // Align the position before writing to the array
              align message
              // write the current position as the starting position for the value in memory
              updatePos count message.Position message
              encodeString pair.Value message
          message
  
negative.code:         let src = utf8.GetBytes(value)
          append src t
          src.Length
      
      /// Decode a string value from the buffer
      let decodeString (length : int) (t : T) = 
          assert (t.Buffer.Length >= t.Position + length)
  