Pigweed
 
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
31namespace pw::elf {
32
34class ElfReader {
35 public:
55 static Result<ElfReader> FromStream(stream::SeekableReader& stream);
56
59 return std::visit([](auto&& impl) -> auto& { return impl.stream(); },
60 impl_);
61 }
62
80 StatusWithSize SeekToSection(std::string_view name) {
81 return std::visit([name](auto&& impl) { return impl.SeekToSection(name); },
82 impl_);
83 }
84
101 Result<std::vector<std::byte>> ReadSection(std::string_view name);
102
103 private:
104 internal::ElfReaderImpls impl_;
105
106 ElfReader(internal::ElfReaderImpls&& impl) : impl_(std::move(impl)) {}
107};
108
109} // namespace pw::elf
Definition: status_with_size.h:49
A basic reader for ELF files.
Definition: reader.h:34
stream::SeekableReader & stream() const
Gets the associated stream.
Definition: reader.h:58
Result< std::vector< std::byte > > ReadSection(std::string_view name)
StatusWithSize SeekToSection(std::string_view name)
Definition: reader.h:80
static Result< ElfReader > FromStream(stream::SeekableReader &stream)
Definition: stream.h:394