From 1c4917bead3c177d2a9f4dfc6fa143395cec6b43 Mon Sep 17 00:00:00 2001 From: Dmitriy Lekomtsev Date: Wed, 29 Jul 2020 16:21:28 +0300 Subject: [PATCH 1/3] Added Void field type --- include/amqpcpp.h | 1 + include/amqpcpp/field.h | 1 + include/amqpcpp/voidfield.h | 124 ++++++++++++++++++++++++++++++++++++ src/field.cpp | 1 + src/includes.h | 1 + 5 files changed, 128 insertions(+) create mode 100644 include/amqpcpp/voidfield.h diff --git a/include/amqpcpp.h b/include/amqpcpp.h index 3c5de03..469292d 100644 --- a/include/amqpcpp.h +++ b/include/amqpcpp.h @@ -55,6 +55,7 @@ #include "amqpcpp/fieldproxy.h" #include "amqpcpp/table.h" #include "amqpcpp/array.h" +#include "amqpcpp/voidfield.h" // envelope for publishing and consuming #include "amqpcpp/metadata.h" diff --git a/include/amqpcpp/field.h b/include/amqpcpp/field.h index b4d8ed9..be27069 100644 --- a/include/amqpcpp/field.h +++ b/include/amqpcpp/field.h @@ -112,6 +112,7 @@ public: virtual bool isTable() const { return false; } virtual bool isBoolean() const { return false; } virtual bool isString() const { return false; } + virtual bool isVoid() const { return false; } }; /** diff --git a/include/amqpcpp/voidfield.h b/include/amqpcpp/voidfield.h new file mode 100644 index 0000000..11f149a --- /dev/null +++ b/include/amqpcpp/voidfield.h @@ -0,0 +1,124 @@ +/** + * Void field type for AMQP + * + * @copyright + */ + +/** + * Include guard + */ +#pragma once + +/** + * Dependencies + */ +#include +#include "receivedframe.h" +#include "outbuffer.h" +#include "field.h" + +/** + * Set up namespace + */ +namespace AMQP +{ +class VoidField : public Field +{ +private: + /** + * Field have no value + */ + +public: + /** + * Default constructor + */ + VoidField() {} + + /** + * Parse based on incoming buffer + * @param frame + */ + VoidField(ReceivedFrame &frame) + { + + } + + /** + * Destructor + */ + virtual ~VoidField() {} + + /** + * Create a new instance of this object + * @return Field* + */ + virtual std::shared_ptr clone() const override + { + // create a new copy of ourselves and return it + return std::make_shared(); + } + + /** + * We are an integer field + * + * @return true, because we are an integer + */ + bool isInteger() const override + { + return false; + } + + /** + * Get the size this field will take when + * encoded in the AMQP wire-frame format + * @return size_t + */ + virtual size_t size() const override + { + // numeric types have no extra storage requirements + return 0; + } + + /** + * Write encoded payload to the given buffer. + * @param buffer OutBuffer to write to + */ + virtual void fill(OutBuffer &buffer) const override + { + } + + /** + * Get the type ID that is used to identify this type of + * field in a field table + */ + virtual char typeID() const override + { + return 'V'; + } + + /** + * Output the object to a stream + * @param std::ostream + */ + virtual void output(std::ostream &stream) const override + { + // show + stream << "void()"; + } + + /** + * We are an void field + * + * @return true, because we are an void + */ + bool isVoid() const override + { + return true; + } +}; + +/** + * end namespace + */ +} diff --git a/src/field.cpp b/src/field.cpp index 2655bb2..982f02e 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -41,6 +41,7 @@ Field *Field::decode(ReceivedFrame &frame) case 'A': return new Array(frame); case 'T': return new Timestamp(frame); case 'F': return new Table(frame); + case 'V': return new VoidField(frame); default: return nullptr; } } diff --git a/src/includes.h b/src/includes.h index 2cc31bd..991521e 100644 --- a/src/includes.h +++ b/src/includes.h @@ -56,6 +56,7 @@ #include "amqpcpp/fieldproxy.h" #include "amqpcpp/table.h" #include "amqpcpp/array.h" +#include "amqpcpp/voidfield.h" // envelope for publishing and consuming #include "amqpcpp/metadata.h" From bc4b9aa163b3704bf503630ff1aa7877ed9e80f2 Mon Sep 17 00:00:00 2001 From: Dmitriy Lekomtsev Date: Wed, 29 Jul 2020 18:35:11 +0300 Subject: [PATCH 2/3] Added setting nullptr for Table's key --- include/amqpcpp/fieldproxy.h | 1 + include/amqpcpp/table.h | 1 + src/includes.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/amqpcpp/fieldproxy.h b/include/amqpcpp/fieldproxy.h index a122f76..91ab004 100644 --- a/include/amqpcpp/fieldproxy.h +++ b/include/amqpcpp/fieldproxy.h @@ -19,6 +19,7 @@ #include "booleanset.h" #include "decimalfield.h" #include "numericfield.h" +#include "voidfield.h" /** * Set up namespace diff --git a/include/amqpcpp/table.h b/include/amqpcpp/table.h index edc1e5f..ebc30e8 100644 --- a/include/amqpcpp/table.h +++ b/include/amqpcpp/table.h @@ -138,6 +138,7 @@ public: Table &set(const std::string &name, int64_t value) { return set(name, LongLong(value)); } Table &set(const std::string &name, const std::string &value) { return set(name, LongString(value)); } Table &set(const std::string &name, const char *value) { return set(name, LongString(std::string(value))); } + Table &set(const std::string &name, nullptr_t) { return set(name, VoidField()); } /** * Is a certain field set in the table diff --git a/src/includes.h b/src/includes.h index 991521e..ec90975 100644 --- a/src/includes.h +++ b/src/includes.h @@ -53,10 +53,10 @@ #include "amqpcpp/decimalfield.h" #include "amqpcpp/stringfield.h" #include "amqpcpp/booleanset.h" +#include "amqpcpp/voidfield.h" #include "amqpcpp/fieldproxy.h" #include "amqpcpp/table.h" #include "amqpcpp/array.h" -#include "amqpcpp/voidfield.h" // envelope for publishing and consuming #include "amqpcpp/metadata.h" From 6c87bcdcb88ec55420e446bdc9e985e83e3cdc19 Mon Sep 17 00:00:00 2001 From: Dmitriy Lekomtsev Date: Wed, 29 Jul 2020 19:07:44 +0300 Subject: [PATCH 3/3] Cleanup copy-pasted part --- include/amqpcpp/voidfield.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/amqpcpp/voidfield.h b/include/amqpcpp/voidfield.h index 11f149a..3a1a4d3 100644 --- a/include/amqpcpp/voidfield.h +++ b/include/amqpcpp/voidfield.h @@ -59,16 +59,6 @@ public: return std::make_shared(); } - /** - * We are an integer field - * - * @return true, because we are an integer - */ - bool isInteger() const override - { - return false; - } - /** * Get the size this field will take when * encoded in the AMQP wire-frame format