6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ENDIAN_ENDIAN_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ENDIAN_ENDIAN_HPP_
17#include "arene/base/algorithm/copy.hpp"
18#include "arene/base/byte/byte.hpp"
19#include "arene/base/constraints/constraints.hpp"
20#include "arene/base/span/span.hpp"
21#include "arene/base/stdlib_choice/cstddef.hpp"
22#include "arene/base/stdlib_choice/cstdint.hpp"
23#include "arene/base/stdlib_choice/enable_if.hpp"
24#include "arene/base/stdlib_choice/ignore.hpp"
25#include "arene/base/stdlib_choice/is_arithmetic.hpp"
26#include "arene/base/stdlib_choice/is_enum.hpp"
27#include "arene/base/stdlib_choice/is_floating_point.hpp"
28#include "arene/base/stdlib_choice/is_integral.hpp"
29#include "arene/base/stdlib_choice/is_same.hpp"
30#include "arene/base/stdlib_choice/underlying_type.hpp"
31#include "arene/base/type_traits/type_identity.hpp"
35#include "arene/base/endian/detail/endian_windows_impl.hpp"
36#elif defined(__BYTE_ORDER__
)
37#include "arene/base/endian/detail/endian_specified_byte_order_impl.hpp"
39#include "arene/base/endian/detail/endian_generic_impl.hpp"
216namespace endian_detail {
219constexpr std::size_t bits_8{8U};
220constexpr std::size_t bits_16{16U};
221constexpr std::size_t bits_24{24U};
222constexpr std::size_t bits_32{32U};
223constexpr std::size_t bits_40{40U};
224constexpr std::size_t bits_48{48U};
225constexpr std::size_t bits_56{56U};
230constexpr std::size_t byte_0{0U};
231constexpr std::size_t byte_1{1U};
232constexpr std::size_t byte_2{2U};
233constexpr std::size_t byte_3{3U};
234constexpr std::size_t byte_4{4U};
235constexpr std::size_t byte_5{5U};
236constexpr std::size_t byte_6{6U};
237constexpr std::size_t byte_7{7U};
242template <std::size_t Size>
247class endian_impl<
sizeof(std::uint8_t)> {
250 using type = std::uint8_t;
255 static constexpr auto read_little_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
256 return ::arene::base::to_integer<type>(bytes[byte_0]);
262 static constexpr void write_little_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
263 bytes[byte_0] = to_byte(value);
269 static constexpr auto read_big_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
270 return ::arene::base::to_integer<type>(bytes[byte_0]);
276 static constexpr void write_big_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
277 bytes[byte_0] = to_byte(value);
283class endian_impl<
sizeof(std::uint16_t)> {
286 using type = std::uint16_t;
291 static constexpr auto read_little_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
299 return ::arene::base::to_integer<std::uint16_t>(bytes[byte_0]) |
300 static_cast<std::uint16_t>(::arene::base::to_integer<std::uint16_t>(bytes[byte_1]) << bits_8);
306 static constexpr void write_little_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
315 bytes[byte_0] = to_byte(value);
316 bytes[byte_1] = to_byte(
static_cast<std::uint8_t>(value >> bits_8));
322 static constexpr auto read_big_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
331 return ::arene::base::to_integer<std::uint16_t>(bytes[byte_1]) |
332 static_cast<std::uint16_t>(::arene::base::to_integer<std::uint16_t>(bytes[byte_0]) << bits_8);
338 static constexpr void write_big_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
347 bytes[byte_1] = to_byte(value);
348 bytes[byte_0] = to_byte(
static_cast<std::uint8_t>(value >> bits_8));
354class endian_impl<
sizeof(std::uint32_t)> {
357 using type = std::uint32_t;
361 static constexpr auto read_little_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
370 return ::arene::base::to_integer<std::uint32_t>(bytes[byte_0]) |
372 (::arene::base::to_integer<std::uint32_t>(bytes[byte_1]) << bits_8) |
374 (::arene::base::to_integer<std::uint32_t>(bytes[byte_2]) << bits_16) |
376 (::arene::base::to_integer<std::uint32_t>(bytes[byte_3]) << bits_24);
382 static constexpr void write_little_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
390 bytes[byte_0] = to_byte(value);
391 bytes[byte_1] = to_byte(value >> bits_8);
392 bytes[byte_2] = to_byte(value >> bits_16);
393 bytes[byte_3] = to_byte(value >> bits_24);
399 static constexpr auto read_big_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
408 return ::arene::base::to_integer<std::uint32_t>(bytes[byte_3]) |
409 (::arene::base::to_integer<std::uint32_t>(bytes[byte_2]) << bits_8) |
410 (::arene::base::to_integer<std::uint32_t>(bytes[byte_1]) << bits_16) |
411 (::arene::base::to_integer<std::uint32_t>(bytes[byte_0]) << bits_24);
417 static constexpr void write_big_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
426 bytes[byte_3] = to_byte(value);
427 bytes[byte_2] = to_byte(value >> bits_8);
428 bytes[byte_1] = to_byte(value >> bits_16);
429 bytes[byte_0] = to_byte(value >> bits_24);
435class endian_impl<
sizeof(std::uint64_t)> {
438 using type = std::uint64_t;
442 static constexpr auto read_little_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
451 return ::arene::base::to_integer<std::uint64_t>(bytes[byte_0]) |
452 (::arene::base::to_integer<std::uint64_t>(bytes[byte_1]) << bits_8) |
453 (::arene::base::to_integer<std::uint64_t>(bytes[byte_2]) << bits_16) |
454 (::arene::base::to_integer<std::uint64_t>(bytes[byte_3]) << bits_24) |
455 (::arene::base::to_integer<std::uint64_t>(bytes[byte_4]) << bits_32) |
456 (::arene::base::to_integer<std::uint64_t>(bytes[byte_5]) << bits_40) |
457 (::arene::base::to_integer<std::uint64_t>(bytes[byte_6]) << bits_48) |
458 (::arene::base::to_integer<std::uint64_t>(bytes[byte_7]) << bits_56);
464 static constexpr void write_little_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
473 bytes[byte_0] = to_byte(value);
474 bytes[byte_1] = to_byte(value >> bits_8);
475 bytes[byte_2] = to_byte(value >> bits_16);
476 bytes[byte_3] = to_byte(value >> bits_24);
477 bytes[byte_4] = to_byte(value >> bits_32);
478 bytes[byte_5] = to_byte(value >> bits_40);
479 bytes[byte_6] = to_byte(value >> bits_48);
480 bytes[byte_7] = to_byte(value >> bits_56);
486 static constexpr auto read_big_endian(span<byte
const,
sizeof(type)>
const bytes)
noexcept -> type {
495 return ::arene::base::to_integer<std::uint64_t>(bytes[byte_7]) |
496 (::arene::base::to_integer<std::uint64_t>(bytes[byte_6]) << bits_8) |
497 (::arene::base::to_integer<std::uint64_t>(bytes[byte_5]) << bits_16) |
498 (::arene::base::to_integer<std::uint64_t>(bytes[byte_4]) << bits_24) |
499 (::arene::base::to_integer<std::uint64_t>(bytes[byte_3]) << bits_32) |
500 (::arene::base::to_integer<std::uint64_t>(bytes[byte_2]) << bits_40) |
501 (::arene::base::to_integer<std::uint64_t>(bytes[byte_1]) << bits_48) |
502 (::arene::base::to_integer<std::uint64_t>(bytes[byte_0]) << bits_56);
508 static constexpr void write_big_endian(type
const value, span<byte,
sizeof(type)>
const bytes)
noexcept {
517 bytes[byte_7] = to_byte(value);
518 bytes[byte_6] = to_byte(value >> bits_8);
519 bytes[byte_5] = to_byte(value >> bits_16);
520 bytes[byte_4] = to_byte(value >> bits_24);
521 bytes[byte_3] = to_byte(value >> bits_32);
522 bytes[byte_2] = to_byte(value >> bits_40);
523 bytes[byte_1] = to_byte(value >> bits_48);
524 bytes[byte_0] = to_byte(value >> bits_56);
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10