Пример #1
0
// Deserializes an 'delete_table' message from a file stream.
//
// message - The message.
// file    - The file stream to read from.
//
// Returns 0 if successful, otherwise returns -1.
int sky_delete_table_message_unpack(sky_delete_table_message *message, FILE *file)
{
    int rc;
    size_t sz;
    bstring key = NULL;
    check(message != NULL, "Message required");
    check(file != NULL, "File stream required");

    // Map
    uint32_t map_length = minipack_fread_map(file, &sz);
    check(sz > 0, "Unable to read map");
    
    // Map items
    uint32_t i;
    for(i=0; i<map_length; i++) {
        rc = sky_minipack_fread_bstring(file, &key);
        check(rc == 0, "Unable to read map key");
        
        if(biseq(key, &SKY_DELETE_TABLE_MESSAGE_NAME_STR)) {
            rc = sky_minipack_fread_bstring(file, &message->name);
            check(rc == 0, "Unable to read table name");
        }

        bdestroy(key);
    }
    
    return 0;

error:
    bdestroy(key);
    return -1;
}
Пример #2
0
// Deserializes an 'lua::aggregate' message from a file stream.
//
// message - The message.
// file    - The file stream to read from.
//
// Returns 0 if successful, otherwise returns -1.
int sky_lua_aggregate_message_unpack(sky_lua_aggregate_message *message,
                                      FILE *file)
{
    int rc;
    size_t sz;
    bstring key = NULL;
    assert(message != NULL);
    assert(file != NULL);

    // Map
    uint32_t map_length = minipack_fread_map(file, &sz);
    check(sz > 0, "Unable to read map");
    
    // Map items
    uint32_t i;
    for(i=0; i<map_length; i++) {
        rc = sky_minipack_fread_bstring(file, &key);
        check(rc == 0, "Unable to read map key");
        
        if(biseq(key, &SKY_LUA_AGGREGATE_KEY_SOURCE) == 1) {
            rc = sky_minipack_fread_bstring(file, &message->source);
            check(rc == 0, "Unable to read source");
        }
        
        bdestroy(key);
        key = NULL;
    }

    return 0;

error:
    bdestroy(key);
    return -1;
}
Пример #3
0
// Deserializes an property from a file stream.
//
// property - The property.
// file   - The file stream to read from.
//
// Returns 0 if successful, otherwise returns -1.
int sky_property_unpack(sky_property *property, FILE *file)
{
    int rc;
    size_t sz;
    bstring key = NULL;
    check(property != NULL, "Message required");
    check(file != NULL, "File stream required");

    // Map
    uint32_t map_length = minipack_fread_map(file, &sz);
    check(sz > 0, "Unable to read map");
    
    // Map items
    uint32_t i;
    for(i=0; i<map_length; i++) {
        rc = sky_minipack_fread_bstring(file, &key);
        check(rc == 0, "Unable to read map key");
        
        if(biseqcstr(key, "id")) {
            int32_t val = minipack_fread_int(file, &sz);
            property->id = (sky_property_id_t)val;
            check(sz > 0, "Unable to read property id");
        }
        else if(biseqcstr(key, "type")) {
            property->type = (sky_property_type_e)minipack_fread_uint(file, &sz);
            check(sz > 0, "Unable to read property type");
        }
        else if(biseqcstr(key, "dataType")) {
            bstring data_type_name = NULL;
            rc = sky_minipack_fread_bstring(file, &data_type_name);
            check(rc == 0, "Unable to read property data type");
            property->data_type = sky_data_type_to_enum(data_type_name);
            bdestroy(data_type_name);
        }
        else if(biseqcstr(key, "name")) {
            rc = sky_minipack_fread_bstring(file, &property->name);
            check(rc == 0, "Unable to read property id");
        }
        
        bdestroy(key);
    }
    
    rc = sky_property_update_type(property);
    check(rc == 0, "Unable to update property type");
    
    return 0;

error:
    bdestroy(key);
    return -1;
}
Пример #4
0
// Deserializes an 'multi' message from a file stream.
//
// message - The message.
// file    - The file stream to read from.
//
// Returns 0 if successful, otherwise returns -1.
int sky_multi_message_unpack(sky_multi_message *message, FILE *file)
{
    int rc;
    size_t sz;
    bstring key = NULL;
    assert(message != NULL);
    assert(file != NULL);

    // Map
    uint32_t map_length = minipack_fread_map(file, &sz);
    check(sz > 0, "Unable to read map");

    // Map items
    uint32_t i;
    for(i=0; i<map_length; i++) {
        rc = sky_minipack_fread_bstring(file, &key);
        check(rc == 0, "Unable to read map key");

        if(biseq(key, &SKY_MULTI_KEY_COUNT_STR) == 1) {
            message->message_count = (uint32_t)minipack_fread_uint(file, &sz);
            check(sz != 0, "Unable to unpack count");
        }

        bdestroy(key);
    }

    return 0;

error:
    bdestroy(key);
    return -1;
}
Пример #5
0
// Deserializes an action from a file stream.
//
// action - The action.
// file   - The file stream to read from.
//
// Returns 0 if successful, otherwise returns -1.
int sky_action_unpack(sky_action *action, FILE *file)
{
    int rc;
    size_t sz;
    bstring key = NULL;
    check(action != NULL, "Message required");
    check(file != NULL, "File stream required");

    // Map
    uint32_t map_length = minipack_fread_map(file, &sz);
    check(sz > 0, "Unable to read map");
    
    // Map items
    uint32_t i;
    for(i=0; i<map_length; i++) {
        rc = sky_minipack_fread_bstring(file, &key);
        check(rc == 0, "Unable to read map key");
        
        if(biseq(key, &SKY_ACTION_ID_STR)) {
            action->id = (sky_action_id_t)minipack_fread_uint(file, &sz);
            check(sz > 0, "Unable to read action id");
        }
        else if(biseq(key, &SKY_ACTION_NAME_STR)) {
            rc = sky_minipack_fread_bstring(file, &action->name);
            check(rc == 0, "Unable to read action id");
        }

        bdestroy(key);
    }
    
    return 0;

error:
    bdestroy(key);
    return -1;
}
Пример #6
0
// Deserializes an PEACH message from a file stream.
//
// message - The message.
// file    - The file stream to read from.
//
// Returns 0 if successful, otherwise returns -1.
int sky_peach_message_unpack(sky_peach_message *message, FILE *file)
{
    int rc;
    check(message != NULL, "Message required");
    check(file != NULL, "File stream required");

    // Query
    rc = sky_minipack_fread_bstring(file, &message->query);
    check(rc == 0, "Unable to read query text");

    return 0;

error:
    return -1;
}
Пример #7
0
// Loads actions from file.
//
// action_file - The action file to load.
//
// Returns 0 if successful, otherwise returns -1.
int sky_action_file_load(sky_action_file *action_file)
{
    int rc;
    size_t sz;
    uint32_t count = 0;
    FILE *file = NULL;
    sky_action **actions = NULL;
    assert(action_file != NULL);
    check(action_file->path != NULL, "Action file path required");

    // Unload any actions currently in memory.
    rc = sky_action_file_unload(action_file);
    check(rc == 0, "Unable to unload action file");

    // Read in actions file if it exists.
    if(sky_file_exists(action_file->path)) {
        file = fopen(bdata(action_file->path), "r");
        check(file, "Failed to open action file: %s",  bdata(action_file->path));

        // Read action count.
        count = minipack_fread_array(file, &sz);
        check(sz != 0, "Unable to read actions array at byte: %ld", ftell(file));

        // Allocate actions.
        if(count > 0) {
            actions = malloc(sizeof(sky_action*) * count);
            check_mem(actions);
        }

        // Read actions.
        uint32_t i;
        for(i=0; i<count; i++) {
            sky_action *action = sky_action_create();
            check_mem(action);

            // Read action id.
            action->id = (sky_action_id_t)minipack_fread_uint(file, &sz);
            check(sz != 0, "Unable to read action identifier at byte: %ld", ftell(file));

            // Read action name.
            rc = sky_minipack_fread_bstring(file, &action->name);
            check(rc == 0, "Unable to read action name at byte: %ld", ftell(file));

            // Append to array.
            action->action_file = action_file;
            actions[i] = action;
        }

        // Close the file.
        fclose(file);
    }

    // Store action list on action file.
    action_file->actions = actions;
    action_file->action_count = count;

    return 0;

error:
    if(file) fclose(file);
    if(actions) free(actions);
    return -1;
}