diff options
| author | Gordon Sim <gsim@apache.org> | 2013-08-13 15:06:42 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2013-08-13 15:06:42 +0000 |
| commit | 592e3317e4277cc469b0bdc29f4e809c1b639d07 (patch) | |
| tree | 2f4aef48e274ace695d87c86efdfbc4fc4cee36a /cpp/src/qpid/messaging/MessageImpl.cpp | |
| parent | 57f7ef0a6cf49ba5275360b8e114b27034ee1548 (diff) | |
| download | qpid-python-592e3317e4277cc469b0bdc29f4e809c1b639d07.tar.gz | |
QPID-5040: support for sending and receiving messages with AmqpValue sections
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1513536 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/messaging/MessageImpl.cpp')
| -rw-r--r-- | cpp/src/qpid/messaging/MessageImpl.cpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/cpp/src/qpid/messaging/MessageImpl.cpp b/cpp/src/qpid/messaging/MessageImpl.cpp index fc9bc5dfa1..7b5854745e 100644 --- a/cpp/src/qpid/messaging/MessageImpl.cpp +++ b/cpp/src/qpid/messaging/MessageImpl.cpp @@ -7,9 +7,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -30,19 +30,21 @@ const std::string EMPTY_STRING = ""; using namespace qpid::types; -MessageImpl::MessageImpl(const std::string& c) : +MessageImpl::MessageImpl(const std::string& c) : priority(0), ttl(0), durable(false), redelivered(false), bytes(c), + contentDecoded(false), internalId(0) {} -MessageImpl::MessageImpl(const char* chars, size_t count) : +MessageImpl::MessageImpl(const char* chars, size_t count) : priority(0), ttl(0), durable (false), redelivered(false), bytes(chars, count), + contentDecoded(false), internalId(0) {} void MessageImpl::setReplyTo(const Address& d) @@ -167,21 +169,35 @@ void MessageImpl::setBytes(const char* chars, size_t count) bytes.assign(chars, count); updated(); } -void MessageImpl::appendBytes(const char* chars, size_t count) -{ - bytes.append(chars, count); - updated(); -} const std::string& MessageImpl::getBytes() const { - if (!bytes.size() && encoded) encoded->getBody(bytes); - return bytes; + if (encoded && !contentDecoded) { + encoded->getBody(bytes, content); + contentDecoded = true; + } + if (bytes.empty() && !content.isVoid()) return content.getString(); + else return bytes; } std::string& MessageImpl::getBytes() { - if (!bytes.size() && encoded) encoded->getBody(bytes); updated();//have to assume body may be edited, invalidating our message - return bytes; + if (bytes.empty() && !content.isVoid()) return content.getString(); + else return bytes; +} + +qpid::types::Variant& MessageImpl::getContent() +{ + updated();//have to assume content may be edited, invalidating our message + return content; +} + +const qpid::types::Variant& MessageImpl::getContent() const +{ + if (encoded && !contentDecoded) { + encoded->getBody(bytes, content); + contentDecoded = true; + } + return content; } void MessageImpl::setInternalId(qpid::framing::SequenceNumber i) { internalId = i; } @@ -197,7 +213,10 @@ void MessageImpl::updated() if (!userId.size() && encoded) encoded->getUserId(userId); if (!correlationId.size() && encoded) encoded->getCorrelationId(correlationId); if (!headers.size() && encoded) encoded->populate(headers); - if (!bytes.size() && encoded) encoded->getBody(bytes); + if (encoded && !contentDecoded) { + encoded->getBody(bytes, content); + contentDecoded = true; + } encoded.reset(); } @@ -210,5 +229,4 @@ const MessageImpl& MessageImplAccess::get(const Message& msg) { return *msg.impl; } - }} // namespace qpid::messaging |
