activemq-cpp-3.9.5
BaseDataStreamMarshaller.h
Go to the documentation of this file.
1
17
18#ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_
19#define _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_
20
27
28namespace activemq{
29namespace wireformat{
30namespace openwire{
31namespace marshal{
32
40 private:
41
42 // Table for converting bytes to Hex Strings.
43 static utils::HexTable hexTable;
44
45 public:
46
48
56 virtual int tightMarshal1(OpenWireFormat* format AMQCPP_UNUSED, commands::DataStructure* command AMQCPP_UNUSED, utils::BooleanStream* bs AMQCPP_UNUSED) {
57 return 0;
58 }
59
68 virtual void tightMarshal2(OpenWireFormat* format AMQCPP_UNUSED,
69 commands::DataStructure* command AMQCPP_UNUSED,
70 decaf::io::DataOutputStream* ds AMQCPP_UNUSED,
71 utils::BooleanStream* bs AMQCPP_UNUSED) {}
72
81 virtual void tightUnmarshal(OpenWireFormat* format AMQCPP_UNUSED,
82 commands::DataStructure* command AMQCPP_UNUSED,
83 decaf::io::DataInputStream* dis AMQCPP_UNUSED,
84 utils::BooleanStream* bs AMQCPP_UNUSED) {}
85
93 virtual void looseMarshal(OpenWireFormat* format AMQCPP_UNUSED,
94 commands::DataStructure* command AMQCPP_UNUSED,
95 decaf::io::DataOutputStream* ds AMQCPP_UNUSED) {}
96
104 virtual void looseUnmarshal(OpenWireFormat* format AMQCPP_UNUSED,
105 commands::DataStructure* command AMQCPP_UNUSED,
106 decaf::io::DataInputStream* dis AMQCPP_UNUSED) {}
107
108 public:
109 // Statics
110
116 static std::string toString(const commands::MessageId* id);
117
123 static std::string toString(const commands::ProducerId* id);
124
130 static std::string toString(const commands::TransactionId* txnId);
131
138 static std::string toHexFromBytes(const std::vector<unsigned char>& data);
139
140 protected:
141
151
162
173
183
192
203
215
225
234
243
252
261 virtual int tightMarshalString1(const std::string& value, utils::BooleanStream* bs);
262
270 virtual void tightMarshalString2(const std::string& value, decaf::io::DataOutputStream* dataOut, utils::BooleanStream* bs);
271
278 virtual void looseMarshalString(const std::string value, decaf::io::DataOutputStream* dataOut);
279
287
296 virtual int tightMarshalLong1(OpenWireFormat* wireFormat, long long value, utils::BooleanStream* bs);
297
306 virtual void tightMarshalLong2(OpenWireFormat* wireFormat, long long value, decaf::io::DataOutputStream* dataOut, utils::BooleanStream* bs);
307
317
325 virtual void looseMarshalLong(OpenWireFormat* wireFormat, long long value, decaf::io::DataOutputStream* dataOut);
326
334 virtual long long looseUnmarshalLong(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
335
343 virtual std::vector<unsigned char> tightUnmarshalByteArray(decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
344
351 virtual std::vector<unsigned char> looseUnmarshalByteArray(decaf::io::DataInputStream* dataIn);
352
362 virtual std::vector<unsigned char> tightUnmarshalConstByteArray(decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs, int size);
363
372 virtual std::vector<unsigned char> looseUnmarshalConstByteArray(decaf::io::DataInputStream* dataIn, int size);
373
383
393
403
412
421
432 template<typename T>
433 int tightMarshalObjectArray1(OpenWireFormat* wireFormat, std::vector<T> objects, utils::BooleanStream* bs) {
434
435 try {
436 if (!objects.empty()) {
437 int rc = 0;
438 bs->writeBoolean(true);
439 rc += 2;
440 for (std::size_t i = 0; i < objects.size(); ++i) {
441 rc += tightMarshalNestedObject1(wireFormat, objects[i].get(), bs);
442 }
443 return rc;
444
445 } else {
446 bs->writeBoolean(false);
447 return 0;
448 }
449 }
453 }
454
465 template<typename T>
466 void tightMarshalObjectArray2(OpenWireFormat* wireFormat, std::vector<T> objects, decaf::io::DataOutputStream* dataOut, utils::BooleanStream* bs) {
467
468 try {
469
470 if (bs->readBoolean()) {
471
472 dataOut->writeShort((short) objects.size());
473 for (std::size_t i = 0; i < objects.size(); ++i) {
474 tightMarshalNestedObject2(wireFormat, objects[i].get(), dataOut, bs);
475 }
476 }
477 }
481 }
482
492 template<typename T>
493 void looseMarshalObjectArray(OpenWireFormat* wireFormat, std::vector<T> objects, decaf::io::DataOutputStream* dataOut) {
494
495 try {
496
497 dataOut->writeBoolean(!objects.empty());
498 if (!objects.empty()) {
499
500 dataOut->writeShort((short) objects.size());
501 for (std::size_t i = 0; i < objects.size(); ++i) {
502 looseMarshalNestedObject(wireFormat, objects[i].get(), dataOut);
503 }
504 }
505 }
509 }
510
511 protected:
512
519 virtual std::string readAsciiString(decaf::io::DataInputStream* dataIn);
520
521 };
522
523}}}}
524
525#endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_*/
#define AMQ_CATCH_RETHROW(type)
Macro for catching and re-throwing an exception of a given type.
Definition ExceptionDefines.h:26
#define AMQ_CATCHALL_THROW(type)
A catch-all that throws a known exception.
Definition ExceptionDefines.h:49
#define AMQ_CATCH_EXCEPTION_CONVERT(sourceType, targetType)
Macro for catching an exception of one type and then re-throwing as another type.
Definition ExceptionDefines.h:38
#define AMQCPP_API
Definition Config.h:30
Definition DataStructure.h:27
Definition MessageId.h:49
Definition ProducerId.h:48
Definition TransactionId.h:47
Base class for all Marshallers that marshal DataStructures to and from the wire using the OpenWire pr...
Definition BaseDataStreamMarshaller.h:39
virtual int tightMarshal1(OpenWireFormat *format AMQCPP_UNUSED, commands::DataStructure *command AMQCPP_UNUSED, utils::BooleanStream *bs AMQCPP_UNUSED)
Tight Marhsal to the given stream.
Definition BaseDataStreamMarshaller.h:56
virtual void tightUnmarshal(OpenWireFormat *format AMQCPP_UNUSED, commands::DataStructure *command AMQCPP_UNUSED, decaf::io::DataInputStream *dis AMQCPP_UNUSED, utils::BooleanStream *bs AMQCPP_UNUSED)
Tight Un-Marshal to the given stream.
Definition BaseDataStreamMarshaller.h:81
virtual int tightMarshalString1(const std::string &value, utils::BooleanStream *bs)
Tight Marshals the String to a Booleans Stream Object, returns the marshaled size.
int tightMarshalObjectArray1(OpenWireFormat *wireFormat, std::vector< T > objects, utils::BooleanStream *bs)
Tightly Marshal an array of DataStructure objects to the provided boolean stream, and return the size...
Definition BaseDataStreamMarshaller.h:433
virtual commands::DataStructure * looseUnmarshalNestedObject(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn)
Loose Unmarshal the nested object.
virtual std::string readAsciiString(decaf::io::DataInputStream *dataIn)
Given an DataInputStream read a know ASCII formatted string from the input and return that string.
virtual long long tightUnmarshalLong(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs)
Tight marshal the long long type.
virtual int tightMarshalLong1(OpenWireFormat *wireFormat, long long value, utils::BooleanStream *bs)
Tightly marshal the long long to the BooleanStream passed.
virtual commands::DataStructure * looseUnmarshalBrokerError(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn)
Loose Unarshal the Error object.
virtual int tightMarshalNestedObject1(OpenWireFormat *wireFormat, commands::DataStructure *object, utils::BooleanStream *bs)
Tightly marshals the passed DataStructure based object to the passed BooleanStream returning the size...
static std::string toString(const commands::MessageId *id)
Converts the object to a String.
virtual std::string looseUnmarshalString(decaf::io::DataInputStream *dataIn)
Loose Un-Marshal the String to the DataOuputStream passed.
virtual std::vector< unsigned char > looseUnmarshalByteArray(decaf::io::DataInputStream *dataIn)
Loose Unmarshal an array of char.
virtual std::string tightUnmarshalString(decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs)
Performs Tight Unmarshaling of String Objects.
void tightMarshalObjectArray2(OpenWireFormat *wireFormat, std::vector< T > objects, decaf::io::DataOutputStream *dataOut, utils::BooleanStream *bs)
Tightly Marshal an array of DataStructure objects to the provided boolean stream and data output stre...
Definition BaseDataStreamMarshaller.h:466
static std::string toString(const commands::TransactionId *txnId)
Converts the given transaction ID into a String.
virtual void tightMarshalLong2(OpenWireFormat *wireFormat, long long value, decaf::io::DataOutputStream *dataOut, utils::BooleanStream *bs)
Tightly marshal the long long to the Streams passed.
virtual int tightMarshalBrokerError1(OpenWireFormat *wireFormat, commands::DataStructure *data, utils::BooleanStream *bs)
Tight Marshal the Error object.
virtual void tightMarshalBrokerError2(OpenWireFormat *wireFormat, commands::DataStructure *data, decaf::io::DataOutputStream *dataOut, utils::BooleanStream *bs)
Tight Marshal the Error object.
virtual int tightMarshalCachedObject1(OpenWireFormat *wireFormat, commands::DataStructure *data, utils::BooleanStream *bs)
Tightly marshals the passed DataStructure based object to the passed BooleanStream returning the size...
virtual void looseMarshalBrokerError(OpenWireFormat *wireFormat, commands::DataStructure *data, decaf::io::DataOutputStream *dataOut)
Tight Marshal the Error object.
virtual commands::DataStructure * tightUnmarshalNestedObject(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs)
Tight Unmarshal the nested object.
virtual commands::DataStructure * looseUnmarshalCachedObject(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn)
Loose Unmarshal the cached object.
virtual commands::DataStructure * tightUnmarshalCachedObject(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs)
Tight Unmarshal the cached object.
virtual void looseMarshalLong(OpenWireFormat *wireFormat, long long value, decaf::io::DataOutputStream *dataOut)
Tightly marshal the long long to the BooleanStream passed.
virtual ~BaseDataStreamMarshaller()
Definition BaseDataStreamMarshaller.h:47
virtual void looseMarshal(OpenWireFormat *format AMQCPP_UNUSED, commands::DataStructure *command AMQCPP_UNUSED, decaf::io::DataOutputStream *ds AMQCPP_UNUSED)
Tight Marshal to the given stream.
Definition BaseDataStreamMarshaller.h:93
virtual void tightMarshalString2(const std::string &value, decaf::io::DataOutputStream *dataOut, utils::BooleanStream *bs)
Tight Marshals the passed string to the streams passed.
virtual commands::DataStructure * tightUnmarshalBrokerError(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs)
Tight Unarshall the Error object.
virtual void looseMarshalString(const std::string value, decaf::io::DataOutputStream *dataOut)
Loose Marshal the String to the DataOuputStream passed.
virtual void tightMarshal2(OpenWireFormat *format AMQCPP_UNUSED, commands::DataStructure *command AMQCPP_UNUSED, decaf::io::DataOutputStream *ds AMQCPP_UNUSED, utils::BooleanStream *bs AMQCPP_UNUSED)
Tight Marshal to the given stream.
Definition BaseDataStreamMarshaller.h:68
virtual void looseMarshalCachedObject(OpenWireFormat *wireFormat, commands::DataStructure *data, decaf::io::DataOutputStream *dataOut)
Loosely marshals the passed DataStructure based object to the passed stream returning nothing.
virtual void tightMarshalCachedObject2(OpenWireFormat *wireFormat, commands::DataStructure *data, decaf::io::DataOutputStream *dataOut, utils::BooleanStream *bs)
Tightly marshals the passed DataStructure based object to the passed streams returning nothing.
void looseMarshalObjectArray(OpenWireFormat *wireFormat, std::vector< T > objects, decaf::io::DataOutputStream *dataOut)
Loosely Marshal an array of DataStructure objects to the provided boolean stream and data output stre...
Definition BaseDataStreamMarshaller.h:493
virtual std::vector< unsigned char > tightUnmarshalByteArray(decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs)
Tight Unmarshal an array of char.
static std::string toString(const commands::ProducerId *id)
Converts the object to a String.
virtual void tightMarshalNestedObject2(OpenWireFormat *wireFormat, commands::DataStructure *object, decaf::io::DataOutputStream *dataOut, utils::BooleanStream *bs)
Tightly marshals the passed DataStructure based object to the passed streams returning nothing.
virtual void looseUnmarshal(OpenWireFormat *format AMQCPP_UNUSED, commands::DataStructure *command AMQCPP_UNUSED, decaf::io::DataInputStream *dis AMQCPP_UNUSED)
Loose Un-Marshal to the given stream.
Definition BaseDataStreamMarshaller.h:104
virtual std::vector< unsigned char > tightUnmarshalConstByteArray(decaf::io::DataInputStream *dataIn, utils::BooleanStream *bs, int size)
Tight Unmarshal a fixed size array from that data input stream and return an stl vector of char as th...
static std::string toHexFromBytes(const std::vector< unsigned char > &data)
given an array of bytes, convert that array to a Hexidecimal coded string that represents that data.
virtual std::vector< unsigned char > looseUnmarshalConstByteArray(decaf::io::DataInputStream *dataIn, int size)
Tight Unmarshal a fixed size array from that data input stream and return an stl vector of char as th...
virtual long long looseUnmarshalLong(OpenWireFormat *wireFormat, decaf::io::DataInputStream *dataIn)
Loose marshal the long long type.
virtual void looseMarshalNestedObject(OpenWireFormat *wireFormat, commands::DataStructure *object, decaf::io::DataOutputStream *dataOut)
Loose marshall the nested object.
Base class for all classes that marshal commands for Openwire.
Definition DataStreamMarshaller.h:37
Manages the writing and reading of boolean data streams to and from a data source such as a DataInput...
Definition BooleanStream.h:49
void writeBoolean(bool value)
Writes a Boolean value to the internal data buffer.
bool readBoolean()
Read a boolean data element from the internal data buffer.
The HexTable class maps hexidecimal strings to the value of an index into the table,...
Definition HexTable.h:37
A data input stream lets an application read primitive Java data types from an underlying input strea...
Definition DataInputStream.h:46
A data output stream lets an application write primitive Java data types to an output stream in a por...
Definition DataOutputStream.h:34
virtual void writeShort(short value)
virtual void writeBoolean(bool value)
Definition IOException.h:28
Definition Exception.h:38
Definition BaseDataStreamMarshaller.h:31
Definition BaseDataStreamMarshaller.h:30
Definition BaseDataStructure.h:28
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition CachedConsumer.h:24