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
00043 static utils::HexTable hexTable;
00044
00045 public:
00046
00047 virtual ~BaseDataStreamMarshaller() {}
00048
00056 virtual int tightMarshal1(OpenWireFormat* format AMQCPP_UNUSED, commands::DataStructure* command AMQCPP_UNUSED, utils::BooleanStream* bs AMQCPP_UNUSED) {
00057 return 0;
00058 }
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:
00109
00110
00116 static std::string toString(const commands::MessageId* id);
00117
00123 static std::string toString(const commands::ProducerId* id);
00124
00130 static std::string toString(const commands::TransactionId* txnId);
00131
00138 static std::string toHexFromBytes(const std::vector<unsigned char>& data);
00139
00140 protected:
00141
00150 virtual commands::DataStructure* tightUnmarshalCachedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
00151
00161 virtual int tightMarshalCachedObject1(OpenWireFormat* wireFormat, commands::DataStructure* data, utils::BooleanStream* bs);
00162
00172 virtual void tightMarshalCachedObject2(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut,utils::BooleanStream* bs);
00173
00182 virtual void looseMarshalCachedObject(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut);
00183
00191 virtual commands::DataStructure* looseUnmarshalCachedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
00192
00202 virtual int tightMarshalNestedObject1(OpenWireFormat* wireFormat, commands::DataStructure* object, utils::BooleanStream* bs);
00203
00213 virtual void tightMarshalNestedObject2(OpenWireFormat* wireFormat, commands::DataStructure* object, decaf::io::DataOutputStream* dataOut,
00214 utils::BooleanStream* bs);
00215
00224 virtual commands::DataStructure* tightUnmarshalNestedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
00225
00233 virtual commands::DataStructure* looseUnmarshalNestedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
00234
00242 virtual void looseMarshalNestedObject(OpenWireFormat* wireFormat, commands::DataStructure* object, decaf::io::DataOutputStream* dataOut);
00243
00251 virtual std::string tightUnmarshalString(decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
00252
00261 virtual int tightMarshalString1(const std::string& value, utils::BooleanStream* bs);
00262
00270 virtual void tightMarshalString2(const std::string& value, decaf::io::DataOutputStream* dataOut, utils::BooleanStream* bs);
00271
00278 virtual void looseMarshalString(const std::string value, decaf::io::DataOutputStream* dataOut);
00279
00286 virtual std::string looseUnmarshalString(decaf::io::DataInputStream* dataIn);
00287
00296 virtual int tightMarshalLong1(OpenWireFormat* wireFormat, long long value, utils::BooleanStream* bs);
00297
00306 virtual void tightMarshalLong2(OpenWireFormat* wireFormat, long long value, decaf::io::DataOutputStream* dataOut, utils::BooleanStream* bs);
00307
00316 virtual long long tightUnmarshalLong(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
00317
00325 virtual void looseMarshalLong(OpenWireFormat* wireFormat, long long value, decaf::io::DataOutputStream* dataOut);
00326
00334 virtual long long looseUnmarshalLong(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
00335
00343 virtual std::vector<unsigned char> tightUnmarshalByteArray(decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
00344
00351 virtual std::vector<unsigned char> looseUnmarshalByteArray(decaf::io::DataInputStream* dataIn);
00352
00362 virtual std::vector<unsigned char> tightUnmarshalConstByteArray(decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs, int size);
00363
00372 virtual std::vector<unsigned char> looseUnmarshalConstByteArray(decaf::io::DataInputStream* dataIn, int size);
00373
00382 virtual commands::DataStructure* tightUnmarshalBrokerError(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
00383
00392 virtual int tightMarshalBrokerError1(OpenWireFormat* wireFormat, commands::DataStructure* data, utils::BooleanStream* bs);
00393
00402 virtual void tightMarshalBrokerError2(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut,utils::BooleanStream* bs);
00403
00411 virtual commands::DataStructure* looseUnmarshalBrokerError(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
00412
00420 virtual void looseMarshalBrokerError(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut);
00421
00432 template<typename T>
00433 int tightMarshalObjectArray1(OpenWireFormat* wireFormat, std::vector<T> objects, utils::BooleanStream* bs) {
00434
00435 try {
00436 if (!objects.empty()) {
00437 int rc = 0;
00438 bs->writeBoolean(true);
00439 rc += 2;
00440 for (std::size_t i = 0; i < objects.size(); ++i) {
00441 rc += tightMarshalNestedObject1(wireFormat, objects[i].get(), bs);
00442 }
00443 return rc;
00444
00445 } else {
00446 bs->writeBoolean(false);
00447 return 0;
00448 }
00449 }
00450 AMQ_CATCH_RETHROW(decaf::io::IOException)
00451 AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException)
00452 AMQ_CATCHALL_THROW(decaf::io::IOException)
00453 }
00454
00465 template<typename T>
00466 void tightMarshalObjectArray2(OpenWireFormat* wireFormat, std::vector<T> objects, decaf::io::DataOutputStream* dataOut, utils::BooleanStream* bs) {
00467
00468 try {
00469
00470 if (bs->readBoolean()) {
00471
00472 dataOut->writeShort((short) objects.size());
00473 for (std::size_t i = 0; i < objects.size(); ++i) {
00474 tightMarshalNestedObject2(wireFormat, objects[i].get(), dataOut, bs);
00475 }
00476 }
00477 }
00478 AMQ_CATCH_RETHROW(decaf::io::IOException)
00479 AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException)
00480 AMQ_CATCHALL_THROW(decaf::io::IOException)
00481 }
00482
00492 template<typename T>
00493 void looseMarshalObjectArray(OpenWireFormat* wireFormat, std::vector<T> objects, decaf::io::DataOutputStream* dataOut) {
00494
00495 try {
00496
00497 dataOut->writeBoolean(!objects.empty());
00498 if (!objects.empty()) {
00499
00500 dataOut->writeShort((short) objects.size());
00501 for (std::size_t i = 0; i < objects.size(); ++i) {
00502 looseMarshalNestedObject(wireFormat, objects[i].get(), dataOut);
00503 }
00504 }
00505 }
00506 AMQ_CATCH_RETHROW(decaf::io::IOException)
00507 AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::Exception, decaf::io::IOException)
00508 AMQ_CATCHALL_THROW(decaf::io::IOException)
00509 }
00510
00511 protected:
00512
00519 virtual std::string readAsciiString(decaf::io::DataInputStream* dataIn);
00520
00521 };
00522
00523 }}}}
00524
00525 #endif