PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
bytes.h
1// Copyright (c) 2009-2026 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_PDF_BYTES_H_INCLUDED_
4#define PDFSDK_CXX_PDF_BYTES_H_INCLUDED_
5
6#include <cstddef>
7#include <cstdint>
8#include <span>
9#include <string_view>
10#include <type_traits>
11
12namespace PDF {
13
23using Byte = uint8_t;
24
25#ifndef SWIG
26
30template<typename T>
31 requires std::is_trivially_copyable_v<T>
32std::span<const Byte> AsBytes(std::span<T> data) {
33 return std::span<const Byte>(reinterpret_cast<const Byte*>(data.data()), data.size_bytes());
34}
35
39template<typename T>
40 requires (std::is_trivially_copyable_v<T> && !std::is_const_v<T>)
41std::span<Byte> AsWritableBytes(std::span<T> data) {
42 return std::span<Byte>(reinterpret_cast<Byte*>(data.data()), data.size_bytes());
43}
44
48inline std::span<const Byte> AsBytes(const void* data, size_t size) {
49 return std::span<const Byte>(static_cast<const Byte*>(data), size);
50}
51
55inline std::span<const Byte> AsBytes(std::string_view data) {
56 return AsBytes(data.data(), data.size());
57}
58
62inline std::span<Byte> AsWritableBytes(void* data, size_t size) {
63 return std::span<Byte>(static_cast<Byte*>(data), size);
64}
65
66#endif // SWIG
67
68} // namespace PDF
69
70#endif // PDFSDK_CXX_PDF_BYTES_H_INCLUDED_