Hyper API for C++  0.0.15888
Hyper client library for C++ applications
ByteSpan.hpp
Go to the documentation of this file.
1 
5 #ifndef TABLEAU_HYPER_BYTESPAN_HPP
6 #define TABLEAU_HYPER_BYTESPAN_HPP
7 
8 #include <cstddef>
9 #include <cstdint>
10 #include <ostream>
11 #include <sstream>
12 #include <string>
13 #include <vector>
14 
15 namespace hyperapi {
16 
20 struct ByteSpan {
22  const uint8_t* data;
24  size_t size;
25 
27  ByteSpan(const uint8_t* data, size_t size) noexcept : data(data), size(size) {}
28 
30  ByteSpan(const std::vector<uint8_t>& bytes) noexcept : data(bytes.data()), size(bytes.size()) {}
31 
35  friend bool operator==(const ByteSpan& lhs, const ByteSpan& rhs) noexcept;
39  friend bool operator>(const ByteSpan& lhs, const ByteSpan& rhs) noexcept;
43  friend bool operator!=(const ByteSpan& a, const ByteSpan& b) noexcept { return !(a == b); }
47  friend bool operator<(const ByteSpan& a, const ByteSpan& b) noexcept { return (b > a); }
51  friend bool operator<=(const ByteSpan& a, const ByteSpan& b) noexcept { return !(a > b); }
55  friend bool operator>=(const ByteSpan& a, const ByteSpan& b) noexcept { return !(a < b); }
56 
63  std::string toString() const;
64 
66  friend std::ostream& operator<<(std::ostream& os, const ByteSpan& obj) { return os << obj.toString(); }
67 };
68 }
69 
70 namespace std {
72 template <>
73 struct hash<hyperapi::ByteSpan> {
75  size_t operator()(const hyperapi::ByteSpan&) const noexcept;
76 };
77 }
78 
79 #include <hyperapi/impl/ByteSpan.impl.hpp>
80 
81 #endif
hyperapi::ByteSpan::data
const uint8_t * data
The start of the binary data.
Definition: ByteSpan.hpp:22
hyperapi::ByteSpan::size
size_t size
The size of the data.
Definition: ByteSpan.hpp:24
hyperapi::ByteSpan::operator==
friend bool operator==(const ByteSpan &lhs, const ByteSpan &rhs) noexcept
Equality operator.
hyperapi::ByteSpan::operator>=
friend bool operator>=(const ByteSpan &a, const ByteSpan &b) noexcept
Greater or equal operator.
Definition: ByteSpan.hpp:55
hyperapi::ByteSpan::ByteSpan
ByteSpan(const std::vector< uint8_t > &bytes) noexcept
Constructor.
Definition: ByteSpan.hpp:30
hyperapi::ByteSpan::toString
std::string toString() const
Returns a string representation of the binary data.
hyperapi::ByteSpan
An arbitrarily-sized binary value.
Definition: ByteSpan.hpp:20
hyperapi::ByteSpan::operator>
friend bool operator>(const ByteSpan &lhs, const ByteSpan &rhs) noexcept
Greater operator.
hyperapi::ByteSpan::operator<=
friend bool operator<=(const ByteSpan &a, const ByteSpan &b) noexcept
Less than or equal operator.
Definition: ByteSpan.hpp:51
hyperapi::ByteSpan::ByteSpan
ByteSpan(const uint8_t *data, size_t size) noexcept
Constructor.
Definition: ByteSpan.hpp:27
hyperapi::ByteSpan::operator<
friend bool operator<(const ByteSpan &a, const ByteSpan &b) noexcept
Less than operator.
Definition: ByteSpan.hpp:47
hyperapi
The primary namespace of the Hyper API for C++.
Definition: ByteSpan.hpp:15
hyperapi::ByteSpan::operator!=
friend bool operator!=(const ByteSpan &a, const ByteSpan &b) noexcept
Not equal operator.
Definition: ByteSpan.hpp:43
hyperapi::ByteSpan::operator<<
friend std::ostream & operator<<(std::ostream &os, const ByteSpan &obj)
Stream output operator.
Definition: ByteSpan.hpp:66