Beispiel #1
0
// Performs no operation on the data. Used for skipping over unused properties
// in the descriptor.
//
// target - Unused.
// value  - The memory location where a MessagePack value is encoded.
// sz     - A pointer to where the number of bytes read should be returned.
//
// Returns nothing.
void sky_data_descriptor_set_noop(void *target, void *value, size_t *sz)
{
    check(target != NULL, "Target pointer cannot be null");
    *sz = minipack_sizeof_elem_and_data(value);
    
error:
    return;
}
Beispiel #2
0
int test_sizeof_nil() {
    mu_assert(minipack_sizeof_elem_and_data("\xC0") == 1);
    return 0;
}
Beispiel #3
0
int test_sizeof_int16() {
    mu_assert(minipack_sizeof_elem_and_data("\xD1\x7F\xFF") == 3);
    return 0;
}
Beispiel #4
0
int test_sizeof_raw32() {
    mu_assert(minipack_sizeof_elem_and_data("\xDB\x00\x00\x00\x05") == 10);
    return 0;
}
Beispiel #5
0
int test_sizeof_bool() {
    mu_assert(minipack_sizeof_elem_and_data("\xC3") == 1);
    mu_assert(minipack_sizeof_elem_and_data("\xC2") == 1);
    return 0;
}
Beispiel #6
0
// Retrieves the next event in the cursor.
//
// module - The module.
// cursor - The cursor.
// event  - The event object to update.
//
// Returns nothing.
void sky_qip_cursor_next(qip_module *module, sky_qip_cursor *cursor,
                         sky_qip_event *event)
{
    int rc;
    size_t sz;
    check(module != NULL, "Module required");
    sky_qip_module *_module = (sky_qip_module*)module->context;
    check(_module != NULL, "Wrapped module required");

    // Update the action id on the event.
    sky_action_id_t action_id;
    rc = sky_cursor_get_action_id(cursor->cursor, &action_id);
    check(rc == 0, "Unable to retrieve action id");
    event->action_id = (int64_t)action_id;
    
    // Localize dynamic property info.
    int64_t property_count = _module->event_property_count;
    sky_property_id_t *property_ids = _module->event_property_ids;
    int64_t *property_offsets = _module->event_property_offsets;
    bstring *property_types = _module->event_property_types;

    // Read data block if we have properties attached to the wrapped module.
    uint32_t i;
    if(property_count > 0) {
        void *property_value_ptr;

        // Retrieve pointer to the start of the data portion of the cursor.
        void *data_ptr = NULL;
        uint32_t data_length = 0;
        rc = sky_cursor_get_data_ptr(cursor->cursor, &data_ptr, &data_length);
        check(rc == 0, "Unable to retrieve cursor data pointer");

        // Clear out action properties.
        for(i=0; i<property_count; i++) {
            if(property_ids[i] < 0) {
                property_value_ptr = ((void*)event) + property_offsets[i];
                if(property_types[i] == &SKY_DATA_TYPE_INT) {
                    *((int64_t*)property_value_ptr) = 0;
                }
                else if(property_types[i] == &SKY_DATA_TYPE_FLOAT) {
                    *((double*)property_value_ptr) = 0;
                }
                else if(property_types[i] == &SKY_DATA_TYPE_BOOLEAN) {
                    *((bool*)property_value_ptr) = 0;
                }
                else if(property_types[i] == &SKY_DATA_TYPE_STRING) {
                    qip_string *string_value = (qip_string*)property_value_ptr;
                    string_value->length = 0;
                    string_value->data = NULL;
                }
            }
        }
        
        // Loop over data section until we run out of data.
        void *ptr = data_ptr;
        while(ptr < data_ptr+data_length) {
            // Read property id.
            sky_property_id_t property_id = *((sky_property_id_t*)ptr);
            ptr += sizeof(property_id);
            
            // Initialize size to zero so we know if it was processed.
            sz = 0;

            // Loop over properties on event to check if we need to update.
            for(i=0; i<property_count; i++) {
                if(property_id == property_ids[i]) {
                    property_value_ptr = ((void*)event) + property_offsets[i];
                    
                    // Parse the data by the data type set on the database property.
                    bstring property_type = property_types[i];
                    if(property_type == &SKY_DATA_TYPE_INT) {
                        *((int64_t*)property_value_ptr) = minipack_unpack_int(ptr, &sz);
                        check(sz != 0, "Unable to unpack event int data");
                        ptr += sz;
                        break;
                    }
                    else if(property_type == &SKY_DATA_TYPE_FLOAT) {
                        *((double*)property_value_ptr) = minipack_unpack_double(ptr, &sz);
                        check(sz != 0, "Unable to unpack event float data");
                        ptr += sz;
                        break;
                    }
                    else if(property_type == &SKY_DATA_TYPE_BOOLEAN) {
                        *((bool*)property_value_ptr) = minipack_unpack_bool(ptr, &sz);
                        check(sz != 0, "Unable to unpack event boolean data");
                        ptr += sz;
                        break;
                    }
                    else if(property_type == &SKY_DATA_TYPE_STRING) {
                        qip_string *string_value = (qip_string*)property_value_ptr;
                        string_value->length = minipack_unpack_raw(ptr, &sz);
                        check(sz != 0, "Unable to unpack event string data");
                        ptr += sz;
                        string_value->data = ptr;
                        ptr += string_value->length;
                        break;
                    }
                }
            }
            
            // If the property was not processed then jump ahead to the next
            // property value in the event.
            if(sz == 0) {
                sz = minipack_sizeof_elem_and_data(ptr);
                check(sz > 0, "Invalid data found in event");
                ptr += sz;
            }
        }
    }
    
    // Move to the next event in the cursor.
    sky_cursor_next(cursor->cursor);
    
    return;
    
error:
    cursor->cursor->eof = true;
    return;
}