|
|
|
@ -7,11 +7,26 @@ static bool json_field_bool_reader( struct json_pull_parser* jpp, void* field_da
|
|
|
|
|
{
|
|
|
|
|
return json_pull_parser_read_bool( jpp, (bool*)field_data );
|
|
|
|
|
}
|
|
|
|
|
static bool json_field_fixed_bool_reader( struct json_pull_parser* jpp, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
static bool json_field_bool_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
bool val = json_pull_parser_read_bool( jpp, (bool*)field_data );
|
|
|
|
|
return val == json_field_data->fixed_bool;
|
|
|
|
|
bool value = *(bool*)(field_data);
|
|
|
|
|
if( !json_field_data->always_write ) {
|
|
|
|
|
if( !json_field_data->required && !value ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json_write_field_name( jw, field_name );
|
|
|
|
|
fprintf( jw->f, value ? "true" : "false" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
struct json_field_type json_field_bool = {
|
|
|
|
|
.reader = json_field_bool_reader,
|
|
|
|
|
.writer = json_field_bool_writer,
|
|
|
|
|
.size = sizeof(bool),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool json_field_bool_or_null_reader( struct json_pull_parser* jpp, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
*(bool*)field_data = false;
|
|
|
|
@ -31,43 +46,34 @@ static bool json_field_bool_or_null_reader( struct json_pull_parser* jpp, void*
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
static bool json_field_fixed_bool_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
bool value = json_field_data->fixed_bool;
|
|
|
|
|
struct json_field_type json_field_bool_or_null = {
|
|
|
|
|
.reader = json_field_bool_or_null_reader,
|
|
|
|
|
.writer = json_field_bool_writer,
|
|
|
|
|
.size = sizeof(bool),
|
|
|
|
|
.type_string = "bool_or_null",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
json_write_field_name( jw, field_name );
|
|
|
|
|
fprintf( jw->f, value ? "true" : "false" );
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
static bool json_field_fixed_bool_reader( struct json_pull_parser* jpp, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
bool val = json_pull_parser_read_bool( jpp, (bool*)field_data );
|
|
|
|
|
return val == json_field_data->fixed_bool;
|
|
|
|
|
}
|
|
|
|
|
static bool json_field_bool_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
static bool json_field_fixed_bool_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
bool value = *(bool*)(field_data);
|
|
|
|
|
if( !json_field_data->always_write ) {
|
|
|
|
|
if( !json_field_data->required && !value ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool value = json_field_data->fixed_bool;
|
|
|
|
|
|
|
|
|
|
json_write_field_name( jw, field_name );
|
|
|
|
|
fprintf( jw->f, value ? "true" : "false" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
struct json_field_type json_field_bool = {
|
|
|
|
|
.reader = json_field_bool_reader,
|
|
|
|
|
.writer = json_field_bool_writer,
|
|
|
|
|
.size = sizeof(bool),
|
|
|
|
|
};
|
|
|
|
|
struct json_field_type json_field_fixed_bool = {
|
|
|
|
|
.reader = json_field_fixed_bool_reader,
|
|
|
|
|
.writer = json_field_fixed_bool_writer,
|
|
|
|
|
.size = sizeof(bool),
|
|
|
|
|
};
|
|
|
|
|
struct json_field_type json_field_bool_or_null = {
|
|
|
|
|
.reader = json_field_bool_or_null_reader,
|
|
|
|
|
.writer = json_field_bool_writer,
|
|
|
|
|
.size = sizeof(bool),
|
|
|
|
|
.type_string = "bool_or_null",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool json_field_bool_callback_reader( struct json_pull_parser* jpp, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
@ -96,3 +102,32 @@ struct json_field_type json_field_bool_callback = {
|
|
|
|
|
.type_string = "bool",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool json_field_rich_bool_reader( struct json_pull_parser* jpp, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
struct rich_bool* rb = field_data;
|
|
|
|
|
bool value;
|
|
|
|
|
bool result = json_pull_parser_read_bool( jpp, &value );
|
|
|
|
|
|
|
|
|
|
rb->value = value;
|
|
|
|
|
rb->visible = result;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
static bool json_field_rich_bool_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_reflection* json_field_data, int offset )
|
|
|
|
|
{
|
|
|
|
|
struct rich_bool* rb = field_data;
|
|
|
|
|
|
|
|
|
|
if( !rb->visible ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json_write_field_name( jw, field_name );
|
|
|
|
|
fprintf( jw->f, rb->value ? "true" : "false" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
struct json_field_type json_field_rich_bool = {
|
|
|
|
|
.reader = json_field_rich_bool_reader,
|
|
|
|
|
.writer = json_field_rich_bool_writer,
|
|
|
|
|
.size = sizeof(bool),
|
|
|
|
|
};
|
|
|
|
|