activemq-cpp-3.3.0

src/main/activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.h

Go to the documentation of this file.
00001 
00018 #ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_
00019 #define _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_
00020 
00021 #include <activemq/wireformat/openwire/marshal/DataStreamMarshaller.h>
00022 #include <activemq/wireformat/openwire/utils/HexTable.h>
00023 #include <activemq/commands/MessageId.h>
00024 #include <activemq/commands/ProducerId.h>
00025 #include <activemq/commands/TransactionId.h>
00026 #include <activemq/util/Config.h>
00027 
00028 namespace activemq{
00029 namespace wireformat{
00030 namespace openwire{
00031 namespace marshal{
00032 
00039     class AMQCPP_API BaseDataStreamMarshaller : public DataStreamMarshaller {
00040     private:
00041 
00042         // Table for converting bytes to Hex Strings.
00043         static utils::HexTable hexTable;
00044 
00045     public:
00046 
00047         virtual ~BaseDataStreamMarshaller() {}
00048 
00056         virtual int tightMarshal1( OpenWireFormat* format AMQCPP_UNUSED,
00057                                    commands::DataStructure* command AMQCPP_UNUSED,
00058                                    utils::BooleanStream* bs AMQCPP_UNUSED ) { return 0; }
00059 
00068         virtual void tightMarshal2( OpenWireFormat* format AMQCPP_UNUSED,
00069                                     commands::DataStructure* command AMQCPP_UNUSED,
00070                                     decaf::io::DataOutputStream* ds AMQCPP_UNUSED,
00071                                     utils::BooleanStream* bs AMQCPP_UNUSED ) {}
00072 
00081         virtual void tightUnmarshal( OpenWireFormat* format AMQCPP_UNUSED,
00082                                      commands::DataStructure* command AMQCPP_UNUSED,
00083                                      decaf::io::DataInputStream* dis AMQCPP_UNUSED,
00084                                      utils::BooleanStream* bs AMQCPP_UNUSED ) {}
00085 
00093         virtual void looseMarshal( OpenWireFormat* format AMQCPP_UNUSED,
00094                                    commands::DataStructure* command AMQCPP_UNUSED,
00095                                    decaf::io::DataOutputStream* ds AMQCPP_UNUSED ) {}
00096 
00104         virtual void looseUnmarshal( OpenWireFormat* format AMQCPP_UNUSED,
00105                                      commands::DataStructure* command AMQCPP_UNUSED,
00106                                      decaf::io::DataInputStream* dis AMQCPP_UNUSED ) {}
00107 
00108     public:      // Statics
00109 
00115         static std::string toString( const commands::MessageId* id );
00116 
00122         static std::string toString( const commands::ProducerId* id );
00123 
00129         static std::string toString( const commands::TransactionId* txnId );
00130 
00137         static std::string toHexFromBytes(
00138             const std::vector<unsigned char>& data );
00139 
00140     protected:
00141 
00150         virtual commands::DataStructure* tightUnmarshalCachedObject(
00151             OpenWireFormat* wireFormat,
00152             decaf::io::DataInputStream* dataIn,
00153             utils::BooleanStream* bs );
00154 
00164         virtual int tightMarshalCachedObject1( OpenWireFormat* wireFormat,
00165                                                commands::DataStructure* data,
00166                                                utils::BooleanStream* bs );
00167 
00177         virtual void tightMarshalCachedObject2( OpenWireFormat* wireFormat,
00178                                                 commands::DataStructure* data,
00179                                                 decaf::io::DataOutputStream* dataOut,
00180                                                 utils::BooleanStream* bs );
00181 
00190         virtual void looseMarshalCachedObject( OpenWireFormat* wireFormat,
00191                                                commands::DataStructure* data,
00192                                                decaf::io::DataOutputStream* dataOut );
00193 
00201         virtual commands::DataStructure* looseUnmarshalCachedObject(
00202             OpenWireFormat* wireFormat,
00203             decaf::io::DataInputStream* dataIn );
00204 
00214         virtual int tightMarshalNestedObject1( OpenWireFormat* wireFormat,
00215                                                commands::DataStructure* object,
00216                                                utils::BooleanStream* bs );
00217 
00227         virtual void tightMarshalNestedObject2( OpenWireFormat* wireFormat,
00228                                                 commands::DataStructure* object,
00229                                                 decaf::io::DataOutputStream* dataOut,
00230                                                 utils::BooleanStream* bs );
00231 
00240         virtual commands::DataStructure* tightUnmarshalNestedObject(
00241             OpenWireFormat* wireFormat,
00242             decaf::io::DataInputStream* dataIn,
00243             utils::BooleanStream* bs );
00244 
00252         virtual commands::DataStructure* looseUnmarshalNestedObject(
00253             OpenWireFormat* wireFormat,
00254             decaf::io::DataInputStream* dataIn );
00255 
00263         virtual void looseMarshalNestedObject( OpenWireFormat* wireFormat,
00264                                                commands::DataStructure* object,
00265                                                decaf::io::DataOutputStream* dataOut );
00266 
00274         virtual std::string tightUnmarshalString( decaf::io::DataInputStream* dataIn,
00275                                                   utils::BooleanStream* bs );
00276 
00285         virtual int tightMarshalString1( const std::string& value,
00286                                          utils::BooleanStream* bs );
00287 
00295         virtual void tightMarshalString2( const std::string& value,
00296                                           decaf::io::DataOutputStream* dataOut,
00297                                           utils::BooleanStream* bs );
00298 
00305         virtual void looseMarshalString( const std::string value,
00306                                          decaf::io::DataOutputStream* dataOut );
00307 
00314         virtual std::string looseUnmarshalString( decaf::io::DataInputStream* dataIn );
00315 
00324         virtual int tightMarshalLong1( OpenWireFormat* wireFormat,
00325                                        long long value,
00326                                        utils::BooleanStream* bs );
00327 
00336         virtual void tightMarshalLong2( OpenWireFormat* wireFormat,
00337                                         long long value,
00338                                         decaf::io::DataOutputStream* dataOut,
00339                                         utils::BooleanStream* bs );
00340 
00349         virtual long long tightUnmarshalLong( OpenWireFormat* wireFormat,
00350                                               decaf::io::DataInputStream* dataIn,
00351                                               utils::BooleanStream* bs );
00352 
00360         virtual void looseMarshalLong( OpenWireFormat* wireFormat,
00361                                        long long value,
00362                                        decaf::io::DataOutputStream* dataOut );
00363 
00371         virtual long long looseUnmarshalLong( OpenWireFormat* wireFormat,
00372                                               decaf::io::DataInputStream* dataIn );
00373 
00381         virtual std::vector<unsigned char> tightUnmarshalByteArray(
00382             decaf::io::DataInputStream* dataIn,
00383             utils::BooleanStream* bs );
00384 
00391         virtual std::vector<unsigned char> looseUnmarshalByteArray(
00392             decaf::io::DataInputStream* dataIn );
00393 
00403         virtual std::vector<unsigned char> tightUnmarshalConstByteArray(
00404             decaf::io::DataInputStream* dataIn,
00405             utils::BooleanStream* bs,
00406             int size );
00407 
00416         virtual std::vector<unsigned char> looseUnmarshalConstByteArray(
00417             decaf::io::DataInputStream* dataIn, int size );
00418 
00427         virtual commands::DataStructure* tightUnmarshalBrokerError(
00428             OpenWireFormat* wireFormat,
00429             decaf::io::DataInputStream* dataIn,
00430             utils::BooleanStream* bs );
00431 
00440         virtual int tightMarshalBrokerError1( OpenWireFormat* wireFormat,
00441                                               commands::DataStructure* data,
00442                                               utils::BooleanStream* bs );
00443 
00452         virtual void tightMarshalBrokerError2( OpenWireFormat* wireFormat,
00453                                                commands::DataStructure* data,
00454                                                decaf::io::DataOutputStream* dataOut,
00455                                                utils::BooleanStream* bs );
00456 
00464         virtual commands::DataStructure* looseUnmarshalBrokerError(
00465             OpenWireFormat* wireFormat,
00466             decaf::io::DataInputStream* dataIn );
00467 
00475         virtual void looseMarshalBrokerError( OpenWireFormat* wireFormat,
00476                                               commands::DataStructure* data,
00477                                               decaf::io::DataOutputStream* dataOut );
00478 
00489         template<typename T>
00490         int tightMarshalObjectArray1( OpenWireFormat* wireFormat,
00491                                       std::vector<T> objects,
00492                                       utils::BooleanStream* bs ) {
00493 
00494             try{
00495                 if( !objects.empty() )
00496                 {
00497                     int rc = 0;
00498                     bs->writeBoolean( true );
00499                     rc += 2;
00500                     for( std::size_t i = 0; i < objects.size(); ++i ) {
00501                         rc += tightMarshalNestedObject1(
00502                                 wireFormat, objects[i].get(), bs );
00503                     }
00504                     return rc;
00505 
00506                 } else {
00507                     bs->writeBoolean( false );
00508                     return 0;
00509                 }
00510             }
00511             AMQ_CATCH_RETHROW( decaf::io::IOException )
00512             AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException )
00513             AMQ_CATCHALL_THROW( decaf::io::IOException )
00514         }
00515 
00526         template<typename T>
00527         void tightMarshalObjectArray2( OpenWireFormat* wireFormat,
00528                                        std::vector<T> objects,
00529                                        decaf::io::DataOutputStream* dataOut,
00530                                        utils::BooleanStream* bs ) {
00531 
00532             try {
00533 
00534                 if( bs->readBoolean() ) {
00535 
00536                     dataOut->writeShort( (short)objects.size() );
00537                     for( std::size_t i = 0; i < objects.size(); ++i ) {
00538                         tightMarshalNestedObject2(
00539                             wireFormat, objects[i].get(), dataOut, bs );
00540                     }
00541                 }
00542             }
00543             AMQ_CATCH_RETHROW( decaf::io::IOException )
00544             AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException )
00545             AMQ_CATCHALL_THROW( decaf::io::IOException )
00546         }
00547 
00557         template<typename T>
00558         void looseMarshalObjectArray( OpenWireFormat* wireFormat,
00559                                       std::vector<T> objects,
00560                                       decaf::io::DataOutputStream* dataOut ) {
00561 
00562             try {
00563 
00564                 dataOut->writeBoolean( !objects.empty() );
00565                 if( !objects.empty() ) {
00566 
00567                     dataOut->writeShort( (short)objects.size() );
00568                     for( std::size_t i = 0; i < objects.size(); ++i ) {
00569                         looseMarshalNestedObject(
00570                             wireFormat, objects[i].get(), dataOut );
00571                     }
00572                 }
00573             }
00574             AMQ_CATCH_RETHROW( decaf::io::IOException )
00575             AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException )
00576             AMQ_CATCHALL_THROW( decaf::io::IOException )
00577         }
00578 
00579     protected:
00580 
00587         virtual std::string readAsciiString( decaf::io::DataInputStream* dataIn );
00588 
00589     };
00590 
00591 }}}}
00592 
00593 #endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_*/