Go to the documentation of this file.
9 #ifndef EAGINE_SERIALIZE_SIZE_AND_DATA_HPP
10 #define EAGINE_SERIALIZE_SIZE_AND_DATA_HPP
12 #include "../branch_predict.hpp"
13 #include "../is_within_limits.hpp"
14 #include "../memory/span_algo.hpp"
15 #include "../multi_byte_seq.hpp"
26 const auto opt_size_cp = limit_cast<mbs::code_point>(src.size());
27 if(EAGINE_LIKELY(opt_size_cp)) {
28 const auto size_cp =
extract(opt_size_cp);
29 const auto opt_size_len = mbs::required_sequence_length(size_cp);
30 if(EAGINE_LIKELY(opt_size_len)) {
31 if(
extract(opt_size_len) + src.size() <= dst.size()) {
32 const auto opt_skip_len = mbs::encode_code_point(size_cp, dst);
33 if(EAGINE_LIKELY(opt_skip_len)) {
35 limit_cast<span_size_t>(
extract(opt_skip_len));
36 copy(src,
skip(dst, skip_len));
37 return head(dst, skip_len + src.size());
52 const auto opt_skip_len = mbs::decode_sequence_length(src);
53 if(
const auto opt_data_len = mbs::do_decode_code_point(src, opt_skip_len)) {
65 const auto opt_skip_len = mbs::decode_sequence_length(tmp);
66 if(
const auto opt_data_len = mbs::do_decode_code_point(tmp, opt_skip_len)) {
69 limit_cast<span_size_t>(
extract(opt_data_len)));
79 const auto opt_skip_len = mbs::decode_sequence_length(src);
80 if(
const auto opt_data_len = mbs::do_decode_code_point(src, opt_skip_len)) {
83 limit_cast<span_size_t>(
extract(opt_data_len)));
92 template <
typename Function>
96 const auto opt_skip_len = mbs::decode_sequence_length(src);
97 const auto opt_data_len = mbs::do_decode_code_point(src, opt_skip_len);
99 const auto skip_len =
extract(opt_skip_len);
100 const auto data_len =
extract(opt_data_len);
103 head(
skip(src, skip_len), limit_cast<span_size_t>(data_len)));
104 src =
skip(src, skip_len + data_len);
116 #endif // EAGINE_SERIALIZE_SIZE_AND_DATA_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
static constexpr auto skip(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Skips a specified count of elements from the front of a span.
Definition: span_algo.hpp:60
static void for_each_data_with_size(memory::const_block src, Function function) noexcept
In a larger block with sub-blocks with size, calls function on each sub-block.
Definition: size_and_data.hpp:94
static auto get_data_with_size(memory::block src) noexcept -> memory::block
Extracts a sub-block from a larger mutable block with encoded sub-block size.
Definition: size_and_data.hpp:62
static auto skip_data_with_size(memory::const_block src) noexcept -> span_size_t
In a block starting with sub-block with size returns the size of the sub-block.
Definition: size_and_data.hpp:50
static auto store_data_with_size(memory::const_block src, memory::block dst) noexcept -> memory::block
Encodes the size of the source block into destination, copies data afterwards.
Definition: size_and_data.hpp:23