|
| 1 | +/*------------------------------------------------------------------------------ |
| 2 | + Copyright Butterfly Energy Systems 2014-2015. |
| 3 | + Distributed under the Boost Software License, Version 1.0. |
| 4 | + (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | + http://www.boost.org/LICENSE_1_0.txt) |
| 6 | +------------------------------------------------------------------------------*/ |
| 7 | + |
| 8 | +#ifndef CPPWAMP_BLOB_HPP |
| 9 | +#define CPPWAMP_BLOB_HPP |
| 10 | + |
| 11 | +//------------------------------------------------------------------------------ |
| 12 | +/** @file |
| 13 | + Contains the declaration of Variant and other closely related |
| 14 | + types/functions. */ |
| 15 | +//------------------------------------------------------------------------------ |
| 16 | + |
| 17 | +#include <cstdint> |
| 18 | +#include <initializer_list> |
| 19 | +#include <ostream> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +namespace wamp |
| 23 | +{ |
| 24 | + |
| 25 | +//------------------------------------------------------------------------------ |
| 26 | +/** Contains binary data as an array of bytes. */ |
| 27 | +//------------------------------------------------------------------------------ |
| 28 | +class Blob |
| 29 | +{ |
| 30 | +public: |
| 31 | + /// Array of bytes used to contain the binary data. |
| 32 | + using Data = std::vector<uint8_t>; |
| 33 | + |
| 34 | + /** Default constructor. */ |
| 35 | + Blob(); |
| 36 | + |
| 37 | + /** Constructor taking a vector of bytes. */ |
| 38 | + explicit Blob(Data data); |
| 39 | + |
| 40 | + /** Constructor taking an initializer list. */ |
| 41 | + explicit Blob(std::initializer_list<uint8_t> list); |
| 42 | + |
| 43 | + /** Obtains the blob's array of bytes. */ |
| 44 | + Data& data(); |
| 45 | + |
| 46 | + /** Obtains the blob's constant array of bytes. */ |
| 47 | + const Data& data() const; |
| 48 | + |
| 49 | + /** Equality comparison. */ |
| 50 | + bool operator==(const Blob& other) const; |
| 51 | + |
| 52 | + /** Inequality comparison. */ |
| 53 | + bool operator!=(const Blob& other) const; |
| 54 | + |
| 55 | + /** Less-than comparison. */ |
| 56 | + bool operator<(const Blob& other) const; |
| 57 | + |
| 58 | +private: |
| 59 | + std::vector<uint8_t> data_; |
| 60 | +}; |
| 61 | + |
| 62 | +//------------------------------------------------------------------------------ |
| 63 | +/** Outputs a Blob to the given output stream. |
| 64 | + @relates Blob */ |
| 65 | +//------------------------------------------------------------------------------ |
| 66 | +std::ostream& operator<<(std::ostream& out, const Blob& blob); |
| 67 | + |
| 68 | +} // namespace wamp |
| 69 | + |
| 70 | +#ifndef CPPWAMP_COMPILED_LIB |
| 71 | +#include "internal/blob.ipp" |
| 72 | +#endif |
| 73 | + |
| 74 | +#endif // CPPWAMP_BLOB_HPP |
0 commit comments