You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/04/16 22:47:38 UTC
svn commit: r765757 - in
/activemq/activemq-cpp/branches/activemq-cpp-2.x/src:
main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
main/decaf/io/DataInputStream.cpp
test/activemq/connector/openwire/utils/OpenwireStringSupportTest.cpp
Author: tabish
Date: Thu Apr 16 20:47:38 2009
New Revision: 765757
URL: http://svn.apache.org/viewvc?rev=765757&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/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/decaf/io/DataInputStream.cpp
activemq/activemq-cpp/branches/activemq-cpp-2.x/src/test/activemq/connector/openwire/utils/OpenwireStringSupportTest.cpp
Modified: activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp?rev=765757&r1=765756&r2=765757&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp Thu Apr 16 20:47:38 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/branches/activemq-cpp-2.x/src/main/decaf/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/decaf/io/DataInputStream.cpp?rev=765757&r1=765756&r2=765757&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/decaf/io/DataInputStream.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/decaf/io/DataInputStream.cpp Thu Apr 16 20:47:38 2009
@@ -282,8 +282,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 );
@@ -292,9 +296,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__,
@@ -318,7 +322,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 ) {
@@ -344,8 +348,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(
@@ -353,9 +357,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/branches/activemq-cpp-2.x/src/test/activemq/connector/openwire/utils/OpenwireStringSupportTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-2.x/src/test/activemq/connector/openwire/utils/OpenwireStringSupportTest.cpp?rev=765757&r1=765756&r2=765757&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-2.x/src/test/activemq/connector/openwire/utils/OpenwireStringSupportTest.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-2.x/src/test/activemq/connector/openwire/utils/OpenwireStringSupportTest.cpp Thu Apr 16 20:47:38 2009
@@ -106,7 +106,7 @@
ByteArrayInputStream myStream( input, inputLength );
DataInputStream reader( &myStream );
- std::string result = OpenwireStringSupport::readString( reader );
+ std::string result = OpenwireStringSupport::readString( reader );
for( std::size_t i = 0; i < result.length(); ++i ) {
CPPUNIT_ASSERT( (unsigned char)result[i] == expect[i] );