Writer example
This commit is contained in:
parent
1476dbdd57
commit
fb97037243
40
README.md
40
README.md
@ -97,7 +97,45 @@ The library is meant to be embedded directly into another project.
|
||||
|
||||
## Writing example
|
||||
|
||||
TBA
|
||||
#include"eebie/writer.h"
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
static void *on_alloc(EBMLWriter *w, void *p, size_t sz) {
|
||||
return realloc(p, sz);
|
||||
}
|
||||
|
||||
static size_t on_write(EBMLWriter *w, const void *p, size_t sz) {
|
||||
FILE *fp = w->ud;
|
||||
|
||||
return fwrite(p, 1, sz, fp);
|
||||
}
|
||||
|
||||
int main() {
|
||||
EBMLWriter w;
|
||||
ebml_writer_init(&w);
|
||||
|
||||
FILE *output = fopen("test.ebml", "wb");
|
||||
w.ud = output;
|
||||
|
||||
w.eventWrite = on_write;
|
||||
w.eventAlloc = on_alloc;
|
||||
|
||||
ebml_writer_push(&w, 0x1A45DFA3);
|
||||
ebml_writer_put(&w, 0x4286, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = 1});
|
||||
ebml_writer_put(&w, 0x4282, EBML_STRING, (EBMLPrimitive) {.string = "excrement"});
|
||||
ebml_writer_pop(&w);
|
||||
|
||||
// Unknown-sized element must not have corresponding pop
|
||||
ebml_writer_push_ind(&w, 0x18538067);
|
||||
|
||||
ebml_writer_put(&w, 0x4123, EBML_STRING, (EBMLPrimitive) {.string = "yodel"});
|
||||
|
||||
while(!ebml_writer_flush(&w));
|
||||
|
||||
fclose(output);
|
||||
}
|
||||
|
||||
## `schemagen`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user