24#include "rawspeedconfig.h"
65 ThrowIOE(
"Out of bounds access in ByteStream");
73 if (size_ && nmemb > std::numeric_limits<size_type>::max() / size_)
74 ThrowIOE(
"Integer overflow when calculating stream length");
75 return check(nmemb * size_);
96 const uint8_t* ret =
peekData(count);
115 if (size_ && nmemb > std::numeric_limits<size_type>::max() / size_)
116 ThrowIOE(
"Integer overflow when calculating stream length");
125 if (size_ && nmemb > std::numeric_limits<size_type>::max() / size_)
126 ThrowIOE(
"Integer overflow when calculating stream length");
141 assert(tmp.getSize() == pattern.size());
142 return std::equal(tmp.begin(), tmp.end(), pattern.begin());
145 [[nodiscard]]
bool hasPrefix(std::string_view prefix)
const {
152 pos += prefix.size();
159 template <
typename T>
T get() {
165 template <
typename T,
int N> std::array<T, N>
getArray() {
166 std::array<T, N> out;
168 std::generate(out.begin(), out.end(), [&bs]() { return bs.get<T>(); });
173 template <
typename T> std::vector<T>
getVector(
int nElt) {
177 std::generate_n(std::back_inserter(out), nElt,
178 [&bs]() {
return bs.get<
T>(); });
201 const auto* termIter = std::find(tmp.
begin(), tmp.
end(),
'\0');
202 if (termIter == tmp.
end())
203 ThrowIOE(
"String is not null-terminated");
204 std::string_view::size_type strlen = std::distance(tmp.
begin(), termIter);
205 return {
reinterpret_cast<const char*
>(tmp.
begin()), strlen};
assert(dim.area() >=area)
Buffer getSubView(size_type offset, size_type size_) const
bool isValid(size_type offset, size_type count=1) const
const uint8_t * begin() const
const uint8_t * end() const
size_type RAWSPEED_READONLY getSize() const
void skipBytes(size_type nmemb, size_type size_)
ByteStream getStream(size_type nmemb, size_type size_)
ByteStream getSubStream(size_type offset) const
std::string_view peekString() const
size_type check(size_type bytes) const
size_type RAWSPEED_READONLY getRemainSize() const
std::array< T, N > getArray()
void setPosition(size_type newPos)
Buffer getBuffer(size_type size_)
const uint8_t * getData(size_type count)
ByteStream getSubStream(size_type offset, size_type size_) const
bool hasPrefix(std::string_view prefix) const
uint32_t peekU32(size_type i=0) const
ByteStream getStream(size_type size_)
std::string_view getString()
ByteStream(DataBuffer buffer)
ByteStream peekStream(size_type size_) const
ByteStream peekStream(size_type nmemb, size_type size_) const
uint8_t peekByte(size_type i=0) const
void skipBytes(size_type nbytes)
size_type check(size_type nmemb, size_type size_) const
const uint8_t * peekData(size_type count) const
T peek(size_type i=0) const
bool skipPrefix(std::string_view prefix)
Buffer peekBuffer(size_type size_) const
std::vector< T > getVector(int nElt)
size_type getPosition() const
bool hasPatternAt(std::string_view pattern, size_type relPos) const
Buffer peekRemainingBuffer() const
Endianness getByteOrder() const
T get(size_type offset, size_type index=0) const
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
static bool RegionIsPoisoned(const volatile void *addr, size_t size)