directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r233578 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java
Date Fri, 19 Aug 2005 23:55:13 GMT
Author: elecharny
Date: Fri Aug 19 16:55:10 2005
New Revision: 233578

URL: http://svn.apache.org/viewcvs?rev=233578&view=rev
Log:
- changed checkTLVFree method's name to isTLVDecode. - The decode function now returns true
or false if the PDU has been decoded or not.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java?rev=233578&r1=233577&r2=233578&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java Fri
Aug 19 16:55:10 2005
@@ -250,7 +250,7 @@
      * Check if the TLV tree is fully decoded
      * @param container The container
      */
-    private boolean checkTLVTree( IAsn1Container container )
+    private boolean isTLVDecoded( IAsn1Container container )
     {
         TLV current = container.getCurrentTLV();
         
@@ -712,13 +712,20 @@
         // First, we have to execute the associated action
         container.getGrammar().executeAction( container );
 
-        // Then we switch to the Start tag state and free the current TLV
-        container.setState( TLVStateEnum.TAG_STATE_START );
-
         // Check if the PDU has been fully decoded.
-        boolean finished = checkTLVTree(container);
-        
-        return (finished ? END : stream.hasRemaining());
+        if ( isTLVDecoded(container) )
+        {
+            // Change the state to DECODED
+            container.setState( TLVStateEnum.PDU_DECODED );
+            
+        }
+        else
+        {
+            // Then we switch to the Start tag state and free the current TLV
+            container.setState( TLVStateEnum.TAG_STATE_START );
+        }
+
+        return stream.hasRemaining();
     }
 
     /**
@@ -782,7 +789,7 @@
      *
      * @throws DecoderException Thrown if enything went wrong!
      */
-    public void decode( ByteBuffer stream, IAsn1Container container ) throws DecoderException
+    public boolean decode( ByteBuffer stream, IAsn1Container container ) throws DecoderException
     {
 
         /* We have to deal with the current state. This is an
@@ -795,6 +802,7 @@
          */
 
         boolean hasRemaining = stream.hasRemaining();
+        boolean isDecoded = false;
 
         if ( DEBUG )
         {
@@ -877,6 +885,22 @@
 
                 case TLVStateEnum.TLV_STATE_DONE :
                     hasRemaining = treatTLVDoneState( stream, container );
+                    
+                    // Check if the PDU is fully decoded
+                    isDecoded = ( container.getState() == TLVStateEnum.PDU_DECODED );
+                    break;
+
+                case TLVStateEnum.PDU_DECODED :
+                    // We have to deal with the case where there are
+                    // more bytes in the buffer, but the PDU has been decoded.
+                    if ( log.isWarnEnabled() )
+                    {
+                        log.warn("The PDU has been fully decoded but there are still bytes
in the buffer.");
+                    }
+                    
+                    isDecoded = true;
+                    hasRemaining = false;
+                    
                     break;
             }
         }
@@ -884,9 +908,20 @@
         if ( DEBUG )
         {
             log.debug( "<<<------------------------------------------" );
-            log.debug( "<-- End decoding : " + container.getCurrentTLV().toString() );
+            
+            if ( isDecoded )
+            {
+                log.debug( "<-- Stop decoding : " + container.getCurrentTLV().toString()
);
+            }
+            else
+            {
+                log.debug( "<-- End decoding : " + container.getCurrentTLV().toString()
);
+            }
+            
             log.debug( "<<<==========================================" );
         }
+        
+        return isDecoded;
     } // end method decode
 
     /**



Mime
View raw message