meta: add serial module for (de)serialising objects
This commit is contained in:
39
serial-test/streams.c
Normal file
39
serial-test/streams.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/object/array.h>
|
||||
#include <blue/object/dict.h>
|
||||
#include <blue/object/number.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/serial.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
|
||||
b_dict *dict = b_dict_create();
|
||||
|
||||
b_array *array = b_array_create();
|
||||
b_array_append(array, B_RV_INT(32));
|
||||
b_array_append(array, B_RV_INT(64));
|
||||
b_array_append(array, B_RV_INT(128));
|
||||
|
||||
b_dict_put(dict, "numbers", B_RV(array));
|
||||
|
||||
array = b_array_create();
|
||||
b_array_append(array, B_RV_CSTR("hello"));
|
||||
b_array_append(array, B_RV_CSTR("world"));
|
||||
|
||||
b_dict_put(dict, "strings", B_RV(array));
|
||||
|
||||
b_to_string(B_OBJECT(dict), b_stdout);
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_serial_ctx_serialise(
|
||||
ctx, B_SERIAL_FORMAT_JSON, B_OBJECT(dict), b_stdout, 0);
|
||||
|
||||
b_dict_release(dict);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user