activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [2/2] git commit: https://issues.apache.org/jira/browse/AMQCPP-551
Date Thu, 21 Aug 2014 17:31:56 GMT
https://issues.apache.org/jira/browse/AMQCPP-551

Ensure that the correct number of bytes are read and written to the
stream for char type.


Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/35c570ba
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/35c570ba
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/35c570ba

Branch: refs/heads/trunk
Commit: 35c570ba75afa94fa5d3f9ad9068636766d361a9
Parents: a965f2b
Author: Timothy Bish <tabish121@gmail.com>
Authored: Thu Aug 21 12:56:00 2014 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Thu Aug 21 12:56:36 2014 -0400

----------------------------------------------------------------------
 .../marshal/PrimitiveTypesMarshaller.cpp        | 373 +++++++++----------
 .../activemq/test/MapMessageTest.cpp            | 126 +++++--
 .../activemq/test/MapMessageTest.h              |   2 +
 .../test/openwire/OpenwireMapMessageTest.h      |   2 +
 4 files changed, 276 insertions(+), 227 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/35c570ba/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
b/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
index 5105831..58d94d1 100644
--- a/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
+++ b/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
@@ -39,159 +39,157 @@ using namespace decaf::lang;
 using namespace decaf::util;
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshal( const PrimitiveMap* map, std::vector<unsigned
char>& buffer ) {
+void PrimitiveTypesMarshaller::marshal(const PrimitiveMap* map, std::vector<unsigned char>&
buffer) {
 
     try {
 
         ByteArrayOutputStream bytesOut;
-        DataOutputStream dataOut( &bytesOut );
+        DataOutputStream dataOut(&bytesOut);
 
-        if( map == NULL ) {
-            dataOut.writeInt( -1 );
+        if (map == NULL) {
+            dataOut.writeInt(-1);
         } else {
-            PrimitiveTypesMarshaller::marshalPrimitiveMap( dataOut, *map );
+            PrimitiveTypesMarshaller::marshalPrimitiveMap(dataOut, *map);
         }
 
-        if( bytesOut.size() > 0 ) {
+        if (bytesOut.size() > 0) {
             std::pair<unsigned char*, int> array = bytesOut.toByteArray();
-            buffer.insert( buffer.begin(), array.first, array.first + array.second );
-            delete [] array.first;
+            buffer.insert(buffer.begin(), array.first, array.first + array.second);
+            delete[] array.first;
         }
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::unmarshal( PrimitiveMap* map, const std::vector<unsigned
char>& buffer ) {
+void PrimitiveTypesMarshaller::unmarshal(PrimitiveMap* map, const std::vector<unsigned
char>& buffer) {
 
     try {
 
-        if( map == NULL || buffer.empty() ) {
+        if (map == NULL || buffer.empty()) {
             return;
         }
 
         // Clear old data
         map->clear();
 
-        ByteArrayInputStream bytesIn( buffer );
-        DataInputStream dataIn( &bytesIn );
-        PrimitiveTypesMarshaller::unmarshalPrimitiveMap( dataIn, *map );
+        ByteArrayInputStream bytesIn(buffer);
+        DataInputStream dataIn(&bytesIn);
+        PrimitiveTypesMarshaller::unmarshalPrimitiveMap(dataIn, *map);
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshal( const PrimitiveList* list, std::vector<unsigned
char>& buffer ) {
+void PrimitiveTypesMarshaller::marshal(const PrimitiveList* list, std::vector<unsigned
char>& buffer) {
 
     try {
 
         ByteArrayOutputStream bytesOut;
-        DataOutputStream dataOut( &bytesOut );
+        DataOutputStream dataOut(&bytesOut);
 
-        if( list == NULL ) {
-            dataOut.writeInt( -1 );
+        if (list == NULL) {
+            dataOut.writeInt(-1);
         } else {
-            PrimitiveTypesMarshaller::marshalPrimitiveList( dataOut, *list );
+            PrimitiveTypesMarshaller::marshalPrimitiveList(dataOut, *list);
         }
 
-        if( bytesOut.size() > 0 ) {
+        if (bytesOut.size() > 0) {
             std::pair<unsigned char*, int> array = bytesOut.toByteArray();
-            buffer.insert( buffer.begin(), array.first, array.first + array.second );
-            delete [] array.first;
+            buffer.insert(buffer.begin(), array.first, array.first + array.second);
+            delete[] array.first;
         }
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::unmarshal( PrimitiveList* list, const std::vector<unsigned
char>& buffer ) {
+void PrimitiveTypesMarshaller::unmarshal(PrimitiveList* list, const std::vector<unsigned
char>& buffer) {
 
     try {
 
-        if( list == NULL || buffer.empty() ) {
+        if (list == NULL || buffer.empty()) {
             return;
         }
 
         // Clear old data
         list->clear();
 
-        ByteArrayInputStream bytesIn( buffer );
-        DataInputStream dataIn( &bytesIn );
-        PrimitiveTypesMarshaller::unmarshalPrimitiveList( dataIn, *list );
+        ByteArrayInputStream bytesIn(buffer);
+        DataInputStream dataIn(&bytesIn);
+        PrimitiveTypesMarshaller::unmarshalPrimitiveList(dataIn, *list);
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshalMap( const PrimitiveMap* map, DataOutputStream&
dataOut ) {
+void PrimitiveTypesMarshaller::marshalMap(const PrimitiveMap* map, DataOutputStream&
dataOut) {
 
     try {
 
-        if( map == NULL ) {
-            dataOut.writeInt( -1 );
+        if (map == NULL) {
+            dataOut.writeInt(-1);
         } else {
-            PrimitiveTypesMarshaller::marshalPrimitiveMap( dataOut, *map );
+            PrimitiveTypesMarshaller::marshalPrimitiveMap(dataOut, *map);
         }
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-PrimitiveMap* PrimitiveTypesMarshaller::unmarshalMap( DataInputStream& dataIn ) {
+PrimitiveMap* PrimitiveTypesMarshaller::unmarshalMap(DataInputStream& dataIn) {
 
     try {
 
-        std::auto_ptr<PrimitiveMap> map( new PrimitiveMap() );
-        PrimitiveTypesMarshaller::unmarshalPrimitiveMap( dataIn, *( map.get() ) );
+        std::auto_ptr<PrimitiveMap> map(new PrimitiveMap());
+        PrimitiveTypesMarshaller::unmarshalPrimitiveMap(dataIn, *(map.get()));
         return map.release();
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshalList( const PrimitiveList* list, DataOutputStream&
dataOut ) {
+void PrimitiveTypesMarshaller::marshalList(const PrimitiveList* list, DataOutputStream&
dataOut) {
 
     try {
 
-        if( list == NULL ) {
-            dataOut.writeInt( -1 );
+        if (list == NULL) {
+            dataOut.writeInt(-1);
         } else {
-            PrimitiveTypesMarshaller::marshalPrimitiveList( dataOut, *list );
+            PrimitiveTypesMarshaller::marshalPrimitiveList(dataOut, *list);
         }
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-PrimitiveList* PrimitiveTypesMarshaller::unmarshalList( DataInputStream& dataIn ) {
+PrimitiveList* PrimitiveTypesMarshaller::unmarshalList(DataInputStream& dataIn) {
 
     try {
 
-        std::auto_ptr<PrimitiveList> list( new PrimitiveList() );
-        PrimitiveTypesMarshaller::unmarshalPrimitiveList( dataIn, *( list.get() ) );
+        std::auto_ptr<PrimitiveList> list(new PrimitiveList());
+        PrimitiveTypesMarshaller::unmarshalPrimitiveList(dataIn, *(list.get()));
         return list.release();
     }
-    AMQ_CATCH_RETHROW( decaf::lang::Exception )
-    AMQ_CATCHALL_THROW( decaf::lang::Exception )
+    AMQ_CATCH_RETHROW(decaf::lang::Exception)
+    AMQ_CATCHALL_THROW(decaf::lang::Exception)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshalPrimitiveMap(
-    decaf::io::DataOutputStream& dataOut,
-    const decaf::util::Map<std::string, PrimitiveValueNode>& map ) {
+void PrimitiveTypesMarshaller::marshalPrimitiveMap(decaf::io::DataOutputStream& dataOut,
const decaf::util::Map<std::string, PrimitiveValueNode>& map) {
 
-    try{
+    try {
 
-        dataOut.writeInt( (int)map.size() );
+        dataOut.writeInt((int) map.size());
 
-        Pointer< Iterator<std::string> > keys(map.keySet().iterator());
+        Pointer<Iterator<std::string> > keys(map.keySet().iterator());
         while (keys->hasNext()) {
             std::string key = keys->next();
             dataOut.writeUTF(key);
@@ -199,259 +197,250 @@ void PrimitiveTypesMarshaller::marshalPrimitiveMap(
             marshalPrimitive(dataOut, value);
         }
     }
-    AMQ_CATCH_RETHROW( io::IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, io::IOException )
-    AMQ_CATCHALL_THROW( io::IOException )
+    AMQ_CATCH_RETHROW(io::IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, io::IOException)
+    AMQ_CATCHALL_THROW(io::IOException)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshalPrimitiveList(
-    decaf::io::DataOutputStream& dataOut,
-    const decaf::util::List<PrimitiveValueNode>& list ) {
+void PrimitiveTypesMarshaller::marshalPrimitiveList(decaf::io::DataOutputStream& dataOut,
const decaf::util::List<PrimitiveValueNode>& list) {
+
+    try {
 
-    try{
-        dataOut.writeInt( (int)list.size() );
+        dataOut.writeInt((int) list.size());
 
-        for( int ix = 0; ix < list.size(); ++ix ) {
-            marshalPrimitive( dataOut, list.get( ix ) );
+        for (int ix = 0; ix < list.size(); ++ix) {
+            marshalPrimitive(dataOut, list.get(ix));
         }
     }
-    AMQ_CATCH_RETHROW( io::IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, io::IOException )
-    AMQ_CATCHALL_THROW( io::IOException )
+    AMQ_CATCH_RETHROW(io::IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, io::IOException)
+    AMQ_CATCHALL_THROW(io::IOException)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::marshalPrimitive( io::DataOutputStream& dataOut,
-                                               const activemq::util::PrimitiveValueNode&
value ) {
+void PrimitiveTypesMarshaller::marshalPrimitive(io::DataOutputStream& dataOut, const
activemq::util::PrimitiveValueNode& value) {
 
     try {
 
-        if( value.getType() == PrimitiveValueNode::BOOLEAN_TYPE ) {
+        if (value.getType() == PrimitiveValueNode::BOOLEAN_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::BOOLEAN_TYPE );
-            dataOut.writeBoolean( value.getBool() );
+            dataOut.writeByte(PrimitiveValueNode::BOOLEAN_TYPE);
+            dataOut.writeBoolean(value.getBool());
 
-        } else if( value.getType() == PrimitiveValueNode::BYTE_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::BYTE_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::BYTE_TYPE );
-            dataOut.writeByte( value.getByte() );
+            dataOut.writeByte(PrimitiveValueNode::BYTE_TYPE);
+            dataOut.writeByte(value.getByte());
 
-        } else if( value.getType() == PrimitiveValueNode::CHAR_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::CHAR_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::CHAR_TYPE );
-            dataOut.writeChar( value.getChar() );
+            // Java Char is two bytes, for now we can only send ASCII
+            dataOut.writeByte(PrimitiveValueNode::CHAR_TYPE);
+            dataOut.writeChar(0);
+            dataOut.writeChar(value.getChar());
 
-        } else if( value.getType() == PrimitiveValueNode::SHORT_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::SHORT_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::SHORT_TYPE );
-            dataOut.writeShort( value.getShort() );
+            dataOut.writeByte(PrimitiveValueNode::SHORT_TYPE);
+            dataOut.writeShort(value.getShort());
 
-        } else if( value.getType() == PrimitiveValueNode::INTEGER_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::INTEGER_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::INTEGER_TYPE );
-            dataOut.writeInt( value.getInt() );
+            dataOut.writeByte(PrimitiveValueNode::INTEGER_TYPE);
+            dataOut.writeInt(value.getInt());
 
-        } else if( value.getType() == PrimitiveValueNode::LONG_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::LONG_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::LONG_TYPE );
-            dataOut.writeLong( value.getLong() );
+            dataOut.writeByte(PrimitiveValueNode::LONG_TYPE);
+            dataOut.writeLong(value.getLong());
 
-        } else if( value.getType() == PrimitiveValueNode::FLOAT_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::FLOAT_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::FLOAT_TYPE );
-            dataOut.writeFloat( value.getFloat() );
+            dataOut.writeByte(PrimitiveValueNode::FLOAT_TYPE);
+            dataOut.writeFloat(value.getFloat());
 
-        } else if( value.getType() == PrimitiveValueNode::DOUBLE_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::DOUBLE_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::DOUBLE_TYPE );
-            dataOut.writeDouble( value.getDouble() );
+            dataOut.writeByte(PrimitiveValueNode::DOUBLE_TYPE);
+            dataOut.writeDouble(value.getDouble());
 
-        } else if( value.getType() == PrimitiveValueNode::BYTE_ARRAY_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::BYTE_ARRAY_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::BYTE_ARRAY_TYPE );
+            dataOut.writeByte(PrimitiveValueNode::BYTE_ARRAY_TYPE);
 
             std::vector<unsigned char> data = value.getByteArray();
 
-            dataOut.writeInt( (int)data.size() );
-            if( !data.empty() ) {
-                dataOut.write( &data[0], (int)data.size() );
+            dataOut.writeInt((int) data.size());
+            if (!data.empty()) {
+                dataOut.write(&data[0], (int) data.size());
             }
 
-        } else if( value.getType() == PrimitiveValueNode::STRING_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::STRING_TYPE) {
 
             std::string data = value.getString();
-            int size = (int)data.size();
+            int size = (int) data.size();
 
             // is the string big??
-            if( size == 0 ) {
-                dataOut.writeByte( PrimitiveValueNode::STRING_TYPE );
-                dataOut.writeShort( (short)size );
-            } else if( (int)data.size() > Short::MAX_VALUE / 4 ) {
-                dataOut.writeByte( PrimitiveValueNode::BIG_STRING_TYPE );
-                dataOut.writeInt( size );
-                dataOut.write( (unsigned char*)data.c_str(), size, 0, size );
+            if (size == 0) {
+                dataOut.writeByte(PrimitiveValueNode::STRING_TYPE);
+                dataOut.writeShort((short) size);
+            } else if ((int) data.size() > Short::MAX_VALUE / 4) {
+                dataOut.writeByte(PrimitiveValueNode::BIG_STRING_TYPE);
+                dataOut.writeInt(size);
+                dataOut.write((unsigned char*) data.c_str(), size, 0, size);
             } else {
-                dataOut.writeByte( PrimitiveValueNode::STRING_TYPE );
-                dataOut.writeShort( (short)size );
-                dataOut.write( (unsigned char*)data.c_str(), size, 0, size );
+                dataOut.writeByte(PrimitiveValueNode::STRING_TYPE);
+                dataOut.writeShort((short) size);
+                dataOut.write((unsigned char*) data.c_str(), size, 0, size);
             }
 
-        } else if( value.getType() == PrimitiveValueNode::LIST_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::LIST_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::LIST_TYPE );
-            marshalPrimitiveList( dataOut, value.getList() );
+            dataOut.writeByte(PrimitiveValueNode::LIST_TYPE);
+            marshalPrimitiveList(dataOut, value.getList());
 
-        } else if( value.getType() == PrimitiveValueNode::MAP_TYPE ) {
+        } else if (value.getType() == PrimitiveValueNode::MAP_TYPE) {
 
-            dataOut.writeByte( PrimitiveValueNode::MAP_TYPE );
-            marshalPrimitiveMap( dataOut, value.getMap() );
+            dataOut.writeByte(PrimitiveValueNode::MAP_TYPE);
+            marshalPrimitiveMap(dataOut, value.getMap());
 
         } else {
             throw IOException(
-                __FILE__,
-                __LINE__,
-                "Object is not a primitive: ");
+            __FILE__,
+            __LINE__, "Object is not a primitive: ");
         }
     }
-    AMQ_CATCH_RETHROW( io::IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, io::IOException )
-    AMQ_CATCHALL_THROW( io::IOException )
+    AMQ_CATCH_RETHROW(io::IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, io::IOException)
+    AMQ_CATCHALL_THROW(io::IOException)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::unmarshalPrimitiveMap(
-    decaf::io::DataInputStream& dataIn, PrimitiveMap& map ) {
+void PrimitiveTypesMarshaller::unmarshalPrimitiveMap(decaf::io::DataInputStream& dataIn,
PrimitiveMap& map) {
 
-    try{
+    try {
 
         int size = dataIn.readInt();
 
-        if( size > 0 ) {
-            for( int i=0; i < size; i++ ) {
+        if (size > 0) {
+            for (int i = 0; i < size; i++) {
                 std::string key = dataIn.readUTF();
-                map.put( key, unmarshalPrimitive( dataIn ) );
+                map.put(key, unmarshalPrimitive(dataIn));
             }
         }
     }
-    AMQ_CATCH_RETHROW( io::IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, io::IOException )
-    AMQ_CATCHALL_THROW( io::IOException )
+    AMQ_CATCH_RETHROW(io::IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, io::IOException)
+    AMQ_CATCHALL_THROW(io::IOException)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void PrimitiveTypesMarshaller::unmarshalPrimitiveList(
-    decaf::io::DataInputStream& dataIn,
-    decaf::util::LinkedList<PrimitiveValueNode>& list ) {
+void PrimitiveTypesMarshaller::unmarshalPrimitiveList(decaf::io::DataInputStream& dataIn,
decaf::util::LinkedList<PrimitiveValueNode>& list) {
 
-    try{
+    try {
 
         int size = dataIn.readInt();
-        while( size-- > 0 ) {
-            list.add( unmarshalPrimitive( dataIn ) );
+        while (size-- > 0) {
+            list.add(unmarshalPrimitive(dataIn));
         }
     }
-    AMQ_CATCH_RETHROW( io::IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, io::IOException )
-    AMQ_CATCHALL_THROW( io::IOException )
+    AMQ_CATCH_RETHROW(io::IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, io::IOException)
+    AMQ_CATCHALL_THROW(io::IOException)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-PrimitiveValueNode PrimitiveTypesMarshaller::unmarshalPrimitive( io::DataInputStream&
dataIn ) {
+PrimitiveValueNode PrimitiveTypesMarshaller::unmarshalPrimitive(io::DataInputStream&
dataIn) {
 
     try {
 
         unsigned char type = dataIn.readByte();
-
         PrimitiveValueNode value;
 
-        switch( type ) {
+        switch (type) {
 
             case PrimitiveValueNode::NULL_TYPE:
                 value.clear();
                 break;
             case PrimitiveValueNode::BYTE_TYPE:
-                value.setByte( dataIn.readByte() );
+                value.setByte(dataIn.readByte());
                 break;
             case PrimitiveValueNode::BOOLEAN_TYPE:
-                value.setBool( dataIn.readBoolean() );
+                value.setBool(dataIn.readBoolean());
                 break;
             case PrimitiveValueNode::CHAR_TYPE:
-                value.setChar( dataIn.readChar() );
+                // Java Char is two bytes, for now we can read ASCII, throw away byte 1
+                dataIn.readByte();
+                value.setChar(dataIn.readChar());
                 break;
             case PrimitiveValueNode::SHORT_TYPE:
-                value.setShort( dataIn.readShort() );
+                value.setShort(dataIn.readShort());
                 break;
             case PrimitiveValueNode::INTEGER_TYPE:
-                value.setInt( dataIn.readInt() );
+                value.setInt(dataIn.readInt());
                 break;
             case PrimitiveValueNode::LONG_TYPE:
-                value.setLong( dataIn.readLong() );
+                value.setLong(dataIn.readLong());
                 break;
             case PrimitiveValueNode::FLOAT_TYPE:
-                value.setFloat( dataIn.readFloat() );
+                value.setFloat(dataIn.readFloat());
                 break;
             case PrimitiveValueNode::DOUBLE_TYPE:
-                value.setDouble( dataIn.readDouble() );
+                value.setDouble(dataIn.readDouble());
                 break;
-            case PrimitiveValueNode::BYTE_ARRAY_TYPE:
-            {
+            case PrimitiveValueNode::BYTE_ARRAY_TYPE: {
                 int size = dataIn.readInt();
                 std::vector<unsigned char> data;
-                if( size > 0 ) {
-                    data.resize( size );
-                    dataIn.readFully( &data[0], size );
+                if (size > 0) {
+                    data.resize(size);
+                    dataIn.readFully(&data[0], size);
                 }
-                value.setByteArray( data );
+                value.setByteArray(data);
                 break;
             }
-            case PrimitiveValueNode::STRING_TYPE:
-            {
+            case PrimitiveValueNode::STRING_TYPE: {
                 int utfLength = dataIn.readShort();
-                if( utfLength > 0 ) {
+                if (utfLength > 0) {
 
-                    std::vector<unsigned char> buffer( utfLength );
-                    dataIn.readFully( &buffer[0], utfLength );
-                    value.setString( std::string( (char*)( &buffer[0] ), utfLength )
);
+                    std::vector<unsigned char> buffer(utfLength);
+                    dataIn.readFully(&buffer[0], utfLength);
+                    value.setString(std::string((char*) (&buffer[0]), utfLength));
                 }
                 break;
             }
-            case PrimitiveValueNode::BIG_STRING_TYPE:
-            {
+            case PrimitiveValueNode::BIG_STRING_TYPE: {
                 int utfLength = dataIn.readInt();
-                if( utfLength > 0 ) {
+                if (utfLength > 0) {
 
-                    std::vector<unsigned char> buffer( utfLength );
-                    dataIn.readFully( &buffer[0], utfLength );
-                    value.setString( std::string( (char*)( &buffer[0] ), utfLength )
);
+                    std::vector<unsigned char> buffer(utfLength);
+                    dataIn.readFully(&buffer[0], utfLength);
+                    value.setString(std::string((char*) (&buffer[0]), utfLength));
                 }
                 break;
             }
-            case PrimitiveValueNode::LIST_TYPE:
-            {
+            case PrimitiveValueNode::LIST_TYPE: {
                 PrimitiveList list;
-                PrimitiveTypesMarshaller::unmarshalPrimitiveList( dataIn, list );
-                value.setList( list );
+                PrimitiveTypesMarshaller::unmarshalPrimitiveList(dataIn, list);
+                value.setList(list);
                 break;
             }
-            case PrimitiveValueNode::MAP_TYPE:
-            {
+            case PrimitiveValueNode::MAP_TYPE: {
                 PrimitiveMap map;
-                PrimitiveTypesMarshaller::unmarshalPrimitiveMap( dataIn, map );
-                value.setMap( map );
+                PrimitiveTypesMarshaller::unmarshalPrimitiveMap(dataIn, map);
+                value.setMap(map);
                 break;
             }
             default:
                 throw IOException(
-                    __FILE__,
-                    __LINE__,
-                    "PrimitiveTypesMarshaller::unmarshalPrimitive - "
-                    "Unsupported data type: ");
+                __FILE__,
+                __LINE__, "PrimitiveTypesMarshaller::unmarshalPrimitive - "
+                        "Unsupported data type: ");
         }
 
         return value;
     }
-    AMQ_CATCH_RETHROW( io::IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, io::IOException )
-    AMQ_CATCHALL_THROW( io::IOException )
+    AMQ_CATCH_RETHROW(io::IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, io::IOException)
+    AMQ_CATCHALL_THROW(io::IOException)
 }

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/35c570ba/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.cpp b/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.cpp
index 36d7b4d..3f76b92 100644
--- a/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.cpp
+++ b/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.cpp
@@ -46,76 +46,132 @@ MapMessageTest::~MapMessageTest() {
 void MapMessageTest::testEmptyMapSendReceive() {
 
     // Create CMS Object for Comms
-    cms::Session* session( cmsProvider->getSession() );
+    cms::Session* session(cmsProvider->getSession());
     cms::MessageConsumer* consumer = cmsProvider->getConsumer();
     cms::MessageProducer* producer = cmsProvider->getProducer();
-    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
 
-    auto_ptr<cms::MapMessage> mapMessage( session->createMapMessage() );
+    auto_ptr<cms::MapMessage> mapMessage(session->createMapMessage());
 
     // Send some text messages
-    producer->send( mapMessage.get() );
+    producer->send(mapMessage.get());
 
-    auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
-    CPPUNIT_ASSERT( message.get() != NULL );
+    auto_ptr<cms::Message> message(consumer->receive(2000));
+    CPPUNIT_ASSERT(message.get() != NULL);
 
-    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>( message.get() );
-    CPPUNIT_ASSERT( recvMapMessage != NULL );
-    CPPUNIT_ASSERT( recvMapMessage->itemExists( "SomeKey" ) == false );
+    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>(message.get());
+    CPPUNIT_ASSERT(recvMapMessage != NULL);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("SomeKey") == false);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void MapMessageTest::testMapWithEmptyStringValue() {
 
     // Create CMS Object for Comms
-    cms::Session* session( cmsProvider->getSession() );
+    cms::Session* session(cmsProvider->getSession());
     cms::MessageConsumer* consumer = cmsProvider->getConsumer();
     cms::MessageProducer* producer = cmsProvider->getProducer();
-    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
 
-    auto_ptr<cms::MapMessage> mapMessage( session->createMapMessage() );
+    auto_ptr<cms::MapMessage> mapMessage(session->createMapMessage());
 
     mapMessage->setString("String1", "");
     mapMessage->setString("String2", "value");
 
     // Send some text messages
-    producer->send( mapMessage.get() );
-
-    auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
-    CPPUNIT_ASSERT( message.get() != NULL );
-
-    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>( message.get() );
-    CPPUNIT_ASSERT( recvMapMessage != NULL );
-    CPPUNIT_ASSERT( recvMapMessage->itemExists( "String1" ) == true );
-    CPPUNIT_ASSERT( recvMapMessage->getString( "String1" ) == "" );
-    CPPUNIT_ASSERT( recvMapMessage->itemExists( "String2" ) == true );
-    CPPUNIT_ASSERT( recvMapMessage->itemExists( "String3" ) == false );
-    CPPUNIT_ASSERT( recvMapMessage->getString( "String2" ) == string( "value" ) );
+    producer->send(mapMessage.get());
+
+    auto_ptr<cms::Message> message(consumer->receive(2000));
+    CPPUNIT_ASSERT(message.get() != NULL);
+
+    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>(message.get());
+    CPPUNIT_ASSERT(recvMapMessage != NULL);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("String1") == true);
+    CPPUNIT_ASSERT(recvMapMessage->getString("String1") == "");
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("String2") == true);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("String3") == false);
+    CPPUNIT_ASSERT(recvMapMessage->getString("String2") == string("value"));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapMessageTest::testMapWithSingleCharEntry() {
+
+    // Create CMS Object for Comms
+    cms::Session* session(cmsProvider->getSession());
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
+
+    auto_ptr<cms::MapMessage> mapMessage(session->createMapMessage());
+
+    mapMessage->setChar("Char1", 'a');
+
+    // Send some text messages
+    producer->send(mapMessage.get());
+
+    auto_ptr<cms::Message> message(consumer->receive(2000));
+    CPPUNIT_ASSERT(message.get() != NULL);
+
+    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>(message.get());
+    CPPUNIT_ASSERT(recvMapMessage != NULL);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("Char1") == true);
+    CPPUNIT_ASSERT(recvMapMessage->getChar("Char1") == 'a');
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("Char2") == false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapMessageTest::testMapWithCharAndStringEntry() {
+
+    // Create CMS Object for Comms
+    cms::Session* session(cmsProvider->getSession());
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
+
+    auto_ptr<cms::MapMessage> mapMessage(session->createMapMessage());
+
+    mapMessage->setChar("Char1", 'a');
+    mapMessage->setString("String1", "string");
+
+    // Send some text messages
+    producer->send(mapMessage.get());
+
+    auto_ptr<cms::Message> message(consumer->receive(2000));
+    CPPUNIT_ASSERT(message.get() != NULL);
+
+    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>(message.get());
+    CPPUNIT_ASSERT(recvMapMessage != NULL);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("Char1") == true);
+    CPPUNIT_ASSERT(recvMapMessage->getChar("Char1") == 'a');
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("Char2") == false);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("String1") == true);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("String3") == false);
+    CPPUNIT_ASSERT(recvMapMessage->getString("String1") == string("string"));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void MapMessageTest::testMapSetEmptyBytesVector() {
 
     // Create CMS Object for Comms
-    cms::Session* session( cmsProvider->getSession() );
+    cms::Session* session(cmsProvider->getSession());
     cms::MessageConsumer* consumer = cmsProvider->getConsumer();
     cms::MessageProducer* producer = cmsProvider->getProducer();
-    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
 
-    auto_ptr<cms::MapMessage> mapMessage( session->createMapMessage() );
+    auto_ptr<cms::MapMessage> mapMessage(session->createMapMessage());
 
     std::vector<unsigned char> bytes;
 
-    mapMessage->setBytes( "BYTES", bytes );
+    mapMessage->setBytes("BYTES", bytes);
 
     // Send some text messages
-    producer->send( mapMessage.get() );
+    producer->send(mapMessage.get());
 
-    auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
-    CPPUNIT_ASSERT( message.get() != NULL );
+    auto_ptr<cms::Message> message(consumer->receive(2000));
+    CPPUNIT_ASSERT(message.get() != NULL);
 
-    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>( message.get() );
-    CPPUNIT_ASSERT( recvMapMessage != NULL );
-    CPPUNIT_ASSERT( recvMapMessage->itemExists( "BYTES" ) == true );
-    CPPUNIT_ASSERT( recvMapMessage->getBytes( "BYTES" ).empty() == true );
+    cms::MapMessage* recvMapMessage = dynamic_cast<MapMessage*>(message.get());
+    CPPUNIT_ASSERT(recvMapMessage != NULL);
+    CPPUNIT_ASSERT(recvMapMessage->itemExists("BYTES") == true);
+    CPPUNIT_ASSERT(recvMapMessage->getBytes("BYTES").empty() == true);
 }

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/35c570ba/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.h b/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.h
index 06b4768..b1b1015 100644
--- a/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.h
+++ b/activemq-cpp/src/test-integration/activemq/test/MapMessageTest.h
@@ -33,6 +33,8 @@ namespace test {
         void testEmptyMapSendReceive();
         void testMapWithEmptyStringValue();
         void testMapSetEmptyBytesVector();
+        void testMapWithSingleCharEntry();
+        void testMapWithCharAndStringEntry();
 
     };
 

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/35c570ba/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireMapMessageTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireMapMessageTest.h
b/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireMapMessageTest.h
index aebf7d7..6e428fd 100644
--- a/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireMapMessageTest.h
+++ b/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireMapMessageTest.h
@@ -31,6 +31,8 @@ namespace openwire {
         CPPUNIT_TEST( testEmptyMapSendReceive );
         CPPUNIT_TEST( testMapWithEmptyStringValue );
         CPPUNIT_TEST( testMapSetEmptyBytesVector );
+        CPPUNIT_TEST( testMapWithSingleCharEntry );
+        CPPUNIT_TEST( testMapWithCharAndStringEntry );
         CPPUNIT_TEST_SUITE_END();
 
     public:


Mime
View raw message