ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
xml.h
Go to the documentation of this file.
1
26#pragma once
27
28#include <stddef.h>
29#include <stdint.h>
30
31#include "ra8_err.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38typedef enum : uint16_t {
42
44typedef struct {
45 uint32_t offset;
46 uint32_t length;
48
50typedef struct {
51 uint32_t name_offset;
52 uint16_t name_length;
53 uint16_t consumer;
55
60
69
71typedef struct {
74 uint16_t depth;
75 uint16_t attribute_count;
76 uint8_t kind;
77 uint8_t self_closing;
79
85
87typedef struct {
88 uint32_t position;
89 uint16_t emitted;
91
93typedef struct {
94 const uint8_t* source;
95 size_t source_len;
96 size_t position;
98 uint16_t stack_size;
99 uint8_t root_count;
100 uint8_t root_closed;
102 uint8_t doctype_seen;
103 uint8_t finished;
105
124[[nodiscard]] ra8_err_t xml_reader_init(xml_reader_t* reader,
125 const uint8_t* source,
126 size_t source_len,
127 xml_workspace_t* workspace);
128
145[[nodiscard]] ra8_err_t xml_reader_next(xml_reader_t* reader, xml_event_t* out_event);
146
164[[nodiscard]] ra8_err_t
165xml_validate(const uint8_t* source, size_t source_len, xml_workspace_t* workspace);
166
179void xml_attr_begin(const xml_event_t* event, xml_attr_cursor_t* cursor);
180
201[[nodiscard]] ra8_err_t xml_attr_next(const uint8_t* source,
202 size_t source_len,
203 const xml_event_t* event,
204 xml_attr_cursor_t* cursor,
205 xml_attribute_t* out_attribute,
206 bool* out_has_value);
207
221[[nodiscard]] bool
222xml_span_equal(const uint8_t* source, size_t source_len, xml_span_t span, const char* literal);
223
237[[nodiscard]] bool xml_span_local_equal(const uint8_t* source,
238 size_t source_len,
239 xml_span_t span,
240 const char* literal);
241
255[[nodiscard]] bool
256xml_decoded_equal(const uint8_t* source, size_t source_len, xml_span_t left, xml_span_t right);
257
279[[nodiscard]] ra8_err_t xml_decode(const uint8_t* source,
280 size_t source_len,
281 xml_span_t span,
282 char* destination,
283 size_t capacity,
284 size_t* out_length);
285
301[[nodiscard]] ra8_err_t
302xml_decoded_size(const uint8_t* source, size_t source_len, xml_span_t span, size_t* out_length);
303
328[[nodiscard]] ra8_err_t xml_decode_prefix(const uint8_t* source,
329 size_t source_len,
330 xml_span_t span,
331 char* destination,
332 size_t capacity,
333 size_t* out_length);
334
335#ifdef __cplusplus
336} /* extern "C" */
337#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Mutable cursor for one start event's attributes.
Definition xml.h:87
uint16_t emitted
Attributes already returned.
Definition xml.h:89
uint32_t position
Next scan position.
Definition xml.h:88
Source-order attribute view.
Definition xml.h:81
xml_span_t value
Quoted value excluding delimiters.
Definition xml.h:83
xml_span_t name
Attribute name.
Definition xml.h:82
One XML pull event.
Definition xml.h:71
uint16_t attribute_count
Source-order attributes on start.
Definition xml.h:75
xml_span_t markup
Complete markup span, or text payload.
Definition xml.h:72
uint8_t self_closing
One for an empty-element start.
Definition xml.h:77
xml_span_t name
Element name for start/end.
Definition xml.h:73
uint16_t depth
Root is depth zero.
Definition xml.h:74
uint8_t kind
xml_event_kind_t.
Definition xml.h:76
One open-element identity retained for close-tag validation.
Definition xml.h:50
uint16_t consumer
Consumer-owned while this frame is live.
Definition xml.h:53
uint16_t name_length
Element-name byte count.
Definition xml.h:52
uint32_t name_offset
Element-name offset in the source.
Definition xml.h:51
Pull-reader state; initialise before each pass.
Definition xml.h:93
uint8_t finished
End validation complete.
Definition xml.h:103
uint8_t root_count
Completed/started roots.
Definition xml.h:99
uint16_t stack_size
Open element count.
Definition xml.h:98
const uint8_t * source
Immutable source bytes.
Definition xml.h:94
uint8_t doctype_seen
One after a supported DOCTYPE.
Definition xml.h:102
xml_workspace_t * workspace
Caller-owned stack.
Definition xml.h:97
size_t source_len
Source byte count.
Definition xml.h:95
size_t position
Next scan position.
Definition xml.h:96
uint8_t declaration_seen
One after XML declaration.
Definition xml.h:101
uint8_t root_closed
One after root close.
Definition xml.h:100
Immutable byte span expressed relative to the source.
Definition xml.h:44
uint32_t length
Byte count.
Definition xml.h:46
uint32_t offset
First byte offset.
Definition xml.h:45
Exactly bounded caller-owned nesting storage.
Definition xml.h:57
xml_frame_t frames[k_xml_workspace_frames]
Open-element stack.
Definition xml.h:58
xml_limits_t
Fixed parser geometry.
Definition xml.h:38
@ k_xml_max_element_depth
Accepted element levels, including root.
Definition xml.h:39
@ k_xml_workspace_frames
Physical frame capacity with headroom.
Definition xml.h:40
ra8_err_t xml_decoded_size(const uint8_t *source, size_t source_len, xml_span_t span, size_t *out_length)
Measure the entity-decoded byte count of a bounded span.
Definition xml_decode.c:544
bool xml_decoded_equal(const uint8_t *source, size_t source_len, xml_span_t left, xml_span_t right)
Compare two entity-decoded spans from the same immutable source.
Definition xml_decode.c:584
void xml_attr_begin(const xml_event_t *event, xml_attr_cursor_t *cursor)
Initialise source-order attribute iteration for a start event.
Definition xml.c:70
bool xml_span_local_equal(const uint8_t *source, size_t source_len, xml_span_t span, const char *literal)
Compare the namespace-local tail of a bounded span with an ASCII literal.
Definition xml_decode.c:565
ra8_err_t xml_attr_next(const uint8_t *source, size_t source_len, const xml_event_t *event, xml_attr_cursor_t *cursor, xml_attribute_t *out_attribute, bool *out_has_value)
Return the next source-order attribute.
Definition xml.c:181
xml_event_kind_t
Pull-event kind.
Definition xml.h:62
@ k_xml_event_cdata
CDATA payload.
Definition xml.h:67
@ k_xml_event_start
Element start.
Definition xml.h:64
@ k_xml_event_none
No event / end of source.
Definition xml.h:63
@ k_xml_event_text
Character-data run.
Definition xml.h:66
@ k_xml_event_end
Element end.
Definition xml.h:65
ra8_err_t xml_validate(const uint8_t *source, size_t source_len, xml_workspace_t *workspace)
Validate a complete document before any consumer mutation.
Definition xml.c:631
bool xml_span_equal(const uint8_t *source, size_t source_len, xml_span_t span, const char *literal)
Compare a bounded span with an exact ASCII literal.
Definition xml_decode.c:555
ra8_err_t xml_decode(const uint8_t *source, size_t source_len, xml_span_t span, char *destination, size_t capacity, size_t *out_length)
Entity-decode a source span into a bounded NUL-terminated buffer.
Definition xml_decode.c:511
ra8_err_t xml_reader_init(xml_reader_t *reader, const uint8_t *source, size_t source_len, xml_workspace_t *workspace)
Initialise a pull pass over immutable bytes.
Definition xml.c:571
ra8_err_t xml_reader_next(xml_reader_t *reader, xml_event_t *out_event)
Return the next semantic event and validate syntax incrementally.
Definition xml.c:590
ra8_err_t xml_decode_prefix(const uint8_t *source, size_t source_len, xml_span_t span, char *destination, size_t capacity, size_t *out_length)
Decode the longest complete prefix that fits the destination.
Definition xml_decode.c:527