C/C++ API Reference
Loading...
Searching...
No Matches
reader.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#pragma once
16
17#include <cstring>
18#include <memory>
19#include <optional>
20#include <string_view>
21#include <variant>
22#include <vector>
23
24#include "pw_bytes/span.h"
25#include "pw_elf/internal/reader_impl.h"
26#include "pw_result/result.h"
27#include "pw_status/status.h"
28#include "pw_status/try.h"
29#include "pw_stream/stream.h"
30
32namespace pw::elf {
33
35
37class ElfReader {
38 public:
59
62 return std::visit([](auto&& impl) -> auto& { return impl.stream(); },
63 impl_);
64 }
65
83 StatusWithSize SeekToSection(std::string_view name) {
84 return std::visit([name](auto&& impl) { return impl.SeekToSection(name); },
85 impl_);
86 }
87
105
106 private:
107 internal::ElfReaderImpls impl_;
108
109 ElfReader(internal::ElfReaderImpls&& impl) : impl_(std::move(impl)) {}
110};
111
112} // namespace pw::elf
Definition: poll.h:25
Definition: status_with_size.h:51
A basic reader for ELF files.
Definition: reader.h:37
Definition: stream.h:400
stream::SeekableReader & stream() const
Gets the associated stream.
Definition: reader.h:61
Result< std::vector< std::byte > > ReadSection(std::string_view name)
StatusWithSize SeekToSection(std::string_view name)
Definition: reader.h:83
static Result< ElfReader > FromStream(stream::SeekableReader &stream)
Basic ELF reader library.
Definition: reader.h:32