Hyper API for C++ 0.0.24081
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 <string>
12#include <vector>
13
14namespace hyperapi {
15
19struct ByteSpan {
21 const uint8_t* data;
23 size_t size;
24
26 ByteSpan(const uint8_t* data, size_t size) noexcept : data(data), size(size) {}
27
29 ByteSpan(const std::vector<uint8_t>& bytes) noexcept : data(bytes.data()), size(bytes.size()) {}
30
34 friend bool operator==(const ByteSpan& lhs, const ByteSpan& rhs) noexcept;
38 friend bool operator>(const ByteSpan& lhs, const ByteSpan& rhs) noexcept;
42 friend bool operator!=(const ByteSpan& a, const ByteSpan& b) noexcept { return !(a == b); }
46 friend bool operator<(const ByteSpan& a, const ByteSpan& b) noexcept { return (b > a); }
50 friend bool operator<=(const ByteSpan& a, const ByteSpan& b) noexcept { return !(a > b); }
54 friend bool operator>=(const ByteSpan& a, const ByteSpan& b) noexcept { return !(a < b); }
55
62 std::string toString() const;
63
65 friend std::ostream& operator<<(std::ostream& os, const ByteSpan& obj) { return os << obj.toString(); }
66};
67}
68
69namespace std {
71template <>
72struct hash<hyperapi::ByteSpan> {
74 size_t operator()(const hyperapi::ByteSpan&) const noexcept;
75};
76}
77
78#include <hyperapi/impl/ByteSpan.impl.hpp>
79
80#endif
The primary namespace of the Hyper API for C++.
Definition ByteSpan.hpp:14
An arbitrarily-sized binary value.
Definition ByteSpan.hpp:19
friend bool operator!=(const ByteSpan &a, const ByteSpan &b) noexcept
Not equal operator.
Definition ByteSpan.hpp:42
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:21
friend bool operator<(const ByteSpan &a, const ByteSpan &b) noexcept
Less than operator.
Definition ByteSpan.hpp:46
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:54
ByteSpan(const std::vector< uint8_t > &bytes) noexcept
Constructor.
Definition ByteSpan.hpp:29
friend bool operator<=(const ByteSpan &a, const ByteSpan &b) noexcept
Less than or equal operator.
Definition ByteSpan.hpp:50
size_t size
The size of the data.
Definition ByteSpan.hpp:23
ByteSpan(const uint8_t *data, size_t size) noexcept
Constructor.
Definition ByteSpan.hpp:26
friend std::ostream & operator<<(std::ostream &os, const ByteSpan &obj)
Stream output operator.
Definition ByteSpan.hpp:65
size_t operator()(const hyperapi::ByteSpan &) const noexcept
Calculates the hash value of the given byte span.