directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 23109 - in incubator/directory/snickers/trunk/ber-codec/src: java/org/apache/snickers/ber test/org/apache/snickers/ber
Date Wed, 21 Jul 2004 02:25:36 GMT
Author: akarasulu
Date: Tue Jul 20 19:25:35 2004
New Revision: 23109

Modified:
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TagEnum.java
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/BEREncoderTest.java
Log:
Commit changes ...

 o Added getTypeClass() method to TagEnum
 o Cleaned up test case for primitives which now works
 o Documenting more of the encoder as I go to make sense of things
 o Corrected bug in Tuple so we now set the typeClass correctly
 
 There is much ugliness here but we can refactor things later.  For
 now the goal is to get the encoder working as best as we can.



Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
Tue Jul 20 19:25:35 2004
@@ -91,10 +91,19 @@
 
     /**
      * Specific callback interface used to send TLV tuple events to this
-     * encoder.
+     * encoder.  Uses the buffer in this encoder to lay down tag and length
+     * pairs yet passing through chunked values.  A downstream encoder can
+     * consolidate these buffers and flush them to a stream.
      */
     class Callback implements BEREncoderCallback
     {
+        /*
+         * The idea here is to see if we can encode the tag bytes into the
+         * remaining bytes of the buffer.  If we can then great we do so.
+         * If we cannot then we have to flush out the full buffer with an
+         * encodeOccurred Event.  This signals the production of encoded data
+         * and free's up the buffer to have the tag bytes writen to it.
+         */
         public void tagEncoded( Tuple tlv )
         {
             if ( buf.remaining() >= tlv.getTagLength() )
@@ -111,6 +120,13 @@
         }
 
 
+        /*
+         * Again we have the same dynamic where we no encode the lenght bytes
+         * into the remaining bytes of the buffer.  If we can then great we do
+         * so.  If we cannot then we have to flush out the full buffer with an
+         * encodeOccurred Event.  This signals the production of encoded data
+         * and free's up the buffer to have the length bytes writen to it.
+         */
         public void lengthEncoded( Tuple tlv )
         {
             if ( buf.remaining() >= tlv.getLengthLength() )
@@ -127,6 +143,16 @@
         }
 
 
+        /*
+         * Here the situation is a little different.  The values are already
+         * chunked so there is no need to copy them into a buffer.  We are
+         * best off passing through this buffer to consumers with an encode but
+         * before we do that we need to check if the present buffer contains
+         * any material that must go out the door first.  Doing this prevents
+         * us from mangling the order of bytes to send.  So if our buf contains
+         * any bytes from previous operations laying down the tag and length
+         * then we must flush it out.  Then we can flush out this chunk.
+         */
         public void partialValueEncoded( Tuple tlv )
         {
             if ( buf.position() > 0 )
@@ -140,6 +166,18 @@
         }
 
 
+        /*
+         * Keep in mind this method signals the end of a Tuple.  It is called
+         * upstream from us by a higher level encoder that generates tuple
+         * streams from objects.  This method simply returns if the object is
+         * a primitive Tuple because all value processing has already occurred
+         * for that tuple.  If on the otherhand the tuple is constructed and of
+         * the indefinate form need to write the termination sequence (two
+         * zeros) down into the stream.  We attempt to do this into the buffer.
+         * If the buffer is full we flush is with an encodeOccurred() event.
+         * Then we write the termination sequence into the buffer and flush
+         * the buffer with an encodeOccurred Event.
+         */
         public void encodeOccurred( StatefulEncoder encoder, Object encoded )
         {
             Tuple tlv = ( Tuple ) encoded;

Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TagEnum.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TagEnum.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TagEnum.java
Tue Jul 20 19:25:35 2004
@@ -74,4 +74,15 @@
     {
         return getValue() | 0x20000000 ;
     }
+
+
+    /**
+     * Gets the type class of a tag.
+     *
+     * @return the type class for this tag enumeration.
+     */
+    public final TypeClass getTypeClass()
+    {
+        return TypeClass.getTypeClass( getValue() >> 24 ) ;
+    }
 }

Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
Tue Jul 20 19:25:35 2004
@@ -213,21 +213,22 @@
 
     /**
      * Sets the raw tag encoded as a primitive int and as a side effect this
-     * call also effects the
+     * call also sets the id, primitive flag, and typeClass of this TLV tuple.
      *
-     * @param rawTag
+     * @param rawTag the raw primitive int encoded tag.
      */
     public void setRawTag( int rawTag )
     {
         this.rawTag = rawTag;
         this.id = Tag.getTagId( rawTag );
         this.isPrimitive = ! Tag.isRawTagConstructed( rawTag );
+        this.typeClass = TypeClass.getTypeClass( rawTag >> 24 );
     }
 
 
     /**
      * Sets the tag parameters using a tag enumeration type.  This operation
-     * sets the id, isPrimitive, and rawTag fields at the same time.
+     * sets the id, isPrimitive, typeClass, and rawTag fields at the same time.
      *
      * @param tag the tag enumeration constant
      */
@@ -236,13 +237,14 @@
         this.rawTag = tag.getValue();
         this.id = tag.getTagId();
         this.isPrimitive = ! Tag.isRawTagConstructed( tag.getValue() ) ;
+        this.typeClass = tag.getTypeClass();
     }
 
 
     /**
      * Sets the tag parameters using a tag enumeration type explicitly setting
      * the primitive/constructed bit.  This operation sets the id, isPrimitive,
-     * and rawTag fields at the same time.
+     * typeClass, and rawTag fields at the same time.
      *
      * @param tag the tag enumeration constant
      * @param isPrimitive primitive/constructed bit override
@@ -252,6 +254,7 @@
         this.rawTag = tag.getValue();
         this.id = tag.getTagId();
         this.isPrimitive = isPrimitive;
+        this.typeClass = tag.getTypeClass();
     }
 
 

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/BEREncoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/BEREncoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/BEREncoderTest.java
Tue Jul 20 19:25:35 2004
@@ -75,18 +75,20 @@
 
         tlv.setLastValueChunk( ByteBuffer.wrap( new byte[] { (byte) 10 }) );
         encoder.getBERCallback().partialValueEncoded( tlv );
+        encoder.getBERCallback().encodeOccurred( encoder, tlv );
 
         ArrayList list = new ArrayList();
-        list.add( tlv.getLastValueChunk() );
+        list.add( ByteBuffer.wrap( new byte[] { (byte) 10 } ) );
         ByteBuffer buf = tlv.toEncodedBuffer( list );
 
         byte[] correctBytes = new byte[buf.remaining()];
         buf.get( correctBytes );
 
+        collector.flip();
         byte[] encodedBytes = new byte[collector.remaining()];
         collector.get( encodedBytes );
 
-        ArrayUtils.isEquals( correctBytes, encodedBytes );
+        assertTrue( ArrayUtils.isEquals( correctBytes, encodedBytes ) );
     }
 
 
@@ -123,6 +125,6 @@
         byte[] encodedBytes = new byte[collector.remaining()];
         collector.get( encodedBytes );
 
-        ArrayUtils.isEquals( correctBytes, encodedBytes );
+        //assertTrue( ArrayUtils.isEquals( correctBytes, encodedBytes ) );
     }
 }

Mime
View raw message