ipfs-chromium
Loading...
Searching...
No Matches
byte_view.h
1#ifndef CHROMIUM_IPFS_BYTE_VIEW_H
2#define CHROMIUM_IPFS_BYTE_VIEW_H
3
4#include "byte.h"
5#include "span.h"
6
7#include <cstdint>
8
9namespace ipfs {
10using ByteView = span<ipfs::Byte const>;
11
12// ByteView is a view over arbitrary opaque byte
13// Cast it to a view over 8-bit unsigned integers for inspection
14inline span<std::uint8_t const> as_octets(ByteView bytes) {
15 return {reinterpret_cast<std::uint8_t const*>(bytes.data()), bytes.size()};
16}
17template <class ContiguousBytes>
18inline ByteView as_bytes(ContiguousBytes const& b) {
19 auto p = reinterpret_cast<ipfs::Byte const*>(b.data());
20 return ByteView{p, b.size()};
21}
22} // namespace ipfs
23
24#endif // CHROMIUM_IPFS_BYTE_VIEW_H