activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r765756 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/wireformat/openwire/utils/ main/decaf/io/ test/activemq/wireformat/openwire/utils/
Date Thu, 16 Apr 2009 20:47:25 GMT
Author: tabish
Date: Thu Apr 16 20:47:25 2009
New Revision: 765756

URL: http://svn.apache.org/viewvc?rev=765756&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-235

Fixed the DataInputStream, DataOutputStream and OpenwireStringSupport classes to all read
and write correct modified UTF-8 strings for all ascii values 0-255.   OpenwireStringSupport
now correctly write the data with an int size prefix to support larger strings enabling primitive
maps to store strings larger than 65535 characters.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/utils/OpenwireStringSupport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/utils/OpenwireStringSupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/utils/OpenwireStringSupport.cpp?rev=765756&r1=765755&r2=765756&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/utils/OpenwireStringSupport.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/utils/OpenwireStringSupport.cpp
Thu Apr 16 20:47:25 2009
@@ -36,12 +36,12 @@
 
         int utfLength = dataIn.readInt();
 
-        if( utfLength == -1 ) {
+        if( utfLength <= 0 ) {
             return "";
         }
 
         std::vector<unsigned char> buffer( utfLength );
-        std::string result( utfLength, char() );
+        std::vector<unsigned char> result( utfLength );
 
         dataIn.readFully( &buffer[0], 0, utfLength );
 
@@ -50,9 +50,9 @@
         unsigned char a = 0;
 
         while( count < utfLength ) {
-            if( (unsigned char)( result[index] = (char)buffer[count++] ) < 0x80 ) {
+            if( ( result[index] = buffer[count++] ) < 0x80 ) {
                 index++;
-            } else if( ( ( a = result[index++] ) & 0xE0 ) == 0xC0 ) {
+            } else if( ( ( a = result[index] ) & 0xE0 ) == 0xC0 ) {
                 if( count >= utfLength ) {
                     throw UTFDataFormatException(
                         __FILE__, __LINE__,
@@ -76,7 +76,7 @@
                         "This method only supports encoded ASCII values of (0-255)." );
                 }
 
-                result[index++] = (char)( ( ( a & 0x1F ) << 6 ) | ( b & 0x3F
) );
+                result[index++] = ( ( a & 0x1F ) << 6 ) | ( b & 0x3F );
 
             } else if( ( a & 0xF0 ) == 0xE0 ) {
 
@@ -102,8 +102,8 @@
                 //        "Invalid UTF-8 encoding found, byte two does not start with 0x80."
);
                 //}
                 //
-                //result[inde++] = (char)( ( ( a & 0x0F ) << 12 ) |
-                //                         ( ( b & 0x3F ) << 6 ) | ( c & 0x3F
) );
+                //result[inde++] = ( ( a & 0x0F ) << 12 ) |
+                //                 ( ( b & 0x3F ) << 6 ) | ( c & 0x3F );
 
             } else {
                 throw UTFDataFormatException(
@@ -111,9 +111,7 @@
             }
         }
 
-        result.resize( index );
-
-        return result;
+        return std::string( (char*)( &result[0] ), index );
     }
     AMQ_CATCH_RETHROW( decaf::io::IOException )
     AMQ_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp?rev=765756&r1=765755&r2=765756&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp Thu Apr
16 20:47:25 2009
@@ -276,8 +276,12 @@
         }
 
         unsigned short utfLength = readUnsignedShort();
+        if( utfLength == 0 ) {
+            return "";
+        }
+
         std::vector<unsigned char> buffer( utfLength );
-        std::string result( utfLength, char() );
+        std::vector<unsigned char> result( utfLength );
 
         this->readFully( &buffer[0], 0, utfLength );
 
@@ -286,9 +290,9 @@
         unsigned char a = 0;
 
         while( count < utfLength ) {
-            if( (unsigned char)( result[index] = (char)buffer[count++] ) < 0x80 ) {
+            if( ( result[index] = buffer[count++] ) < 0x80 ) {
                 index++;
-            } else if( ( ( a = result[index++] ) & 0xE0 ) == 0xC0 ) {
+            } else if( ( ( a = result[index] ) & 0xE0 ) == 0xC0 ) {
                 if( count >= utfLength ) {
                     throw UTFDataFormatException(
                         __FILE__, __LINE__,
@@ -312,7 +316,7 @@
                         "This method only supports encoded ASCII values of (0-255)." );
                 }
 
-                result[index++] = (char)( ( ( a & 0x1F ) << 6 ) | ( b & 0x3F
) );
+                result[index++] = ( ( a & 0x1F ) << 6 ) | ( b & 0x3F );
 
             } else if( ( a & 0xF0 ) == 0xE0 ) {
 
@@ -338,8 +342,8 @@
                 //        "Invalid UTF-8 encoding found, byte two does not start with 0x80."
);
                 //}
                 //
-                //result[inde++] = (char)( ( ( a & 0x0F ) << 12 ) |
-                //                         ( ( b & 0x3F ) << 6 ) | ( c & 0x3F
) );
+                //result[inde++] = ( ( a & 0x0F ) << 12 ) |
+                //                 ( ( b & 0x3F ) << 6 ) | ( c & 0x3F );
 
             } else {
                 throw UTFDataFormatException(
@@ -347,9 +351,7 @@
             }
         }
 
-        result.resize( index );
-
-        return result;
+        return std::string( (char*)( &result[0] ), index );
     }
     DECAF_CATCH_RETHROW( UTFDataFormatException )
     DECAF_CATCH_RETHROW( EOFException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp?rev=765756&r1=765755&r2=765756&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp Thu Apr
16 20:47:25 2009
@@ -345,7 +345,9 @@
         }
 
         this->writeUnsignedShort( (unsigned short)utfLength );
-        this->write( &utfBytes[0], 0, utfIndex );
+        if( utfLength > 0 ) {
+            this->write( &utfBytes[0], 0, utfIndex );
+        }
     }
     DECAF_CATCH_RETHROW( UTFDataFormatException )
     DECAF_CATCH_RETHROW( IOException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp?rev=765756&r1=765755&r2=765756&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp
Thu Apr 16 20:47:25 2009
@@ -107,7 +107,7 @@
     ByteArrayInputStream myStream( input, inputLength );
     DataInputStream reader( &myStream );
 
-    std::string result = reader.readUTF();
+    std::string result = OpenwireStringSupport::readString( reader );
 
     for( std::size_t i = 0; i < result.length(); ++i ) {
         CPPUNIT_ASSERT( (unsigned char)result[i] == expect[i] );



Mime
View raw message