Binary reading stream, that is useful during binary deserialization.
More...
Definition at line 22 of file read_stream.hpp.
#include <read_stream.hpp>
|
| ReadStream (const void *buff, size_t size) |
|
| ReadStream (Slice< const uint8_t > slice) |
|
| ReadStream (const std::vector< uint8_t > &v) |
|
| ReadStream (const std::string &s) |
|
| ReadStream (ReadStream &&)=default |
|
ReadStream & | operator= (ReadStream &&)=default |
|
bool | read (size_t size, uint8_t *out, ValidationState &state) |
| Read type T of 'size' bytes. More...
|
|
std::vector< uint8_t > | assertRead (size_t size) |
|
bool | readSlice (size_t size, Slice< const uint8_t > &out, ValidationState &state) |
|
Slice< const uint8_t > | assertReadSlice (size_t size) |
|
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type> |
T | assertReadBE (size_t bytes=sizeof(T)) |
|
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type> |
bool | readBE (T &t, ValidationState &state, size_t bytes=sizeof(T)) |
|
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type> |
T | assertReadLE () |
|
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type> |
bool | readLE (T &t, ValidationState &state) |
|
uint32_t | getVersion () const noexcept |
|
void | setVersion (uint32_t version) noexcept |
|
size_t | position () const noexcept |
|
void | setPosition (const size_t &) noexcept |
|
size_t | remaining () const noexcept |
|
bool | hasMore (size_t nbytes) const noexcept |
|
void | reset () noexcept |
|
Slice< const uint8_t > | data () const |
|
Slice< const uint8_t > | remainingBytes () const |
|
◆ assertReadBE()
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
T altintegration::ReadStream::assertReadBE |
( |
size_t |
bytes = sizeof(T) | ) |
|
|
inline |
Definition at line 56 of file read_stream.hpp.
56 {
57 ValidationState state;
58 T t = 0;
59 bool result = readBE<T>(t, state, bytes);
60 VBK_ASSERT_MSG(result, "Can't readBE: %s", state.toString());
61 return t;
62 }
◆ assertReadLE()
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
T altintegration::ReadStream::assertReadLE |
( |
| ) |
|
|
inline |
Definition at line 86 of file read_stream.hpp.
86 {
87 ValidationState state;
88 T t = 0;
89 bool result = readLE<T>(t, state);
90 VBK_ASSERT_MSG(result, "Can't readLE: %s", state.toString());
91 return t;
92 }
◆ hasMore()
bool altintegration::ReadStream::hasMore |
( |
size_t |
nbytes | ) |
const |
|
inlinenoexcept |
◆ read()
bool altintegration::ReadStream::read |
( |
size_t |
size, |
|
|
uint8_t * |
out, |
|
|
ValidationState & |
state |
|
) |
| |
- Parameters
-
size | bytes to be read |
out | preallocated array of at least size |
state | will return error description here |
- Returns
- true if read is OK, false otherwise
◆ readBE()
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
bool altintegration::ReadStream::readBE |
( |
T & |
t, |
|
|
ValidationState & |
state, |
|
|
size_t |
bytes = sizeof(T) |
|
) |
| |
|
inline |
Definition at line 68 of file read_stream.hpp.
68 {
69 if (!hasMore(bytes)) {
70 return state.Invalid(
71 "readbe-underflow",
72 format("Tried to read {} bytes from stream, but it has {} bytes",
73 bytes,
74 remaining()));
75 }
76 t = 0;
77 for (size_t i = 0, shift = (bytes - 1) * 8; i < bytes; i++, shift -= 8) {
78 t += static_cast<T>((static_cast<T>(m_Buffer[m_Pos++])) << shift);
79 }
80 return true;
81 }
◆ readLE()
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
Definition at line 98 of file read_stream.hpp.
98 {
99 if (!hasMore(sizeof(T))) {
100 return state.Invalid(
101 "readle-underflow",
102 format("Tried to read {} bytes from stream, but it has {} bytes",
103 sizeof(T),
104 remaining()));
105 }
106
107 t = 0;
108 for (size_t i = 0, shift = 0; i < sizeof(T); i++, shift += 8) {
109 t += static_cast<T>((static_cast<T>(m_Buffer[m_Pos++])) << shift);
110 }
111 return true;
112 }
◆ remaining()
size_t altintegration::ReadStream::remaining |
( |
| ) |
const |
|
inlinenoexcept |
The documentation for this struct was generated from the following file: