rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
doxy_serialization_implementation.hpp
Go to the documentation of this file.
1
2#include "c4/yml/tree.hpp"
3#include "c4/yml/node.hpp"
5
6namespace c4 {
7namespace yml {
8
9
10// DANGER: Keep markdown []() links in a single line!!!
11//
12// doxygen is broken and fails to render the markdown links when
13// they span multi lines.
14//
15
16/** @addtogroup doc_serialization_overview
17
18
19# Implementation overview
20
21
22@note If you are implementing serialization functions for your type,
23you should first skim over the info here, and then remember to return
24to this if you're in trouble.
25
26This describes how ryml implements the serialization pipeline. This is
27useful to understand how the user-provided read() and write()
28functions fit and interact with ryml's implementation.
29
30
31Note also that in a pinch, you can override any non-member function
32mentioned below; however, there shouldn't be any reason to do so
33unless explicitly noted. If you do feel the need to override other
34functions, please submit also an issue at
35https://github.com/biojppm/rapidyaml/issues to discuss whether this is
36an API oversight or maybe a misunderstanding, and hopefully this
37documentation can be improved.
38
39
40// <br>
41// <hr>
42
43## Serialization (write)
44
45
46ryml implements serialization in the following way:
47
48 - The user-facing @ref NodeRef functions are
49 [.save()](@ref c4::yml::NodeRef::save()) and
50 [.save_key()](@ref c4::yml::NodeRef::save_key())
51 (where the node is checked), and
52 [.set_serialized()](@ref c4::yml::NodeRef::set_serialized()) and
53 [.set_key_serialized()](@ref c4::yml::NodeRef::set_key_serialized())
54 (where the node is merely asserted). After the validity check/assert,
55 these functions then call...
56
57 - ... the [node write() overloads](@ref doc_serialization_node_write). **These
58 functions can be overrided for user types**. The default
59 implementations (provided by ryml) merely forward to...:
60
61 - ... the user-facing @ref Tree functions, which are
62 [.save()](@ref c4::yml::Tree::save()) and
63 [.save_key()](@ref c4::yml::Tree::save_key()), as well as
64 [.set_serialized()](@ref c4::yml::Tree::set_serialized()) and
65 [.set_key_serialized()](@ref c4::yml::Tree::set_key_serialized()).
66 Like their node counterparts, these do a value existence check and then call...
67
68 - ... the [tree write()/write_key() overloads](@ref doc_serialization_tree_write),
69 which **again can be overrided for user types**. The default
70 implementations of these functions now get into the nitty-gritty
71 of serialization by choosing a style flag with
72 [scalar_flags_val()](@ref scalar_flags_val()) / [scalar_flags_key()](@ref scalar_flags_key())
73 (**these functions can also be overrided for user types**)
74 and then calling...
75
76 - [serialize_to_arena()](@ref c4::yml::serialize_to_arena())
77 which uses trait @ref c4::is_string<T> to dispatch to...
78
79 - either [serialize_to_arena_str()](@ref c4::yml::serialize_to_arena_str()) for strings,
80 which grows the arena and copies the string to the arena
81
82 - or [serialize_to_arena_scalar()](@ref c4::yml::serialize_to_arena_scalar()),
83 which grows the arena and calls...
84
85 - [scalar_serialize()](@ref c4::yml::scalar_serialize()) to dispatch to...
86
87 - either [to_chars()](@ref c4::yml::to_chars()) for
88 non-floating scalar types, **including user scalar
89 types**. **This function can be overrided for scalar
90 user-types **
91
92 - or [to_chars_float()](@ref c4::yml::to_chars_float()) for
93 floating scalar types, which trims leading +, checks for
94 special YAML value strings eg `.nan` or `.inf`, and then
95 dispatches to @ref c4::ftoa() or @ref c4::dtoa()
96
97
98
99// <br>
100// <hr>
101
102## Deserialization (read)
103
104ryml implements deserialization in the following way:
105
106 - User facing @ref ConstNodeRef functions
107 [.load()](@ref c4::yml::ConstNodeRef::load()) and
108 [.load_key()](@ref c4::yml::ConstNodeRef::load_key())
109 (which check node and deserialization), and
110 [.deserialize()](@ref c4::yml::ConstNodeRef::deserialize()) and
111 [.deserialize_key()](@ref c4::yml::ConstNodeRef::deserialize_key())
112 (which assert node and
113 check serialization). After the validity check/assert, these functions call...
114
115 - ... the [node read() overloads](@ref doc_serialization_node_read). **These
116 functions can be overrided for user types**. The default
117 implementations (provided by ryml) merely forward to...:
118
119 - ... the user-facing @ref Tree functions, which are
120 [.load()](@ref c4::yml::Tree::load()) and
121 [.load_key()](@ref c4::yml::Tree::load_key()) (which check node and deserialization),
122 as well as [.deserialize()](@ref c4::yml::Tree::deserialize()) and
123 [.deserialize_key()](@ref c4::yml::Tree::deserialize_key())
124 (which assert node and check serialization).
125 Like their node counterparts, these do a value existence check
126 and then call...
127
128 - ... the [tree read()/read_key() overloads](@ref doc_serialization_tree_read),
129 which **again can be overrided for user types**. The default
130 implementations of these functions first check that the node
131 [.has_val()](@ref c4::yml::Tree::has_val()) (or key) and then
132 get into the nitty-gritty off deserialization by calling...
133
134 - [scalar_deserialize()](@ref c4::yml::scalar_deserialize()) for
135 standard scalars passed as pointers to read(), which is a
136 dispatcher to...
137
138 - either [from_chars_float()](@ref c4::yml::from_chars_float())
139 for floating types, which trims leading `+` and compares against
140 special YAML float strings such as `.nan` or `.inf`, and finally
141 calls @ref c4::from_chars() which dispatches to either
142 @ref c4::atoi() or @ref c4::atof(), or ...
143
144 - [from_chars_integral()](@ref c4::yml::from_chars_integral())
145 for integral (arithmetic, non-float) types, which trims
146 leading `+` and finally calls @ref c4::from_chars() wrapping
147 either @ref c4::atoi() or @ref c4::atou()
148
149 - and for all other types call from_chars(). **This function
150 can be overrided for scalar user-types**.
151
152 - or [from_chars()](@ref from_chars()) directly for wrapper types
153 like eg @ref c4::fmt::base64() that wrap the destination with
154 some meta-info related with deserialization. **This function
155 can be overrided for wrapper user-types**.
156
157*/
158
159
160} // namespace yml
161} // namespace c4
Node classes.