summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-01-18 19:22:40 +0000
committerGordon Sim <gsim@apache.org>2007-01-18 19:22:40 +0000
commit93bddfd4c9260f958eab861a8a43db55bb836690 (patch)
treef1c88f0db979fc8aa51f4ca10e1ee4ed4ce3b655 /cpp
parent5b6ca65abd333e0ea15790ec351bfb67a7013a5e (diff)
downloadqpid-python-93bddfd4c9260f958eab861a8a43db55bb836690.tar.gz
Initial implementation of AMQP content data type.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@497542 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r--cpp/lib/broker/BrokerAdapter.cpp5
-rw-r--r--cpp/lib/common/framing/AMQMethodBody.h1
-rw-r--r--cpp/lib/common/framing/FramingContent.cpp45
-rw-r--r--cpp/lib/common/framing/FramingContent.h21
-rw-r--r--cpp/tests/FramingTest.cpp24
5 files changed, 83 insertions, 13 deletions
diff --git a/cpp/lib/broker/BrokerAdapter.cpp b/cpp/lib/broker/BrokerAdapter.cpp
index 58062d4471..41a66b6727 100644
--- a/cpp/lib/broker/BrokerAdapter.cpp
+++ b/cpp/lib/broker/BrokerAdapter.cpp
@@ -491,13 +491,14 @@ BrokerAdapter::ServerOps::ChannelHandlerImpl::ok( const MethodContext& )
void
BrokerAdapter::ServerOps::ChannelHandlerImpl::ping( const MethodContext& )
{
- assert(0); // FIXME aconway 2007-01-04: 0-9 feature
+ connection.client->getChannel().ok(channel.getId());
+ connection.client->getChannel().pong(channel.getId());
}
void
BrokerAdapter::ServerOps::ChannelHandlerImpl::pong( const MethodContext& )
{
- assert(0); // FIXME aconway 2007-01-04: 0-9 feature
+ connection.client->getChannel().ok(channel.getId());
}
void
diff --git a/cpp/lib/common/framing/AMQMethodBody.h b/cpp/lib/common/framing/AMQMethodBody.h
index a38f580aa5..9f859046f8 100644
--- a/cpp/lib/common/framing/AMQMethodBody.h
+++ b/cpp/lib/common/framing/AMQMethodBody.h
@@ -26,6 +26,7 @@
#include <AMQBody.h>
#include <Buffer.h>
#include <AMQP_ServerOperations.h>
+#include <MethodContext.h>
namespace qpid {
namespace framing {
diff --git a/cpp/lib/common/framing/FramingContent.cpp b/cpp/lib/common/framing/FramingContent.cpp
index 70c56e1fdd..bf3399525e 100644
--- a/cpp/lib/common/framing/FramingContent.cpp
+++ b/cpp/lib/common/framing/FramingContent.cpp
@@ -22,26 +22,57 @@
#include "Buffer.h"
#include "FramingContent.h"
+#include <QpidError.h>
+#include <sstream>
namespace qpid {
namespace framing {
+Content::Content() : discriminator(0) {}
+
+Content::Content(u_int8_t _discriminator, const string& _value): discriminator(_discriminator), value(_value) {
+ validate();
+}
+
+void Content::validate() {
+ //validation:
+ if (discriminator == REFERENCE) {
+ if(value.empty()) {
+ //cannot have empty reference
+ THROW_QPID_ERROR(FRAMING_ERROR, "Reference cannot be empty");
+ }
+ }else if (discriminator != INLINE) {
+ //invalid discriminator
+ std::stringstream out;
+ out << "Invalid discriminator: " << discriminator;
+ THROW_QPID_ERROR(FRAMING_ERROR, out.str());
+ }
+}
+
Content::~Content() {}
-void Content::encode(Buffer&) const {
- assert(0); // FIXME aconway 2007-01-04: 0-9 feature
+void Content::encode(Buffer& buffer) const {
+ buffer.putOctet(discriminator);
+ buffer.putLongString(value);
}
-void Content::decode(Buffer&) {
- assert(0); // FIXME aconway 2007-01-04: 0-9 feature
+void Content::decode(Buffer& buffer) {
+ discriminator = buffer.getOctet();
+ buffer.getLongString(value);
+ validate();
}
size_t Content::size() const {
- assert(0); // FIXME aconway 2007-01-04: 0-9 feature
+ return 1 + 4 + value.size();
}
-std::ostream& operator<<(std::ostream&, const Content&) {
- assert(0); // FIXME aconway 2007-01-04: 0-9 feature
+std::ostream& operator<<(std::ostream& out, const Content& content) {
+ if (content.discriminator == REFERENCE) {
+ out << "{REF:" << content.value << "}";
+ } else if (content.discriminator == INLINE) {
+ out << "{INLINE:" << content.value.size() << " bytes}";
+ }
+ return out;
}
}} // namespace framing::qpid
diff --git a/cpp/lib/common/framing/FramingContent.h b/cpp/lib/common/framing/FramingContent.h
index 833e766f9a..0f4a4b8f64 100644
--- a/cpp/lib/common/framing/FramingContent.h
+++ b/cpp/lib/common/framing/FramingContent.h
@@ -6,19 +6,32 @@
namespace qpid {
namespace framing {
-/*
- * TODO: New Content class required for AMQP 0-9. This is a stub only.
+enum discriminator_types { INLINE = 0, REFERENCE = 1 };
+
+/**
+ * A representation of the AMQP 'content' data type (used for message
+ * bodies) which can hold inline data or a reference.
*/
class Content
{
- public:
+ u_int8_t discriminator;
+ string value;
+
+ void validate();
+
+ public:
+ Content();
+ Content(u_int8_t _discriminator, const string& _value);
~Content();
void encode(Buffer& buffer) const;
void decode(Buffer& buffer);
size_t size() const;
+ bool isInline() { return discriminator == INLINE; }
+ bool isReference() { return discriminator == REFERENCE; }
+ const string& getValue() { return value; }
- friend std::ostream& operator<<(std::ostream&, const Content&);
+ friend std::ostream& operator<<(std::ostream&, const Content&);
};
}} // namespace qpid::framing
diff --git a/cpp/tests/FramingTest.cpp b/cpp/tests/FramingTest.cpp
index 268963f7b8..b081b5822b 100644
--- a/cpp/tests/FramingTest.cpp
+++ b/cpp/tests/FramingTest.cpp
@@ -55,6 +55,8 @@ class FramingTest : public CppUnit::TestCase
CPPUNIT_TEST(testResponseBodyFrame);
CPPUNIT_TEST(testRequester);
CPPUNIT_TEST(testResponder);
+ CPPUNIT_TEST(testInlineContent);
+ CPPUNIT_TEST(testContentReference);
CPPUNIT_TEST_SUITE_END();
private:
@@ -175,6 +177,28 @@ class FramingTest : public CppUnit::TestCase
CPPUNIT_ASSERT(decoded);
}
+ void testInlineContent() {
+ Content content(INLINE, "MyData");
+ CPPUNIT_ASSERT(content.isInline());
+ content.encode(buffer);
+ buffer.flip();
+ Content recovered;
+ recovered.decode(buffer);
+ CPPUNIT_ASSERT(recovered.isInline());
+ CPPUNIT_ASSERT_EQUAL(content.getValue(), recovered.getValue());
+ }
+
+ void testContentReference() {
+ Content content(REFERENCE, "MyRef");
+ CPPUNIT_ASSERT(content.isReference());
+ content.encode(buffer);
+ buffer.flip();
+ Content recovered;
+ recovered.decode(buffer);
+ CPPUNIT_ASSERT(recovered.isReference());
+ CPPUNIT_ASSERT_EQUAL(content.getValue(), recovered.getValue());
+ }
+
void testRequester() {
Requester r;
AMQRequestBody::Data q;