From 9758ff6ce1458df98fa4889e7995f14b296a024a Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Thu, 17 Aug 2006 18:58:55 +0000
Subject: [PATCH] Added an extra byte before the ASN1 encoding of database entries for versioning purposes. Also, error handling mechnisms are also added for handling incompatible version numbers. Some extra catch statements are removed to allow the orginal exception to bubble up to the debug logger.

---
 opendj-sdk/opends/src/server/org/opends/server/backends/jeb/JebFormat.java |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/JebFormat.java b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/JebFormat.java
index a3beab2..9c5069e 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/JebFormat.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/JebFormat.java
@@ -64,6 +64,11 @@
        "org.opends.server.backends.je.JebFormat";
 
   /**
+   * The format version used by this class to encode and decode a DatabaseEntry.
+   */
+  public static final byte FORMAT_VERSION = 0x01;
+
+  /**
    * The ASN1 tag for the DatabaseEntry type.
    */
   public static final byte TAG_DATABASE_ENTRY = 0x60;
@@ -89,9 +94,13 @@
   {
     assert debugEnter(CLASS_NAME, "decodeDatabaseEntry", String.valueOf(bytes));
 
+    // Remove version number from the encoded bytes
+    byte[] encodedBytes = new byte[bytes.length - 1];
+    System.arraycopy(bytes, 1, encodedBytes, 0, encodedBytes.length);
+
     // Decode the sequence.
     List<ASN1Element> elements;
-    elements = ASN1Sequence.decodeAsSequence(bytes).elements();
+    elements = ASN1Sequence.decodeAsSequence(encodedBytes).elements();
 
     // Decode the uncompressed size.
     int uncompressedSize;
@@ -292,8 +301,15 @@
     ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(2);
     elements.add(new ASN1Integer(uncompressedSize));
     elements.add(new ASN1OctetString(bytes));
+    byte[] asn1Sequence =
+        new ASN1Sequence(TAG_DATABASE_ENTRY, elements).encode();
 
-    return new ASN1Sequence(TAG_DATABASE_ENTRY, elements).encode();
+    // Prefix version number to the encoded bytes
+    byte[] encodedBytes = new byte[asn1Sequence.length + 1];
+    encodedBytes[0] = FORMAT_VERSION;
+    System.arraycopy(asn1Sequence, 0, encodedBytes, 1, asn1Sequence.length);
+
+    return encodedBytes;
   }
 
   /**
@@ -489,4 +505,15 @@
     return bytes;
   }
 
+   /**
+   * Get the version number of the DatabaseEntry.
+   *
+   * @param bytes The encoded bytes of a DatabaseEntry.
+   * @return The version number.
+   */
+  public static byte getEntryVersion(byte[] bytes)
+  {
+    return bytes[0];
+  }
+
 }

--
Gitblit v1.10.0