test: serial: update to use new object system
This commit is contained in:
@@ -26,13 +26,12 @@ int main(void)
|
||||
|
||||
b_dict_put(dict, "strings", B_RV(array));
|
||||
|
||||
b_to_string(B_DSREF(dict), b_stdout);
|
||||
b_object_to_string(dict, b_stdout);
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_serial_ctx_serialise(
|
||||
ctx, B_SERIAL_FORMAT_JSON, B_DSREF(dict), b_stdout, 0);
|
||||
b_serial_ctx_serialise(ctx, B_SERIAL_FORMAT_JSON, dict, b_stdout, 0);
|
||||
|
||||
b_dict_release(dict);
|
||||
b_dict_unref(dict);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
#include <blue/ds/datetime.h>
|
||||
#include <blue/ds/dict.h>
|
||||
#include <blue/ds/number.h>
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <blue/ds/type.h>
|
||||
#include <blue/serial.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
void write_tagged_value(b_dsref *data);
|
||||
void write_tagged_value(b_object *data);
|
||||
|
||||
void write_raw_string(const b_string *data)
|
||||
{
|
||||
@@ -127,7 +125,7 @@ void write_tagged_datetime(b_datetime *data)
|
||||
|
||||
b_stream_write_string(b_stdout, "\" }", NULL);
|
||||
|
||||
b_string_release(new_data);
|
||||
b_string_unref(new_data);
|
||||
}
|
||||
|
||||
void write_tagged_dict(b_dict *data)
|
||||
@@ -169,40 +167,34 @@ void write_tagged_array(b_array *data)
|
||||
b_stream_write_string(b_stdout, " ]", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_value(b_dsref *data)
|
||||
void write_tagged_value(b_object *data)
|
||||
{
|
||||
b_dsref_type_id typeid = B_TYPEID(data);
|
||||
if (b_object_is_type(data, B_TYPE_DICT)) {
|
||||
write_tagged_dict(data);
|
||||
|
||||
switch (typeid) {
|
||||
case B_DSREF_TYPE_DICT:
|
||||
write_tagged_dict(B_DICT(data));
|
||||
break;
|
||||
case B_DSREF_TYPE_ARRAY:
|
||||
write_tagged_array(B_ARRAY(data));
|
||||
break;
|
||||
case B_DSREF_TYPE_STRING:
|
||||
write_tagged_string(B_STRING(data));
|
||||
break;
|
||||
case B_DSREF_TYPE_DATETIME:
|
||||
write_tagged_datetime(B_DATETIME(data));
|
||||
break;
|
||||
case B_DSREF_TYPE_NUMBER:
|
||||
switch (b_number_get_type(B_NUMBER(data))) {
|
||||
} else if (b_object_is_type(data, B_TYPE_ARRAY)) {
|
||||
write_tagged_array(data);
|
||||
|
||||
} else if (b_object_is_type(data, B_TYPE_STRING)) {
|
||||
write_tagged_string(data);
|
||||
|
||||
} else if (b_object_is_type(data, B_TYPE_DATETIME)) {
|
||||
write_tagged_datetime(data);
|
||||
|
||||
} else if (b_object_is_type(data, B_TYPE_NUMBER)) {
|
||||
switch (b_number_get_number_type(data)) {
|
||||
case B_NUMBER_LONGLONG:
|
||||
write_tagged_integer(B_NUMBER(data));
|
||||
write_tagged_integer(data);
|
||||
break;
|
||||
case B_NUMBER_INT8:
|
||||
write_tagged_bool(B_NUMBER(data));
|
||||
write_tagged_bool(data);
|
||||
break;
|
||||
case B_NUMBER_DOUBLE:
|
||||
write_tagged_float(B_NUMBER(data));
|
||||
write_tagged_float(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +206,7 @@ int main(void)
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
|
||||
b_dsref *data;
|
||||
b_object *data;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_TOML, src, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
@@ -226,7 +218,7 @@ int main(void)
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_serial_ctx_destroy(ctx);
|
||||
b_release(data);
|
||||
b_object_unref(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/serial.h>
|
||||
|
||||
int main(void)
|
||||
|
||||
Reference in New Issue
Block a user