Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
// Reads a MessagePack integer value from memory and sets the value to the
// given memory location.
//
// target - The place where the integer should be written to.
// value  - The memory location where a MessagePack encoded int is located.
// sz     - A pointer to where the number of bytes read should be returned.
//
// Returns nothing.
void sky_data_descriptor_set_int(void *target, void *value, size_t *sz)
{
    *((int64_t*)target) = minipack_unpack_int(value, sz);
}
Ejemplo n.º 3
0
// Deserializes event data from memory at the current pointer.
//
// data - The event data to unpack into.
// ptr  - The pointer to the current location.
// sz   - The number of bytes read.
//
// Returns 0 if successful, otherwise returns -1.
int sky_event_data_unpack(sky_event_data *data, void *ptr, size_t *sz)
{
    size_t _sz;
    void *start = ptr;
    
    // Validate.
    check(data != NULL, "Event data required");
    check(ptr != NULL, "Pointer required");

    // Read key.
    data->key = *((sky_property_id_t*)ptr);
    ptr += sizeof(data->key);

    // If there is no data type set then determine it from the data.
    if(data->data_type == SKY_DATA_TYPE_NONE) {
        if(minipack_is_raw(ptr)) {
            data->data_type = SKY_DATA_TYPE_STRING;
        }
        else if(minipack_is_bool(ptr)) {
            data->data_type = SKY_DATA_TYPE_BOOLEAN;
        }
        else if(minipack_is_double(ptr)) {
            data->data_type = SKY_DATA_TYPE_DOUBLE;
        }
        else {
            data->data_type = SKY_DATA_TYPE_INT;
        }
    }

    // Read value.
    if(data->data_type == SKY_DATA_TYPE_INT) {
        data->int_value = minipack_unpack_int(ptr, &_sz);
        check(_sz != 0, "Unable to unpack event int value");
        ptr += _sz;
    }
    else if(data->data_type == SKY_DATA_TYPE_DOUBLE) {
        data->double_value = minipack_unpack_double(ptr, &_sz);
        check(_sz != 0, "Unable to unpack event float value");
        ptr += _sz;
    }
    else if(data->data_type == SKY_DATA_TYPE_BOOLEAN) {
        data->boolean_value = minipack_unpack_bool(ptr, &_sz);
        check(_sz != 0, "Unable to unpack event boolean value");
        ptr += _sz;
    }
    else if(data->data_type == SKY_DATA_TYPE_STRING) {
        // Read raw header.
        uint32_t value_length = minipack_unpack_raw(ptr, &_sz);
        check(_sz != 0, "Unable to unpack event value header at %p", ptr);
        ptr += _sz;

        // Read raw data.
        data->string_value = blk2bstr(ptr, value_length); check_mem(data->string_value);
        ptr += value_length;
    }
    else {
        sentinel("Invalid data type (%d) for event data", data->data_type);
    }

    // Store number of bytes read.
    if(sz != NULL) *sz = (ptr-start);
    
    return 0;

error:
    *sz = 0;
    return -1;
}