Merge pull request #345 from tarhan/master

Added Void field type
This commit is contained in:
Emiel Bruijntjes 2020-10-14 21:02:12 +02:00 committed by GitHub
commit 2e49fd1220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 0 deletions

View File

@ -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"

View File

@ -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; }
};
/**

View File

@ -19,6 +19,7 @@
#include "booleanset.h"
#include "decimalfield.h"
#include "numericfield.h"
#include "voidfield.h"
/**
* Set up namespace

View File

@ -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

114
include/amqpcpp/voidfield.h Normal file
View File

@ -0,0 +1,114 @@
/**
* Void field type for AMQP
*
* @copyright
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <memory>
#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<Field> clone() const override
{
// create a new copy of ourselves and return it
return std::make_shared<VoidField>();
}
/**
* 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
*/
}

View File

@ -41,6 +41,7 @@ Field *Field::decode(InBuffer &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;
}
}

View File

@ -53,6 +53,7 @@
#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"