You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
#include "../../object.h"
|
|
|
|
#include "json/json.h"
|
|
|
|
#include <string.h>
|
|
|
|
#define OBJ_TYPE struct ap_activity_source
|
|
struct json_object_field ap_activity_source_layout[] = {
|
|
JSON_FIELD_STRING( content, true ),
|
|
JSON_FIELD_STRING( mime_type, false ),
|
|
JSON_FIELD_END,
|
|
};
|
|
#undef OBJ_TYPE
|
|
|
|
bool ap_activity_source_reader( struct json_pull_parser* jpp, void* field_data, struct json_object_field* layout_field_data )
|
|
{
|
|
struct ap_activity_source* src = field_data;
|
|
|
|
// If only a string is provided, that is the value field
|
|
char* data = json_pull_parser_read_string(jpp);
|
|
if( data ) {
|
|
memset(src,0,sizeof(*src));
|
|
src->content = data;
|
|
return true;
|
|
}
|
|
|
|
printf( "Reading suource as object\n" );
|
|
return json_read_object_layout( jpp, ap_activity_source_layout, src );
|
|
}
|
|
bool ap_activity_source_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_object_field* layout_field_data )
|
|
{
|
|
struct ap_activity_source* src = field_data;
|
|
|
|
|
|
// Collapse to simple string if no additional properties are present
|
|
if( !src->mime_type ) {
|
|
if( !src->content ) {
|
|
return false;
|
|
} else {
|
|
json_write_field_name( jw, field_name );
|
|
json_write_string( jw->f, src->content );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
json_write_field_name( jw, field_name );
|
|
json_write_pretty_object_layout( jw, ap_activity_source_layout, src );
|
|
return true;
|
|
}
|
|
|
|
struct json_field_type ap_activity_source_type = {
|
|
.reader = ap_activity_source_reader,
|
|
.writer = ap_activity_source_writer,
|
|
};
|
|
|