directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226906 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
Date Mon, 01 Aug 2005 23:07:21 GMT
Author: elecharny
Date: Mon Aug  1 16:07:17 2005
New Revision: 226906

URL: http://svn.apache.org/viewcvs?rev=226906&view=rev
Log:
- added a method to encode enumerated values
- fixed a bug in the encoding of an integer (the length was not calcutated
correctly when above 256)

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

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java?rev=226906&r1=226905&r2=226906&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java Mon
Aug  1 16:07:17 2005
@@ -336,7 +336,34 @@
         try
         {
             buffer.put( UniversalTag.INTEGER_TAG );
-            buffer.put( Length.getBytes( Length.getNbBytes( value ) ) );
+            buffer.put( Length.getBytes( getNbBytes( value ) ) );
+            buffer.put( getBytes( value ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return;
+    }
+
+    /**
+     * Encode an enumerated value 
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param value The integer to be encoded
+     */
+    public static void encodeEnumerated( ByteBuffer buffer, int value ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( UniversalTag.ENUMERATED_TAG );
+            buffer.put( Length.getBytes( getNbBytes( value ) ) );
             buffer.put( getBytes( value ) );
         }
         catch ( BufferOverflowException boe )



Mime
View raw message