16#ifndef LIEF_SPAN_STREAM_H
17#define LIEF_SPAN_STREAM_H
34 using BinaryStream::p;
35 using BinaryStream::end;
36 using BinaryStream::start;
38 static result<SpanStream>
from_vector(
const std::vector<uint8_t>& data) {
39 return SpanStream(data);
43 static result<SpanStream>
from_array(
const std::array<uint8_t, N>& data) {
44 return SpanStream(data.data(), N);
48 SpanStream(data.data(), data.size())
52 SpanStream(data.data(), data.size())
56 BinaryStream(BinaryStream::STREAM_TYPE::SPAN),
61 SpanStream(data.data(), data.size())
64 std::unique_ptr<SpanStream>
clone()
const {
65 return std::make_unique<SpanStream>(*
this);
71 SpanStream&
operator=(
const SpanStream& other) =
default;
74 SpanStream&
operator=(SpanStream&& other)
noexcept =
default;
76 uint64_t
size()
const override {
80 const uint8_t*
p()
const override {
81 return data_.data() + this->pos();
84 const uint8_t*
start()
const override {
88 const uint8_t*
end()
const override {
89 return data_.data() + size();
93 return {data_.begin(), data_.end()};
96 result<SpanStream>
slice(
size_t offset,
size_t size)
const {
97 if (offset > data_.size() || (offset + size) > data_.size()) {
100 return data_.subspan(offset, size);
102 result<SpanStream>
slice(
size_t offset)
const {
103 if (offset > data_.size()) {
106 return data_.subspan(offset, data_.size() - offset);
111 static bool classof(
const BinaryStream& stream) {
112 return stream.
type() == BinaryStream::STREAM_TYPE::SPAN;
118 result<const void*> read_at(uint64_t offset, uint64_t size, uint64_t )
const override {
119 const uint64_t stream_size = this->size();
120 if (offset > stream_size || (offset + size) > stream_size) {
123 return data_.data() + offset;
125 span<const uint8_t> data_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
STREAM_TYPE type() const
Definition BinaryStream.hpp:53
Definition SpanStream.hpp:32
~SpanStream() override=default
std::unique_ptr< VectorStream > to_vector() const
SpanStream & operator=(SpanStream &&other) noexcept=default
SpanStream & operator=(const SpanStream &other)=default
SpanStream(const SpanStream &other)=default
const uint8_t * p() const override
Definition SpanStream.hpp:80
SpanStream(const uint8_t *p, size_t size)
Definition SpanStream.hpp:55
static bool classof(const BinaryStream &stream)
Definition SpanStream.hpp:111
std::unique_ptr< SpanStream > clone() const
Definition SpanStream.hpp:64
SpanStream(span< uint8_t > data)
Definition SpanStream.hpp:51
result< SpanStream > slice(size_t offset, size_t size) const
Definition SpanStream.hpp:96
static result< SpanStream > from_vector(const std::vector< uint8_t > &data)
Definition SpanStream.hpp:38
static result< SpanStream > from_array(const std::array< uint8_t, N > &data)
Definition SpanStream.hpp:43
const uint8_t * start() const override
Definition SpanStream.hpp:84
SpanStream(const std::vector< uint8_t > &data)
Definition SpanStream.hpp:60
SpanStream(SpanStream &&other) noexcept=default
const uint8_t * end() const override
Definition SpanStream.hpp:88
result< SpanStream > slice(size_t offset) const
Definition SpanStream.hpp:102
uint64_t size() const override
Definition SpanStream.hpp:76
std::vector< uint8_t > content() const
Definition SpanStream.hpp:92
SpanStream(span< const uint8_t > data)
Definition SpanStream.hpp:47
Definition VectorStream.hpp:29
@ read_out_of_bound
Definition errors.hpp:32
@ read_error
Definition errors.hpp:24
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create an standard error code from lief_errors.
Definition errors.hpp:52
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41