Go to the documentation of this file.
9 #ifndef EAGINE_SERIALIZE_READ_BACKEND_HPP
10 #define EAGINE_SERIALIZE_READ_BACKEND_HPP
12 #include "../identifier.hpp"
13 #include "../interface.hpp"
14 #include "../reflect/decl_name.hpp"
125 template <
typename Derived,
typename Source = deserializer_data_source>
157 return derived().do_read(values, done);
161 return derived().do_read(values, done);
165 return derived().do_read(values, done);
169 return derived().do_read(values, done);
173 return derived().do_read(values, done);
177 return derived().do_read(values, done);
181 return derived().do_read(values, done);
185 return derived().do_read(values, done);
190 return derived().do_read(values, done);
194 return derived().do_read(values, done);
199 return derived().do_read(values, done);
204 return derived().do_read(values, done);
208 return derived().do_read(values, done);
212 return derived().do_read(values, done);
216 return derived().do_read(values, done);
221 return derived().do_read(values, done);
225 return derived().do_read(values, done);
261 -> valid_if_nonnegative<span_size_t> {
262 EAGINE_ASSERT(_source);
263 return _source->scan_for(what, max, step);
267 EAGINE_ASSERT(_source);
268 return _source->top(size);
277 const valid_if_positive<span_size_t>& max,
278 const valid_if_positive<span_size_t>& step = {256}) {
279 auto found = scan_for(
byte(c), max, step);
280 return top_string(extract_or(found, 0));
284 return top_string(1);
288 EAGINE_ASSERT(_source);
293 return are_equal(top_string(what.size()), what);
296 auto starts_with(
char c) ->
bool {
297 return starts_with(view_one(c));
300 auto consume(
string_view what, result& errors) ->
bool {
302 auto top_str = top_string(what.size());
303 if(top_str.size() < what.size()) {
304 errors |= error_code::not_enough_data;
306 if(are_equal(top_str, what)) {
310 errors |= error_code::unexpected_data;
316 auto consume(
char what, result& errors) ->
bool {
317 return consume(view_one(what), errors);
320 template <
typename Function>
323 const valid_if_positive<span_size_t> step = {256}) {
324 while(
auto pos = _source->scan_until(predicate, step, step)) {
335 auto top_str = top_string(what.size());
336 if(top_str.size() < what.size()) {
337 errors |= error_code::not_enough_data;
339 if(are_equal(top_str, what)) {
342 errors |= error_code::invalid_format;
349 auto require(
char what) -> result {
350 return require(view_one(what));
354 Source* _source{
nullptr};
356 auto derived() noexcept -> Derived& {
357 return *
static_cast<Derived*
>(
this);
363 #endif // EAGINE_SERIALIZE_READ_BACKEND_HPP
virtual auto finish() -> result=0
Finishes the deserialization of a potentially complex structured value.
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
virtual auto type_id() -> identifier=0
Returns a descriptive identifier of the implementation.
auto set_source(Source &s) noexcept -> Derived &
Sets a reference to a new Source object.
Definition: read_backend.hpp:136
Typed enumeration for GL error code constants.
Definition: enum_types.hpp:32
virtual auto begin_struct(span_size_t &member_count) -> result=0
Begins the deserialization of a structure instance.
auto read(span< char > values, span_size_t &done) -> result override
Reads character values, returns how many were done through second argument.
Definition: read_backend.hpp:160
virtual auto begin_element(span_size_t index) -> result=0
Begins the deserialization of a container element.
virtual auto begin_list(span_size_t &element_count) -> result=0
Begins the deserialization of a container instance.
auto read(span< unsigned > values, span_size_t &done) -> result override
Reads uint values, returns how many were done through second argument.
Definition: read_backend.hpp:193
Common code is placed in this namespace.
Definition: eagine.hpp:21
common_deserializer_backend(Source &source) noexcept
Construction from a reference to a Source.
Definition: read_backend.hpp:132
auto begin_member(string_view) -> result override
Begins the deserialization of a structure data member.
Definition: read_backend.hpp:231
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
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
Primary template for conditionally valid values.
Definition: decl.hpp:49
auto read(span< unsigned long > values, span_size_t &done) -> result override
Reads ulong values, returns how many were done through second argument.
Definition: read_backend.hpp:197
auto begin_element(span_size_t) -> result override
Begins the deserialization of a container element.
Definition: read_backend.hpp:243
auto read(span< unsigned short > values, span_size_t &done) -> result override
Reads ushort values, returns how many were done through second argument.
Definition: read_backend.hpp:188
virtual auto begin() -> result=0
Starts the deserialization of a potentially complex structured value.
virtual auto finish_member(string_view name) -> result=0
Finishes the deserialization of a structure data member.
auto read(span< std::int8_t > values, span_size_t &done) -> result override
Reads 8-bit int values, returns how many were done through second argument.
Definition: read_backend.hpp:164
auto begin_struct(span_size_t &) -> result override
Begins the deserialization of a structure instance.
Definition: read_backend.hpp:228
deserialization_error_code
Deserialization error code bits enumeration.
Definition: result.hpp:53
Base template for abstract interfaces, implements common functionality.
Definition: interface.hpp:18
auto finish_member(string_view) -> result override
Finishes the deserialization of a structure data member.
Definition: read_backend.hpp:234
auto source() -> deserializer_data_source *final
Returns a pointer to the associated data source, if any.
Definition: read_backend.hpp:144
virtual auto finish_list() -> result=0
Finishes the deserialization of a container instance.
auto begin() -> result override
Starts the deserialization of a potentially complex structured value.
Definition: read_backend.hpp:152
virtual auto source() -> deserializer_data_source *=0
Returns a pointer to the associated data source, if any.
auto finish_element(span_size_t) -> result override
Finishes the deserialization of a container element.
Definition: read_backend.hpp:246
auto begin_list(span_size_t &) -> result override
Begins the deserialization of a container instance.
Definition: read_backend.hpp:240
auto read(span< bool > values, span_size_t &done) -> result override
Reads boolean values, returns how many were done through second argument.
Definition: read_backend.hpp:156
common_deserializer_backend() noexcept=default
Default constructor.
bitfield< deserialization_error_code > deserialization_errors
Alias for deserialization error bitfield.
Definition: result.hpp:106
Abstract base class for deserialization data sources.
Definition: data_source.hpp:25
virtual auto finish_struct() -> result=0
Finishes the deserialization of a structure instance.
Interface for deserialization read backends.
Definition: read_backend.hpp:25
virtual auto begin_member(string_view name) -> result=0
Begins the deserialization of a structure data member.
auto read(span< short > values, span_size_t &done) -> result override
Reads short values, returns how many were done through second argument.
Definition: read_backend.hpp:168
auto read(span< long long > values, span_size_t &done) -> result override
Reads long long values, returns how many were done through second argument.
Definition: read_backend.hpp:180
auto enum_as_string() -> bool override
@brie Indicates if the backed stores enumerators as strings (or numeric values).
Definition: read_backend.hpp:148
auto read(span< long > values, span_size_t &done) -> result override
Reads long values, returns how many were done through second argument.
Definition: read_backend.hpp:176
auto read(span< decl_name_storage > values, span_size_t &done) -> result override
Reads decl_name values, returns how many were done through second argument.
Definition: read_backend.hpp:219
auto read(span< std::uint8_t > values, span_size_t &done) -> result override
Reads 8-bit uint values, returns how many were done through second argument.
Definition: read_backend.hpp:184
auto finish_list() -> result override
Finishes the deserialization of a container instance.
Definition: read_backend.hpp:249
auto finish_struct() -> result override
Finishes the deserialization of a structure instance.
Definition: read_backend.hpp:237
auto read(span< double > values, span_size_t &done) -> result override
Reads double values, returns how many were done through second argument.
Definition: read_backend.hpp:211
auto read(span< std::string > values, span_size_t &done) -> result override
Reads string values, returns how many were done through second argument.
Definition: read_backend.hpp:224
auto read(span< int > values, span_size_t &done) -> result override
Reads int values, returns how many were done through second argument.
Definition: read_backend.hpp:172
virtual auto enum_as_string() -> bool=0
@brie Indicates if the backed stores enumerators as strings (or numeric values).
CRTP mixin implementing the common parts of deserializer backends.
Definition: read_backend.hpp:126
static constexpr auto as_chars(block blk) noexcept
Converts a block into a span of characters.
Definition: block.hpp:48
auto read(span< unsigned long long > values, span_size_t &done) -> result override
Reads ulong long values, returns how many were done through second argument.
Definition: read_backend.hpp:202
auto finish() -> result override
Finishes the deserialization of a potentially complex structured value.
Definition: read_backend.hpp:252
virtual auto finish_element(span_size_t index) -> result=0
Finishes the deserialization of a container element.
virtual auto read(span< bool >, span_size_t &) -> result=0
Reads boolean values, returns how many were done through second argument.
auto read(span< identifier > values, span_size_t &done) -> result override
Reads identifier values, returns how many were done through second argument.
Definition: read_backend.hpp:215
auto read(span< float > values, span_size_t &done) -> result override
Reads float values, returns how many were done through second argument.
Definition: read_backend.hpp:207