activemq-cpp-3.8.2
BaseDataStreamMarshaller.h
Go to the documentation of this file.
1 
18 #ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_
19 #define _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_BASEDATASTREAMMARSHALLER_H_
20 
26 #include <activemq/util/Config.h>
27 
28 namespace activemq{
29 namespace wireformat{
30 namespace openwire{
31 namespace 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 
150  virtual commands::DataStructure* tightUnmarshalCachedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
151 
161  virtual int tightMarshalCachedObject1(OpenWireFormat* wireFormat, commands::DataStructure* data, utils::BooleanStream* bs);
162 
172  virtual void tightMarshalCachedObject2(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut,utils::BooleanStream* bs);
173 
182  virtual void looseMarshalCachedObject(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut);
183 
191  virtual commands::DataStructure* looseUnmarshalCachedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
192 
202  virtual int tightMarshalNestedObject1(OpenWireFormat* wireFormat, commands::DataStructure* object, utils::BooleanStream* bs);
203 
213  virtual void tightMarshalNestedObject2(OpenWireFormat* wireFormat, commands::DataStructure* object, decaf::io::DataOutputStream* dataOut,
215 
224  virtual commands::DataStructure* tightUnmarshalNestedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
225 
233  virtual commands::DataStructure* looseUnmarshalNestedObject(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
234 
242  virtual void looseMarshalNestedObject(OpenWireFormat* wireFormat, commands::DataStructure* object, decaf::io::DataOutputStream* dataOut);
243 
251  virtual std::string tightUnmarshalString(decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
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 
286  virtual std::string looseUnmarshalString(decaf::io::DataInputStream* dataIn);
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 
316  virtual long long tightUnmarshalLong(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
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 
382  virtual commands::DataStructure* tightUnmarshalBrokerError(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn, utils::BooleanStream* bs);
383 
392  virtual int tightMarshalBrokerError1(OpenWireFormat* wireFormat, commands::DataStructure* data, utils::BooleanStream* bs);
393 
402  virtual void tightMarshalBrokerError2(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut,utils::BooleanStream* bs);
403 
411  virtual commands::DataStructure* looseUnmarshalBrokerError(OpenWireFormat* wireFormat, decaf::io::DataInputStream* dataIn);
412 
420  virtual void looseMarshalBrokerError(OpenWireFormat* wireFormat, commands::DataStructure* data, decaf::io::DataOutputStream* dataOut);
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_*/
virtual void writeShort(short value)
Definition: ProducerId.h:48
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 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
Base class for all Marshallers that marshal DataStructures to and from the wire using the OpenWire pr...
Definition: BaseDataStreamMarshaller.h:39
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
#define AMQCPP_API
Definition: Config.h:30
virtual ~BaseDataStreamMarshaller()
Definition: BaseDataStreamMarshaller.h:47
Definition: OpenWireFormat.h:43
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
Definition: IOException.h:28
Manages the writing and reading of boolean data streams to and from a data source such as a DataInput...
Definition: BooleanStream.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
Definition: DataStructure.h:27
#define AMQ_CATCH_RETHROW(type)
Macro for catching and re-throwing an exception of a given type.
Definition: ExceptionDefines.h:26
A data output stream lets an application write primitive Java data types to an output stream in a por...
Definition: DataOutputStream.h:34
Definition: TransactionId.h:47
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
A data input stream lets an application read primitive Java data types from an underlying input strea...
Definition: DataInputStream.h:46
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
Definition: MessageId.h:49
void writeBoolean(bool value)
Writes a Boolean value to the internal data buffer.
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
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: CachedConsumer.h:24
Definition: Exception.h:38
Base class for all classes that marshal commands for Openwire.
Definition: DataStreamMarshaller.h:37
#define AMQ_CATCHALL_THROW(type)
A catch-all that throws a known exception.
Definition: ExceptionDefines.h:49
bool readBoolean()
Read a boolean data element from the internal data buffer.
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 void writeBoolean(bool value)
The HexTable class maps hexidecimal strings to the value of an index into the table, i.e.
Definition: HexTable.h:37