From cdcdaf79a3a718e85e2be0ee579dddd7dacff146 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 27 Mar 2023 14:12:37 +0200 Subject: [PATCH] added more constructors to AMQP::Envelope --- include/amqpcpp/envelope.h | 11 +++++++++++ include/amqpcpp/metadata.h | 8 +++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/amqpcpp/envelope.h b/include/amqpcpp/envelope.h index deaf1974..551d2d95 100644 --- a/include/amqpcpp/envelope.h +++ b/include/amqpcpp/envelope.h @@ -53,7 +53,18 @@ class Envelope : public MetaData * @param size */ Envelope(const char *body, uint64_t size) : MetaData(), _body(body), _bodySize(size) {} + Envelope(const std::string_view &body) : Envelope(body.data(), body.size()) {} Envelope(const char *body) : Envelope(body, strlen(body)) {} + + /** + * Constructor that preserves meta-data, but installs different body + * @param metadata + * @param body + * @param size + */ + Envelope(const MetaData &metadata, const char *body, uint64_t size) : MetaData(metadata), _body(body), _bodySize(size) {} + Envelope(const MetaData &metadata, const std::string_view &body) : Envelope(metadata, body.data(), body.size()) {} + Envelope(const MetaData &metadata, const char *body) : Envelope(metadata, body, strlen(body)) {} /** * Read envelope frmo an input-buffer diff --git a/include/amqpcpp/metadata.h b/include/amqpcpp/metadata.h index 663e2a15..4a92d532 100644 --- a/include/amqpcpp/metadata.h +++ b/include/amqpcpp/metadata.h @@ -4,7 +4,7 @@ * With every published message a set of meta data is passed to. This class * holds all that meta data. * - * @copyright 2014 - 2017 Copernica BV + * @copyright 2014 - 2023 Copernica BV */ /** @@ -127,14 +127,12 @@ class MetaData ShortString _clusterID; +public: /** - * Protected constructor to ensure that this class can only be constructed - * in a derived class + * Constructor for empty meta data. Can be useful when user-space wants to preserve all meta-data */ MetaData() {} - -public: /** * Read incoming frame * @param frame