Hyper API for C++ 0.0.20746
Hyper client library for C++ applications
Loading...
Searching...
No Matches
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
15namespace hyperapi {
16
20struct 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
70namespace std {
72template <>
73struct 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
The primary namespace of the Hyper API for C++.
Definition ByteSpan.hpp:15
An arbitrarily-sized binary value.
Definition ByteSpan.hpp:20
friend bool operator!=(const ByteSpan &a, const ByteSpan &b) noexcept
Not equal operator.
Definition ByteSpan.hpp:43
friend bool operator>(const ByteSpan &lhs, const ByteSpan &rhs) noexcept
Greater operator.
const uint8_t * data
The start of the binary data.
Definition ByteSpan.hpp:22
friend bool operator<(const ByteSpan &a, const ByteSpan &b) noexcept
Less than operator.
Definition ByteSpan.hpp:47
std::string toString() const
Returns a string representation of the binary data.
friend bool operator==(const ByteSpan &lhs, const ByteSpan &rhs) noexcept
Equality operator.
friend bool operator>=(const ByteSpan &a, const ByteSpan &b) noexcept
Greater or equal operator.
Definition ByteSpan.hpp:55
ByteSpan(const std::vector< uint8_t > &bytes) noexcept
Constructor.
Definition ByteSpan.hpp:30
friend bool operator<=(const ByteSpan &a, const ByteSpan &b) noexcept
Less than or equal operator.
Definition ByteSpan.hpp:51
size_t size
The size of the data.
Definition ByteSpan.hpp:24
ByteSpan(const uint8_t *data, size_t size) noexcept
Constructor.
Definition ByteSpan.hpp:27
friend std::ostream & operator<<(std::ostream &os, const ByteSpan &obj)
Stream output operator.
Definition ByteSpan.hpp:66
size_t operator()(const hyperapi::ByteSpan &) const noexcept
Calculates the hash value of the given byte span.