|
rapidyaml 0.16.0
parse and emit YAML, and do it fast
|
An event handler used by ParseEngine to creates an integer buffer with a very compact representation of the YAML tree in a source buffer. More...
Namespaces | |
| namespace | c4::yml::extra::ievt |
Classes | |
| struct | c4::yml::extra::EventHandlerInts |
| A parser event handler that creates a compact representation of the YAML tree in a contiguous buffer of integers. More... | |
Typedefs | |
| using | c4::yml::extra::evt_size = int32_t |
| data type for integer events size. | |
Functions | |
| evt_size | c4::yml::extra::estimate_events_ints_size (csubstr src) |
| Read YAML source and, without undergoing a full parse, estimate the size of the integer buffer required for EventHandlerInts. | |
| size_t | c4::yml::extra::events_ints_to_testsuite (csubstr parsed_yaml, csubstr arena, ievt::evt_bits const *evts_ints, ievt::evt_bits evts_ints_sz, substr evts_testsuite) |
| Create a testsuite event string from integer events. | |
| template<class Container> | |
| void | c4::yml::extra::events_ints_to_testsuite (csubstr parsed_yaml, csubstr arena, ievt::evt_bits const *evts_ints, ievt::evt_bits evts_ints_sz, Container *evts_testsuite) |
| Create a testsuite event string from integer events, writing into an output container. | |
| template<class Container> | |
| Container | c4::yml::extra::events_ints_to_testsuite (csubstr parsed_yaml, csubstr arena, ievt::evt_bits const *evts_ints, ievt::evt_bits evts_ints_sz) |
| Create a testsuite event string from integer events, returning a new container with the result. | |
| void | c4::yml::extra::events_ints_print (csubstr parsed_yaml, csubstr arena, ievt::evt_bits const *evts_ints, ievt::evt_bits evts_ints_sz) |
| Print integer events to stdout. | |
An event handler used by ParseEngine to creates an integer buffer with a very compact representation of the YAML tree in a source buffer.
This feature is an extra and is not part of the main rapidyaml library.
This is meant for use by other programming languages, and supports container keys (unlike the ryml tree). It parses faster than the ryml tree parser, because the resulting data structure is much simpler.
The resulting integer buffer is a linear array of integers containing encoded YAML events (as a mask of ievt::EventBits), which in some cases (eg scalars) are followed by an encoded string (encoded as an offset and length to the parsed source buffer).
For example, parsing [a, bb, ccc] results in the following event buffer (grouped to highlight the event sequence structure):
Here is a sketch clarifying the meaning of this event sequence:
Note that the buffer contains both events and strings encoded as integer pairs. That is, events that have an associated string are immediately followed by two integers providing the offset and length of that string in the source buffer. (In the example above, this happens in the events for the strings a, bb, and ccc at positions 3, 6 and 9, respectively).
The flag ievt::PSTR and the mask ievt::WSTR are provided to enable easier iteration over the array: you can use them to test for presence of a string when iterating over the array.
The flag ievt::PSTR announces that an event is preceded by a string. That is, the previous event has a string, so that when this flag is found while iterating right-to-left, a jump of -3 should be used to get at the bitmask of the previous event. (In the example above, this flag is present for the events for bb and ccc, but not a because it is not preceded by a string).
Likewise, to signify that the current event is followed by a string, there is the mask ievt::WSTR, which is a mask of all the flags of events that have a string: ievt::SCLR, ievt::ALIA, ievt::ANCH and ievt::TAG_. While iterating left-to-right in the array, presence of any of the bits in the mask ievt::WSTR means that a jump of +3 should be employed to get at the bitmask of the next event.
Here's another example with the result of parsing a: bb
Typical code to iterate left-to-right over the array will look like this:
| using c4::yml::extra::evt_size = int32_t |
data type for integer events size.
This is set to an int32_t integer to allow compatibility with a wide range of processing languages.
Definition at line 176 of file event_handler_ints.hpp.
Read YAML source and, without undergoing a full parse, estimate the size of the integer buffer required for EventHandlerInts.
This estimation is meant to exceed the actual number of required events.
Definition at line 25 of file event_handler_ints.cpp.
Referenced by estimate_events_ints_size().
| size_t c4::yml::extra::events_ints_to_testsuite | ( | csubstr | parsed_yaml, |
| csubstr | arena, | ||
| ievt::evt_bits const * | evts_ints, | ||
| ievt::evt_bits | evts_ints_sz, | ||
| substr | evts_testsuite ) |
Create a testsuite event string from integer events.
This overload receives a buffer where the string is to be written, and returns the size needed to accomodate the result. The size of the buffer is strictly respected. The caller must check that the returned size is smaller than the buffer's size to ensure that the result is complete. If that's not the case, the user must resize the buffer and call again.
Definition at line 33 of file ints_to_testsuite.cpp.
Referenced by events_ints_to_testsuite(), events_ints_to_testsuite(), and events_ints_to_testsuite().
| void c4::yml::extra::events_ints_to_testsuite | ( | csubstr | parsed_yaml, |
| csubstr | arena, | ||
| ievt::evt_bits const * | evts_ints, | ||
| ievt::evt_bits | evts_ints_sz, | ||
| Container * | evts_testsuite ) |
Create a testsuite event string from integer events, writing into an output container.
Definition at line 39 of file ints_to_testsuite.hpp.
| Container c4::yml::extra::events_ints_to_testsuite | ( | csubstr | parsed_yaml, |
| csubstr | arena, | ||
| ievt::evt_bits const * | evts_ints, | ||
| ievt::evt_bits | evts_ints_sz ) |
Create a testsuite event string from integer events, returning a new container with the result.
Definition at line 58 of file ints_to_testsuite.hpp.
| void c4::yml::extra::events_ints_print | ( | csubstr | parsed_yaml, |
| csubstr | arena, | ||
| ievt::evt_bits const * | evts, | ||
| ievt::evt_bits | evts_sz ) |
Print integer events to stdout.
Definition at line 103 of file ints_utils.cpp.