sparrow-ipc 0.2.0
Loading...
Searching...
No Matches
magic_values.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <cstdint>
6#include <istream>
7#include <ranges>
8
9namespace sparrow_ipc
10{
15 inline constexpr std::array<std::uint8_t, 4> continuation = {0xFF, 0xFF, 0xFF, 0xFF};
16
21 inline constexpr std::array<std::uint8_t, 8> end_of_stream = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00};
22
28 inline constexpr std::array<std::uint8_t, 6> arrow_file_magic = {'A', 'R', 'R', 'O', 'W', '1'};
29 inline constexpr std::size_t arrow_file_magic_size = arrow_file_magic.size();
30
34 inline constexpr std::array<std::uint8_t, 8> arrow_file_header_magic = {'A', 'R', 'R', 'O', 'W', '1', 0x00, 0x00};
35
36 template <std::ranges::input_range R>
37 [[nodiscard]] bool is_continuation(const R& buf)
38 {
39 return std::ranges::equal(buf, continuation);
40 }
41
42 template <std::ranges::input_range R>
43 [[nodiscard]] bool is_end_of_stream(const R& buf)
44 {
45 return std::ranges::equal(buf, end_of_stream);
46 }
47
48 template <std::ranges::input_range R>
49 [[nodiscard]] bool is_arrow_file_magic(const R& buf)
50 {
51 if (std::ranges::size(buf) < arrow_file_magic_size)
52 {
53 return false;
54 }
55 auto buf_begin = std::ranges::begin(buf);
56 return std::equal(buf_begin, buf_begin + arrow_file_magic_size, arrow_file_magic.begin());
57 }
58}
bool is_end_of_stream(const R &buf)
constexpr std::array< std::uint8_t, 8 > end_of_stream
End-of-stream marker defined in the Arrow IPC specification: https://arrow.apache....
constexpr std::array< std::uint8_t, 6 > arrow_file_magic
Magic bytes for Arrow file format defined in the Arrow IPC specification: https://arrow....
constexpr std::size_t arrow_file_magic_size
bool is_continuation(const R &buf)
bool is_arrow_file_magic(const R &buf)
constexpr std::array< std::uint8_t, 8 > arrow_file_header_magic
Magic bytes with padding for file header (8 bytes total for alignment)
constexpr std::array< std::uint8_t, 4 > continuation
Continuation value defined in the Arrow IPC specification: https://arrow.apache.org/docs/format/Colum...