Zserio C++17 runtime library  0.5.0
Built for Zserio 2.17.0
Bytes.h
Go to the documentation of this file.
1 #ifndef ZSERIO_BYTES_H_INC
2 #define ZSERIO_BYTES_H_INC
3 
4 #include <algorithm>
5 #include <cstdint>
6 #include <string_view>
7 #include <vector>
8 
9 #include "zserio/BitSize.h"
10 #include "zserio/Span.h"
11 #include "zserio/Traits.h"
12 
13 namespace zserio
14 {
15 
19 template <typename ALLOC = std::allocator<uint8_t>>
20 using BasicBytes = std::vector<uint8_t, ALLOC>;
21 
26 
31 
32 template <typename ALLOC>
33 struct view_type<BasicBytes<ALLOC>>
34 {
35  using type = BytesView;
36 };
37 
38 inline bool operator==(const BytesView& lhs, const BytesView& rhs)
39 {
40  return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
41 }
42 
43 inline bool operator!=(const BytesView& lhs, const BytesView& rhs)
44 {
45  return !(lhs == rhs);
46 }
47 
48 inline bool operator<(const BytesView& lhs, const BytesView& rhs)
49 {
50  return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
51 }
52 
53 inline bool operator>(const BytesView& lhs, const BytesView& rhs)
54 {
55  return rhs < lhs;
56 }
57 
58 inline bool operator<=(const BytesView& lhs, const BytesView& rhs)
59 {
60  return !(rhs < lhs);
61 }
62 
63 inline bool operator>=(const BytesView& lhs, const BytesView& rhs)
64 {
65  return !(lhs < rhs);
66 }
67 
68 namespace detail
69 {
70 
71 void validate(BytesView stringValue, std::string_view fieldName);
72 BitSize bitSizeOf(BytesView bytesValue, BitSize bitPosition = 0);
73 BitSize initializeOffsets(BytesView bytesValue, BitSize bitPosition);
74 
75 } // namespace detail
76 
77 } // namespace zserio
78 
79 #endif // ZSERIO_BYTES_H_INC
constexpr iterator end() const noexcept
Definition: Span.h:210
constexpr iterator begin() const noexcept
Definition: Span.h:200
Span< const uint8_t > BytesView
Definition: Bytes.h:30
bool operator>(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
Definition: BitBuffer.h:525
bool operator==(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
Definition: BitBuffer.h:507
unsigned int BitSize
Definition: BitSize.h:8
std::vector< uint8_t, ALLOC > BasicBytes
Definition: Bytes.h:20
bool operator<(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
Definition: BitBuffer.h:519
BasicBytes<> Bytes
Definition: Bytes.h:25
bool operator<=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
Definition: BitBuffer.h:531
bool operator>=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
Definition: BitBuffer.h:537
bool operator!=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
Definition: BitBuffer.h:513