libfyaml
libfyaml copied to clipboard
sequence of documents output style
I'm trying to get the emitter to output an array of documents in full block style. This is what the library outputs in block mode:
key: [
a: 1,
b: 2]
and this is what I'm trying to emit as output:
key:
- a: 1
- b: 2
Is this possible?
it has something do internally with an empty save ctx in fy_emit_sequence_prolog.
The program below shows the issue. This is the output:
key: [
a: 1]
struct fy_emitter*, enum fy_emitter_write_type, const char* str, int len, void*) {
write(1, str, len);
return len;
}
int main(int argc, char* argv[]) {
struct fy_emitter_cfg cfg;
struct fy_emitter* emit;
cfg.flags = FYECF_MODE_BLOCK;
cfg.output = handler;
emit = fy_emitter_create(&cfg);
fy_emit_event(emit, fy_emit_event_create(emit, FYET_STREAM_START));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_DOCUMENT_START, true, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_MAPPING_START, FYNS_BLOCK, NULL, NULL));
fy_emit_event(emit,
fy_emit_event_create(emit, FYET_SCALAR, FYSS_PLAIN, "key", FY_NT, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_SEQUENCE_START, FYNS_BLOCK, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_MAPPING_START, FYNS_BLOCK, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_SCALAR, FYSS_PLAIN, "a", FY_NT, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_SCALAR, FYSS_PLAIN, "1", FY_NT, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_MAPPING_END));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_SEQUENCE_END));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_MAPPING_END));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_DOCUMENT_END, true, NULL, NULL));
fy_emit_event(emit, fy_emit_event_create(emit, FYET_STREAM_END));
fy_emitter_destroy(emit);
}