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.

88 lines
2.1 KiB
C

#include "Poll.h"
#include "model/status/poll.h"
#include "json/json.h"
#include "json/layout.h"
extern struct json_field_type api_Emoji_type;
#define OBJ_TYPE struct status_poll_option
struct json_object_field api_PollOption_layout[] = {
JSON_FIELD_STRING( title, false ),
{
.key = "votes_count",
.offset = offsetof( OBJ_TYPE, votes.count ),
.required = true,
.type = &json_field_integer,
},
JSON_FIELD_END,
};
#undef OBJ_TYPE
struct json_field_type api_PollOption_type = {
.reader = json_field_object_type_reader,
.writer = json_field_object_type_writer,
.size = sizeof( struct status* ),
.layout = api_PollOption_layout,
.type_string = "Poll::Option",
};
bool int_to_string_callback( void* field_data, bool is_read, char** res );
#define OBJ_TYPE struct status_poll
struct json_object_field api_Poll_layout[] = {
{
.key = "id",
.offset = offsetof( OBJ_TYPE, id ),
.type = &json_field_callback_string,
.string_callback = int_to_string_callback,
},
JSON_FIELD_DATETIME( expires_at, false ),
JSON_FIELD_FIXED_BOOL( expired, false ),
{
.key = "multiple",
.offset = offsetof( OBJ_TYPE, multiple_choice ),
.required = true,
.type = &json_field_bool,
},
JSON_FIELD_ARRAY_OF_INTS( own_votes, true ),
JSON_FIELD_INTEGER( votes_count, true ),
JSON_FIELD_FIXED_NULL( voters_count ),
JSON_FIELD_BOOL( voted, true ),
{
.key = "options",
.offset = offsetof( OBJ_TYPE, options ),
.type = &json_field_array_of,
.array_item_type = &api_PollOption_type,
},
{
.key = "emojis",
.offset = offsetof( OBJ_TYPE, emoji ),
.required = true,
.type = &json_field_array_of,
.array_item_type = &api_Emoji_type,
},
JSON_FIELD_END,
};
#undef OBJ_TYPE
struct json_field_type api_Poll_type = {
.reader = json_field_object_type_reader,
.writer = json_field_object_type_writer,
.size = sizeof( struct status* ),
.layout = api_Poll_layout,
.type_string = "Poll",
};
void api_Poll_write( struct status_poll* poll, FILE* f, int indent )
{
struct json_writer jw = {
.f = f,
.indentation = "\t",
.indent = indent,
};
json_write_pretty_object_layout( &jw, api_Poll_layout, poll );
}