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 2006/11/18 22:59:59 UTC
svn commit: r476619 - in
/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal:
BaseDataStreamMarshaller.cpp BaseDataStreamMarshaller.h
Author: tabish
Date: Sat Nov 18 13:59:58 2006
New Revision: 476619
URL: http://svn.apache.org/viewvc?view=rev&rev=476619
Log:
Code Submit for planned Openwire Support
Modified:
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp?view=diff&rev=476619&r1=476618&r2=476619
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp Sat Nov 18 13:59:58 2006
@@ -21,13 +21,17 @@
#include <activemq/connector/openwire/commands/TransactionId.h>
#include <activemq/connector/openwire/commands/LocalTransactionId.h>
#include <activemq/connector/openwire/commands/XATransactionId.h>
+#include <activemq/connector/openwire/commands/BrokerError.h>
#include <activemq/connector/openwire/utils/HexTable.h>
+#include <activemq/exceptions/ActiveMQException.h>
#include <activemq/util/Long.h>
#include <activemq/util/Integer.h>
using namespace std;
using namespace activemq;
+using namespace activemq::io;
using namespace activemq::util;
+using namespace activemq::exceptions;
using namespace activemq::connector;
using namespace activemq::connector::openwire;
using namespace activemq::connector::openwire::marshal;
@@ -35,11 +39,647 @@
using namespace activemq::connector::openwire::utils;
////////////////////////////////////////////////////////////////////////////////
-BaseDataStreamMarshaller::BaseDataStreamMarshaller() {
+commands::DataStructure* BaseDataStreamMarshaller::tightUnmarshalCachedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs ) throw ( io::IOException ) {
+
+ try{
+ return wireFormat->tightUnmarshalNestedObject( dataIn, bs );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BaseDataStreamMarshaller::tightMarshalCachedObject1(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+ return wireFormat->tightMarshalNestedObject1( data, bs );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::tightMarshalCachedObject2(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+ wireFormat->tightMarshalNestedObject2( data, dataOut, bs );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::looseMarshalCachedObject(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException ) {
+
+ try{
+ wireFormat->looseMarshalNestedObject( data, dataOut );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+commands::DataStructure* BaseDataStreamMarshaller::looseUnmarshalCachedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn ) throw ( io::IOException ) {
+
+ try{
+ return wireFormat->looseUnmarshalNestedObject( dataIn );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BaseDataStreamMarshaller::tightMarshalNestedObject1(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* object,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+ return wireFormat->tightMarshalNestedObject1( object, bs );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::tightMarshalNestedObject2(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* object,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+ wireFormat->tightMarshalNestedObject2( object, dataOut, bs );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+commands::DataStructure* BaseDataStreamMarshaller::tightUnmarshalNestedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+ return wireFormat->tightUnmarshalNestedObject( dataIn, bs );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+commands::DataStructure* BaseDataStreamMarshaller::looseUnmarshalNestedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn )
+ throw ( io::IOException ) {
+
+ try{
+ return wireFormat->looseUnmarshalNestedObject( dataIn );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::looseMarshalNestedObject(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* object,
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException ) {
+
+ try{
+ wireFormat->looseMarshalNestedObject( object, dataOut );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string BaseDataStreamMarshaller::tightUnmarshalString(
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs ) throw ( io::IOException ) {
+
+ try{
+
+ if( bs->readBoolean() ) {
+
+ if (bs->readBoolean() ) {
+ return this->readAsciiString( dataIn );
+ } else {
+ return dataIn->readUTF();
+ }
+ } else {
+ return "";
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BaseDataStreamMarshaller::tightMarshalString1( const std::string& value,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+ try{
+
+ bs->writeBoolean( value == "" );
+ if( value != "" )
+ {
+ int strlen = value.length();
+
+ int utflen = 0;
+ int c = 0;
+ bool isOnlyAscii = true;
+
+ for( int i = 0; i < strlen; ++i ) {
+
+ c = value[i];
+ if( (c >= 0x0001) && (c <= 0x007F) ) // ASCII char
+ {
+ utflen++;
+ }
+ else if( c > 0x07FF )
+ {
+ utflen += 3;
+ isOnlyAscii = false;
+ }
+ else
+ {
+ isOnlyAscii = false;
+ utflen += 2;
+ }
+ }
+
+ if( utflen >= 0x10000 ) {
+ throw IOException(
+ __FILE__, __LINE__,
+ "BaseDataStreamMarshaller::tightMarshalString1 - "
+ "Encountered a String value that is too long to encode." );
+ }
+
+ bs->writeBoolean( isOnlyAscii );
+ return utflen + 2;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::tightMarshalString2(
+ const std::string& value,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs ) throw ( io::IOException ) {
+
+ try{
+
+ if( bs->readBoolean() ) {
+
+ // If we verified it only holds ascii values
+ if( bs->readBoolean() ) {
+
+ dataOut->writeShort( (short)value.length() );
+ dataOut->writeBytes( value );
+
+ } else {
+ dataOut->writeChars( value );
+ }
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::looseMarshalString(
+ const std::string value,
+ io::DataOutputStream* dataOut ) throw ( io::IOException ) {
+
+ try{
+
+ dataOut->writeBoolean( value != "" );
+ if( value != "" )
+ {
+ dataOut->writeBytes( value );
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string BaseDataStreamMarshaller::looseUnmarshalString(
+ io::DataInputStream* dataIn ) throw ( io::IOException ) {
+
+ try{
+ if( dataIn->readBoolean() ) {
+ return dataIn->readUTF(); // TODO
+ } else {
+ return "";
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BaseDataStreamMarshaller::tightMarshalLong1( OpenWireFormat* wireFormat,
+ long long value,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+
+ if( value == 0L )
+ {
+ bs->writeBoolean( false );
+ bs->writeBoolean( false );
+ return 0;
+ }
+ else
+ {
+ unsigned long long ul = (unsigned long long)value;
+ if( (ul & 0xFFFFFFFFFFFF0000LL) == 0LL )
+ {
+ bs->writeBoolean(false);
+ bs->writeBoolean(true);
+ return 2;
+ }
+ else if( (ul & 0xFFFFFFFF00000000LL) == 0LL )
+ {
+ bs->writeBoolean(true);
+ bs->writeBoolean(false);
+ return 4;
+ }
+ else
+ {
+ bs->writeBoolean(true);
+ bs->writeBoolean(true);
+ return 8;
+ }
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::tightMarshalLong2( OpenWireFormat* wireFormat,
+ long long value,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+ try{
+
+ if( bs->readBoolean() ) {
+
+ if( bs->readBoolean() ) {
+ dataOut->writeLong( value );
+ } else {
+ dataOut->writeInt( (int)value );
+ }
+
+ } else {
+
+ if( bs->readBoolean() ) {
+ dataOut->writeShort( (short)value );
+ }
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long BaseDataStreamMarshaller::tightUnmarshalLong(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+ if( bs->readBoolean() ) {
+
+ if( bs->readBoolean() ) {
+ return dataIn->readLong();
+ } else {
+ return dataIn->readInt();
+ }
+
+ } else {
+
+ if( bs->readBoolean()) {
+ return dataIn->readShort();
+ } else {
+ return 0;
+ }
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::looseMarshalLong( OpenWireFormat* wireFormat,
+ long long value,
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException ) {
+
+ try{
+ dataOut->writeLong( value );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long BaseDataStreamMarshaller::looseUnmarshalLong(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn )
+ throw ( io::IOException ) {
+
+ try{
+
+ return dataIn->readLong();
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+commands::DataStructure* BaseDataStreamMarshaller::tightUnmarshalBrokerError(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs ) throw ( io::IOException ) {
+
+ try{
+
+ if( bs->readBoolean() )
+ {
+ BrokerError* answer = new BrokerError();
+
+ answer->setExceptionClass( tightUnmarshalString( dataIn, bs ) );
+ answer->setMessage( tightUnmarshalString( dataIn, bs ) );
+
+ if( wireFormat->isStackTraceEnabled() )
+ {
+ short length = dataIn->readShort();
+ std::vector< BrokerError::StackTraceElement* > stackTrace;
+
+ for( int i = 0; i < length; ++i )
+ {
+ BrokerError::StackTraceElement* element =
+ new BrokerError::StackTraceElement;
+
+ element->ClassName = tightUnmarshalString( dataIn, bs );
+ element->MethodName = tightUnmarshalString( dataIn, bs );
+ element->FileName = tightUnmarshalString( dataIn, bs );
+ element->LineNumber = dataIn->readInt();
+ stackTrace.push_back( element );
+ }
+ answer->setStackTraceElements( stackTrace );
+ answer->setCause( dynamic_cast<BrokerError*>(
+ tightUnmarshalBrokerError( wireFormat, dataIn, bs ) ) );
+ }
+ return answer;
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
}
+
+////////////////////////////////////////////////////////////////////////////////
+int BaseDataStreamMarshaller::tightMarshalBrokerError1(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ utils::BooleanStream* bs )
+ throw ( io::IOException )
+{
+ try{
+
+ BrokerError* error = dynamic_cast<BrokerError*>( data );
+
+ if( error == NULL ) {
+
+ bs->writeBoolean( false );
+ return 0;
+
+ } else {
+
+ int rc = 0;
+ bs->writeBoolean( true );
+ rc += tightMarshalString1( error->getExceptionClass(), bs );
+ rc += tightMarshalString1( error->getMessage(), bs );
+
+ if( wireFormat->isStackTraceEnabled() ) {
+
+ rc += 2;
+
+ for( int i = 0; i < error->getStackTraceElements().size(); ++i ) {
+
+ const BrokerError::StackTraceElement* element =
+ error->getStackTraceElements()[i];
+ rc += tightMarshalString1( element->ClassName, bs );
+ rc += tightMarshalString1( element->MethodName, bs );
+ rc += tightMarshalString1( element->FileName, bs );
+ rc += 4;
+ }
+ rc += tightMarshalBrokerError1( wireFormat, error->getCause(), bs );
+ }
+
+ return rc;
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshaller::tightMarshalBrokerError2(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {
+
+ try{
+
+ if( bs->readBoolean() ) {
+
+ BrokerError* error = dynamic_cast<BrokerError*>( data );
+
+ tightMarshalString2( error->getExceptionClass(), dataOut, bs );
+ tightMarshalString2( error->getMessage(), dataOut, bs );
+
+ if( wireFormat->isStackTraceEnabled() ) {
+
+ int length = (short)error->getStackTraceElements().size();
+ dataOut->writeShort( (short)length );
+
+ for( int i = 0; i < length; ++i ) {
+
+ BrokerError::StackTraceElement* element =
+ error->getStackTraceElements()[i];
+
+ tightMarshalString2( element->ClassName, dataOut, bs );
+ tightMarshalString2( element->MethodName, dataOut, bs );
+ tightMarshalString2( element->FileName, dataOut, bs );
+ dataOut->writeInt( element->LineNumber );
+ }
+
+ tightMarshalBrokerError2(
+ wireFormat, error->getCause(), dataOut, bs );
+ }
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+commands::DataStructure* BaseDataStreamMarshaller::looseUnmarshalBrokerError(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn )
+ throw ( io::IOException ) {
+ try{
+
+ if( dataIn->readBoolean() ) {
+
+ BrokerError* answer = new BrokerError();
+
+ answer->setExceptionClass( looseUnmarshalString( dataIn ) );
+ answer->setMessage( looseUnmarshalString( dataIn ) );
+
+ if( wireFormat->isStackTraceEnabled() ) {
+
+ short length = dataIn->readShort();
+ std::vector< BrokerError::StackTraceElement* > stackTrace;
+
+ for( int i = 0; i < length; ++i ) {
+
+ BrokerError::StackTraceElement* element =
+ new BrokerError::StackTraceElement;
+
+ element->ClassName = looseUnmarshalString( dataIn );
+ element->MethodName = looseUnmarshalString( dataIn );
+ element->FileName = looseUnmarshalString( dataIn );
+ element->LineNumber = dataIn->readInt();
+
+ stackTrace.push_back( element );
+ }
+ answer->setStackTraceElements( stackTrace );
+ answer->setCause( dynamic_cast<BrokerError*>(
+ looseUnmarshalBrokerError( wireFormat, dataIn ) ) );
+ }
+
+ return answer;
+
+ } else {
+ return NULL;
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
////////////////////////////////////////////////////////////////////////////////
-BaseDataStreamMarshaller::~BaseDataStreamMarshaller() {
+void BaseDataStreamMarshaller::looseMarshalBrokerError(
+ OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException ) {
+
+ try{
+
+ BrokerError* error = dynamic_cast<BrokerError*>( data );
+
+ dataOut->write( error != NULL );
+
+ if( error != NULL ){
+
+ looseMarshalString( error->getExceptionClass(), dataOut );
+ looseMarshalString( error->getMessage(), dataOut );
+
+ if( wireFormat->isStackTraceEnabled() ) {
+
+ int length = error->getStackTraceElements().size();
+
+ dataOut->writeShort( (short)length );
+
+ for( int i = 0; i < length; ++i ) {
+
+ BrokerError::StackTraceElement* element =
+ error->getStackTraceElements()[i];
+
+ looseMarshalString( element->ClassName, dataOut );
+ looseMarshalString( element->MethodName, dataOut );
+ looseMarshalString( element->FileName, dataOut );
+
+ dataOut->writeInt( element->LineNumber );
+ }
+
+ looseMarshalBrokerError( wireFormat, error->getCause(), dataOut );
+ }
+ }
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -91,4 +731,29 @@
}
return buffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string BaseDataStreamMarshaller::readAsciiString(
+ io::DataInputStream* dataIn )
+ throw ( io::IOException )
+{
+ try{
+
+ int size = dataIn->readShort() + 1; // add space c++ NULL
+ unsigned char* data = new unsigned char[size];
+ dataIn->readFully( data, 0, size-1 );
+ data[size] = 0; // enforce NULL
+
+ // Now build a string and copy data into it.
+ std::string text;
+ text.resize( size );
+ text.copy( (char*)data, size );
+ delete data;
+
+ return text;
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
}
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h?view=diff&rev=476619&r1=476618&r2=476619
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h Sat Nov 18 13:59:58 2006
@@ -42,8 +42,7 @@
public:
- BaseDataStreamMarshaller();
- virtual ~BaseDataStreamMarshaller();
+ virtual ~BaseDataStreamMarshaller() {}
/**
* Tight Marhsal to the given stream
@@ -55,7 +54,7 @@
virtual int tightMarshal1( OpenWireFormat* format,
commands::DataStructure* command,
utils::BooleanStream* bs )
- throw ( io::IOException ) { return 0; };
+ throw ( io::IOException ) = 0;
/**
* Tight Marhsal to the given stream
@@ -69,7 +68,7 @@
commands::DataStructure* command,
io::DataOutputStream* ds,
utils::BooleanStream* bs )
- throw ( io::IOException ) {};
+ throw ( io::IOException ) = 0;
/**
* Tight Un-marhsal to the given stream
@@ -83,7 +82,7 @@
commands::DataStructure* command,
io::DataInputStream* dis,
utils::BooleanStream* bs )
- throw ( io::IOException ) {};
+ throw ( io::IOException ) = 0;
/**
* Tight Marhsal to the given stream
@@ -95,7 +94,7 @@
virtual void looseMarshal( OpenWireFormat* format,
commands::DataStructure* command,
io::DataOutputStream* ds )
- throw ( io::IOException ) {};
+ throw ( io::IOException ) = 0;
/**
* Loose Un-marhsal to the given stream
@@ -107,7 +106,7 @@
virtual void looseUnmarshal( OpenWireFormat* format,
commands::DataStructure* command,
io::DataInputStream* dis )
- throw ( io::IOException ) {};
+ throw ( io::IOException ) = 0;
public: // Statics
@@ -144,59 +143,147 @@
protected:
/**
- * Tight Unmarshal an array of char
- * @param dataIn - the DataInputStream to Un-Marshal from
- * @param bs - boolean stream to unmarshal from.
- * @returns the unmarshalled vector of chars.
+ * Tight Unmarshall the cached object
+ * @param wireFormat - The OpenwireFormat properties
+ * @param dataIn - stream to read marshalled form from
+ * @param bs - boolean stream to marshal to.
+ * @returns pointer to a new DataStructure Object
+ * @throws IOException if an error occurs.
*/
- virtual std::vector<unsigned char> tightUnmarshalByteArray(
- io::DataInputStream* dataIn,
- utils::BooleanStream* bs )
- { return std::vector<unsigned char>(); }
+ virtual commands::DataStructure* tightUnmarshalCachedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs ) throw ( io::IOException );
/**
- * Loose Unmarshal an array of char
- * @param dataIn - the DataInputStream to Un-Marshal from
- * @returns the unmarshalled vector of chars.
+ * Tightly marshalls the passed DataStructure based object to the passed
+ * BooleanStream returning the size of the data marshalled
+ * @param wireFormat - The OpenwireFormat properties
+ * @param data - DataStructure Object Pointer to marshal
+ * @param bs - boolean stream to marshal to.
+ * @returns size of data written.
+ * @throws IOException if an error occurs.
*/
- virtual std::vector<unsigned char> looseUnmarshalByteArray(
- io::DataInputStream* dataIn )
- { return std::vector<unsigned char>(); }
+ virtual int tightMarshalCachedObject1( OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
- * Tight Unmarshal a fixed size array from that data input stream
- * and return an stl vector of char as the resultant.
- * @param dataIn - the DataInputStream to Un-Marshal from
- * @param bs - boolean stream to unmarshal from.
- * @param size - size of the const array to unmarshal
- * @returns the unmarshalled vector of chars.
+ * Tightly marshalls the passed DataStructure based object to the passed
+ * streams returning nothing
+ * @param wireFormat - The OpenwireFormat properties
+ * @param data - DataStructure Object Pointer to marshal
+ * @param bs - boolean stream to marshal to.
+ * @param dataOut - stream to write marshalled data to
+ * @throws IOException if an error occurs.
*/
- virtual std::vector<unsigned char> tightUnmarshalConstByteArray(
- io::DataInputStream* dataIn,
- utils::BooleanStream* bs,
- int size ) { return std::vector<unsigned char>(); }
+ virtual void tightMarshalCachedObject2( OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
- * Tight Unmarshal a fixed size array from that data input stream
- * and return an stl vector of char as the resultant.
- * @param dataIn - the DataInputStream to Un-Marshal from
- * @param bs - boolean stream to unmarshal from.
- * @param size - size of the const array to unmarshal
- * @returns the unmarshalled vector of chars.
+ * Loosely marshalls the passed DataStructure based object to the passed
+ * stream returning nothing
+ * @param wireFormat - The OpenwireFormat properties
+ * @param data - DataStructure Object Pointer to marshal
+ * @param bs - boolean stream to marshal to.
+ * @param dataOut - stream to write marshalled data to
+ * @throws IOException if an error occurs.
*/
- virtual std::vector<unsigned char> looseUnmarshalConstByteArray(
- io::DataInputStream* dataIn,
- int size ) { return std::vector<unsigned char>(); }
+ virtual void looseMarshalCachedObject( OpenWireFormat* wireFormat,
+ commands::DataStructure* data,
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException );
+
+ /**
+ * Loose Unmarshall the cached object
+ * @param wireFormat - The OpenwireFormat properties
+ * @param dataIn - stream to read marshalled form from
+ * @returns pointer to a new DataStructure Object
+ * @throws IOException if an error occurs.
+ */
+ virtual commands::DataStructure* looseUnmarshalCachedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn ) throw ( io::IOException );
+
+ /**
+ * Tightly marshalls the passed DataStructure based object to the passed
+ * BooleanStream returning the size of the data marshalled
+ * @param wireFormat - The OpenwireFormat properties
+ * @param object - DataStructure Object Pointer to marshal
+ * @param bs - boolean stream to marshal to.
+ * @returns size of data written.
+ * @throws IOException if an error occurs.
+ */
+ virtual int tightMarshalNestedObject1( OpenWireFormat* wireFormat,
+ commands::DataStructure* object,
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
+
+ /**
+ * Tightly marshalls the passed DataStructure based object to the passed
+ * streams returning nothing
+ * @param wireFormat - The OpenwireFormat properties
+ * @param object - DataStructure Object Pointer to marshal
+ * @param bs - boolean stream to marshal to.
+ * @param dataOut - stream to write marshalled data to
+ * @throws IOException if an error occurs.
+ */
+ virtual void tightMarshalNestedObject2( OpenWireFormat* wireFormat,
+ commands::DataStructure* object,
+ io::DataOutputStream* dataOut,
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
+
+ /**
+ * Tight Unmarshall the nested object
+ * @param wireFormat - The OpenwireFormat properties
+ * @param dataIn - stream to read marshalled form from
+ * @param bs - boolean stream to marshal to.
+ * @returns pointer to a new DataStructure Object
+ * @throws IOException if an error occurs.
+ */
+ virtual commands::DataStructure* tightUnmarshalNestedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs ) throw ( io::IOException );
+
+ /**
+ * Loose Unmarshall the nested object
+ * @param wireFormat - The OpenwireFormat properties
+ * @param dataIn - stream to read marshalled form from
+ * @returns pointer to a new DataStructure Object
+ * @throws IOException if an error occurs.
+ */
+ virtual commands::DataStructure* looseUnmarshalNestedObject(
+ OpenWireFormat* wireFormat,
+ io::DataInputStream* dataIn ) throw ( io::IOException );
+
+ /**
+ * Loose marshall the nested object
+ * @param wireFormat - The OpenwireFormat properties
+ * @param object - DataStructure Object Pointer to marshal
+ * @param dataOut - stream to write marshalled data to
+ * @throws IOException if an error occurs.
+ */
+ virtual void looseMarshalNestedObject( OpenWireFormat* wireFormat,
+ commands::DataStructure* object,
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException );
/**
* Performs Tight Unmarshalling of String Objects
* @param dataIn - the DataInputStream to Un-Marshal from
* @param bs - boolean stream to unmarshal from.
* @returns the unmarshalled string.
+ * @throws IOException if an error occurs.
*/
virtual std::string tightUnmarshalString( io::DataInputStream* dataIn,
- utils::BooleanStream* bs ) {}
-
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Tight Marshals the String to a Booleans Stream Object, returns
@@ -204,34 +291,42 @@
* @param value - string to marshal
* @param bs - BooleanStream to use.
* @returns size of marshalled string.
+ * @throws IOException if an error occurs.
*/
virtual int tightMarshalString1( const std::string& value,
- utils::BooleanStream* bs ) {}
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Tight Marshals the passed string to the streams passed
* @param value - string to marshal
* @param dataOut - the DataOutputStream to Marshal to
* @param bs - boolean stream to marshal to.
+ * @throws IOException if an error occurs.
*/
virtual void tightMarshalString2( const std::string& value,
io::DataOutputStream* dataOut,
- utils::BooleanStream* bs ) {}
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Loose Marshal the String to the DataOuputStream passed
* @param value - string to marshal
* @param dataOut - stream to write marshalled form to
+ * @throws IOException if an error occurs.
*/
virtual void looseMarshalString( const std::string value,
- io::DataOutputStream* dataOut ) {}
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException );
/**
* Loose Un-Marshal the String to the DataOuputStream passed
* @param dataIn - stream to read marshalled form from
* @return the unmarshalled string
+ * @throws IOException if an error occurs.
*/
- virtual std::string looseUnmarshalString( io::DataInputStream* dataIn ) {}
+ virtual std::string looseUnmarshalString( io::DataInputStream* dataIn )
+ throw ( io::IOException );
/**
* Tightly marshal the long long to the BooleanStream passed.
@@ -239,10 +334,12 @@
* @param value - long long to marshal
* @param bs - boolean stream to marshal to.
* @returns size of data written.
+ * @throws IOException if an error occurs.
*/
virtual int tightMarshalLong1( OpenWireFormat* wireFormat,
long long value,
- utils::BooleanStream* bs ) {}
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Tightly marshal the long long to the Streams passed.
@@ -250,11 +347,13 @@
* @param value - long long to marshal
* @param dataOut - stream to write marshalled form to
* @param bs - boolean stream to marshal to.
+ * @throws IOException if an error occurs.
*/
virtual void tightMarshalLong2( OpenWireFormat* wireFormat,
long long value,
io::DataOutputStream* dataOut,
- utils::BooleanStream* bs ) {}
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Tight marshal the long long type.
@@ -262,159 +361,100 @@
* @param dataIn - stream to read marshalled form from
* @param bs - boolean stream to marshal to.
* @returns the unmarshalled long long
+ * @throws IOException if an error occurs.
*/
virtual long long tightUnmarshalLong( OpenWireFormat* wireFormat,
io::DataInputStream* dataIn,
- utils::BooleanStream* bs ) {}
-
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Tightly marshal the long long to the BooleanStream passed.
* @param wireFormat - The OpenwireFormat properties
* @param value - long long to marshal
* @param dataOut - DataOutputStream to marshal to.
+ * @throws IOException if an error occurs.
*/
virtual void looseMarshalLong( OpenWireFormat* wireFormat,
long long value,
- io::DataOutputStream* dataOut ) {}
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException );
/**
* Loose marshal the long long type.
* @param wireFormat - The OpenwireFormat properties
* @param dataIn - stream to read marshalled form from
* @returns the unmarshalled long long
+ * @throws IOException if an error occurs.
*/
virtual long long looseUnmarshalLong( OpenWireFormat* wireFormat,
- io::DataInputStream* dataIn ) { return 0; }
-
- /**
- * Tight Unmarshall the cached object
- * @param wireFormat - The OpenwireFormat properties
- * @param dataIn - stream to read marshalled form from
- * @param bs - boolean stream to marshal to.
- * @returns pointer to a new DataStructure Object
- */
- virtual commands::DataStructure* tightUnmarshalCachedObject(
- OpenWireFormat* wireFormat,
- io::DataInputStream* dataIn,
- utils::BooleanStream* bs ) {}
-
- /**
- * Tightly marshalls the passed DataStructure based object to the passed
- * BooleanStream returning the size of the data marshalled
- * @param wireFormat - The OpenwireFormat properties
- * @param data - DataStructure Object Pointer to marshal
- * @param bs - boolean stream to marshal to.
- * @returns size of data written.
- */
- virtual int tightMarshalCachedObject1( OpenWireFormat* wireFormat,
- commands::DataStructure* data,
- utils::BooleanStream* bs ) { return 0; }
+ io::DataInputStream* dataIn )
+ throw ( io::IOException );
/**
- * Tightly marshalls the passed DataStructure based object to the passed
- * streams returning nothing
- * @param wireFormat - The OpenwireFormat properties
- * @param data - DataStructure Object Pointer to marshal
- * @param bs - boolean stream to marshal to.
- * @param dataOut - stream to write marshalled data to
- */
- virtual void tightMarshalCachedObject2( OpenWireFormat* wireFormat,
- commands::DataStructure* data,
- io::DataOutputStream* dataOut,
- utils::BooleanStream* bs ) {}
-
-
- /**
- * Loosely marshalls the passed DataStructure based object to the passed
- * stream returning nothing
- * @param wireFormat - The OpenwireFormat properties
- * @param data - DataStructure Object Pointer to marshal
- * @param bs - boolean stream to marshal to.
- * @param dataOut - stream to write marshalled data to
- */
- virtual void looseMarshalCachedObject( OpenWireFormat* wireFormat,
- commands::DataStructure* data,
- io::DataOutputStream* dataOut ) {}
-
- /**
- * Loose Unmarshall the cached object
- * @param wireFormat - The OpenwireFormat properties
- * @param dataIn - stream to read marshalled form from
- * @returns pointer to a new DataStructure Object
- */
- virtual commands::DataStructure* looseUnmarshalCachedObject(
- OpenWireFormat* wireFormat,
- io::DataInputStream* dataIn ) { return NULL; }
-
- /**
- * Tightly marshalls the passed DataStructure based object to the passed
- * BooleanStream returning the size of the data marshalled
- * @param wireFormat - The OpenwireFormat properties
- * @param object - DataStructure Object Pointer to marshal
- * @param bs - boolean stream to marshal to.
- * @returns size of data written.
- */
- virtual int tightMarshalNestedObject1( OpenWireFormat* wireFormat,
- commands::DataStructure* object,
- utils::BooleanStream* bs ) { return 0; }
-
- /**
- * Tightly marshalls the passed DataStructure based object to the passed
- * streams returning nothing
- * @param wireFormat - The OpenwireFormat properties
- * @param object - DataStructure Object Pointer to marshal
- * @param bs - boolean stream to marshal to.
- * @param dataOut - stream to write marshalled data to
+ * Tight Unmarshal an array of char
+ * @param dataIn - the DataInputStream to Un-Marshal from
+ * @param bs - boolean stream to unmarshal from.
+ * @returns the unmarshalled vector of chars.
+ * @throws IOException if an error occurs.
*/
- virtual void tightMarshalNestedObject2( OpenWireFormat* wireFormat,
- commands::DataStructure* object,
- io::DataOutputStream* dataOut,
- utils::BooleanStream* bs ) {}
+ virtual std::vector<unsigned char> tightUnmarshalByteArray(
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs ) throw ( io::IOException )
+ { return std::vector<unsigned char>(); }
/**
- * Tight Unmarshall the nested object
- * @param wireFormat - The OpenwireFormat properties
- * @param dataIn - stream to read marshalled form from
- * @param bs - boolean stream to marshal to.
- * @returns pointer to a new DataStructure Object
+ * Loose Unmarshal an array of char
+ * @param dataIn - the DataInputStream to Un-Marshal from
+ * @returns the unmarshalled vector of chars.
+ * @throws IOException if an error occurs.
*/
- virtual commands::DataStructure* tightUnmarshalNestedObject(
- OpenWireFormat* wireFormat,
- io::DataInputStream* dataIn,
- utils::BooleanStream* bs ) { return NULL; }
+ virtual std::vector<unsigned char> looseUnmarshalByteArray(
+ io::DataInputStream* dataIn ) throw ( io::IOException )
+ { return std::vector<unsigned char>(); }
/**
- * Loose Unmarshall the nested object
- * @param wireFormat - The OpenwireFormat properties
- * @param dataIn - stream to read marshalled form from
- * @returns pointer to a new DataStructure Object
+ * Tight Unmarshal a fixed size array from that data input stream
+ * and return an stl vector of char as the resultant.
+ * @param dataIn - the DataInputStream to Un-Marshal from
+ * @param bs - boolean stream to unmarshal from.
+ * @param size - size of the const array to unmarshal
+ * @returns the unmarshalled vector of chars.
+ * @throws IOException if an error occurs.
*/
- virtual commands::DataStructure* looseUnmarshalNestedObject(
- OpenWireFormat* wireFormat,
- io::DataInputStream* dataIn ) { return NULL; }
+ virtual std::vector<unsigned char> tightUnmarshalConstByteArray(
+ io::DataInputStream* dataIn,
+ utils::BooleanStream* bs,
+ int size ) throw ( io::IOException ) {
+ return std::vector<unsigned char>();
+ }
/**
- * Loose marshall the nested object
- * @param wireFormat - The OpenwireFormat properties
- * @param object - DataStructure Object Pointer to marshal
- * @param dataOut - stream to write marshalled data to
+ * Tight Unmarshal a fixed size array from that data input stream
+ * and return an stl vector of char as the resultant.
+ * @param dataIn - the DataInputStream to Un-Marshal from
+ * @param bs - boolean stream to unmarshal from.
+ * @param size - size of the const array to unmarshal
+ * @returns the unmarshalled vector of chars.
+ * @throws IOException if an error occurs.
*/
- virtual void looseMarshalNestedObject( OpenWireFormat* wireFormat,
- commands::DataStructure* object,
- io::DataOutputStream* dataOut ) {}
-
+ virtual std::vector<unsigned char> looseUnmarshalConstByteArray(
+ io::DataInputStream* dataIn,
+ int size ) throw ( io::IOException )
+ { return std::vector<unsigned char>(); }
+
/**
* Tight Unarshall the Error object
* @param wireFormat - The OpenwireFormat properties
* @param dataIn - stream to read marshalled form from
* @param bs - boolean stream to marshal to.
* @returns pointer to a new DataStructure Object
+ * @throws IOException if an error occurs.
*/
virtual commands::DataStructure* tightUnmarshalBrokerError(
OpenWireFormat* wireFormat,
io::DataInputStream* dataIn,
- utils::BooleanStream* bs ) { return NULL; }
+ utils::BooleanStream* bs ) throw ( io::IOException );
/**
* Tight Marshall the Error object
@@ -422,10 +462,12 @@
* @param error - Error to Marshal
* @param bs - boolean stream to marshal to.
* @returns size of the marshalled data
+ * @throws IOException if an error occurs.
*/
virtual int tightMarshalBrokerError1( OpenWireFormat* wireFormat,
commands::DataStructure* error,
- utils::BooleanStream* bs ) { return 0; }
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Tight Marshall the Error object
@@ -433,49 +475,68 @@
* @param error - Error to Marshal
* @param dataOut - stream to write marshalled data to
* @param bs - boolean stream to marshal to.
+ * @throws IOException if an error occurs.
*/
virtual void tightMarshalBrokerError2( OpenWireFormat* wireFormat,
commands::DataStructure* error,
io::DataOutputStream* dataOut,
- utils::BooleanStream* bs ) {}
+ utils::BooleanStream* bs )
+ throw ( io::IOException );
/**
* Loose Unarshall the Error object
* @param wireFormat - The OpenwireFormat properties
* @param dataIn - stream to read marshalled form from
* @returns pointer to a new DataStructure Object
+ * @throws IOException if an error occurs.
*/
virtual commands::DataStructure* looseUnmarshalBrokerError(
OpenWireFormat* wireFormat,
- io::DataInputStream* dataIn ) { return NULL; }
+ io::DataInputStream* dataIn ) throw ( io::IOException );
/**
* Tight Marshall the Error object
* @param wireFormat - The OpenwireFormat properties
* @param error - Error to Marshal
* @param dataOut - stream to write marshalled data to
+ * @throws IOException if an error occurs.
*/
virtual void looseMarshalBrokerError( OpenWireFormat* wireFormat,
commands::DataStructure* error,
- io::DataOutputStream* dataOut ) {}
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException );
template<typename T>
int tightMarshalObjectArray1( OpenWireFormat* wireFormat,
std::vector<T*>,
utils::BooleanStream* bs )
+ throw ( io::IOException )
{ return 0; }
template<typename T>
void tightMarshalObjectArray2( OpenWireFormat* wireFormat,
std::vector<T*>,
io::DataOutputStream* dataOut,
- utils::BooleanStream* bs ) {}
+ utils::BooleanStream* bs )
+ throw ( io::IOException ) {}
template<typename T>
void looseMarshalObjectArray( OpenWireFormat* wireFormat,
std::vector<T*>,
- io::DataOutputStream* dataOut ) {}
-
+ io::DataOutputStream* dataOut )
+ throw ( io::IOException ) {}
+
+ protected:
+
+ /**
+ * Given an DataInputStream read a know ASCII formatted string from
+ * the input and return that string
+ * @param dataIn - DataInputStream to read from
+ * @return string value read from stream
+ */
+ virtual std::string readAsciiString( io::DataInputStream* dataIn )
+ throw ( io::IOException );
+
};
}}}}