Рейтинг@Mail.ru

Модуль tuple

Замечание

Документация находится в процессе перевода и может отставать от английской версии.

Модуль tuple

box_tuple_format_t
box_tuple_format_t *box_tuple_format_default(void)

Tuple format.

Each Tuple has associated format (class). Default format is used to create tuples which are not attach to any particular space.

box_tuple_t

Tuple

box_tuple_t *box_tuple_new(box_tuple_format_t *format, const char *tuple, const char *tuple_end)

Allocate and initialize a new tuple from a raw MsgPack Array data.

Параметры:
  • format (box_tuple_format_t*) – tuple format. Use box_tuple_format_default() to create space-independent tuple.
  • char* tuple (const) – tuple data in MsgPack Array format ([field1, field2, …])
  • char* tuple_end (const) – the end of data
Результат:

NULL on out of memory

Результат:

tuple otherwise

See also: box.tuple.new()

int box_tuple_ref(box_tuple_t *tuple)

Increase the reference counter of tuple.

Tuples are reference counted. All functions that return tuples guarantee that the last returned tuple is refcounted internally until the next call to API function that yields or returns another tuple.

You should increase the reference counter before taking tuples for long processing in your code. Such tuples will not be garbage collected even if another fiber remove they from space. After processing please decrement the reference counter using box_tuple_unref(), otherwise the tuple will leak.

Параметры:
Результат:

-1 on error

Результат:

0 otherwise

See also: box_tuple_unref()

void box_tuple_unref(box_tuple_t *tuple)

Decrease the reference counter of tuple.

Параметры:
Результат:

-1 on error

Результат:

0 otherwise

See also: box_tuple_ref()

uint32_t box_tuple_field_count(const box_tuple_t *tuple)

Return the number of fields in tuple (the size of MsgPack Array).

Параметры:
size_t box_tuple_bsize(const box_tuple_t *tuple)

Return the number of bytes used to store internal tuple data (MsgPack Array).

Параметры:
ssize_t box_tuple_to_buf(const box_tuple_t *tuple, char *buf, size_t size)

Dump raw MsgPack data to the memory buffer buf of size size.

Store tuple fields in the memory buffer.

Upon successful return, the function returns the number of bytes written. If buffer size is not enough then the return value is the number of bytes which would have been written if enough space had been available.

Результат:-1 on error
Результат:number of bytes written on success.
box_tuple_format_t *box_tuple_format(const box_tuple_t *tuple)

Return the associated format.

Параметры:
Результат:

tuple format

const char *box_tuple_field(const box_tuple_t *tuple, uint32_t field_id)

Return the raw tuple field in MsgPack format. The result is a pointer to raw MessagePack data which can be decoded with mp_decode functions, for an example see the tutorial program read.c.

The buffer is valid until next call to box_tuple_* functions.

Параметры:
  • tuple (box_tuple_t*) – a tuple
  • field_id (uint32_t) – zero-based index in MsgPack array.
Результат:

NULL if i >= box_tuple_field_count()

Результат:

msgpack otherwise

box_tuple_iterator_t

Tuple iterator

box_tuple_iterator_t *box_tuple_iterator(box_tuple_t *tuple)

Allocate and initialize a new tuple iterator. The tuple iterator allow to iterate over fields at root level of MsgPack array.

Example:

box_tuple_iterator_t* it = box_tuple_iterator(tuple);
if (it == NULL) {
    // error handling using box_error_last()
}
const char* field;
while (field = box_tuple_next(it)) {
    // process raw MsgPack data
}

// rewind iterator to first position
box_tuple_rewind(it)
assert(box_tuple_position(it) == 0);

// rewind three fields
field = box_tuple_seek(it, 3);
assert(box_tuple_position(it) == 4);

box_iterator_free(it);
void box_tuple_iterator_free(box_tuple_iterator_t *it)

Destroy and free tuple iterator

uint32_t box_tuple_position(box_tuple_iterator_t *it)

Return zero-based next position in iterator. That is, this function return the field id of field that will be returned by the next call to box_tuple_next(). Returned value is zero after initialization or rewind and box_tuple_field_count() after the end of iteration.

Параметры:
Результат:

position

void box_tuple_rewind(box_tuple_iterator_t *it)

Rewind iterator to the initial position.

Параметры:

After: box_tuple_position(it) == 0

const char *box_tuple_seek(box_tuple_iterator_t *it, uint32_t field_no)

Seek the tuple iterator.

The result is a pointer to raw MessagePack data which can be decoded with mp_decode functions, for an example see the tutorial program read.c. The returned buffer is valid until next call to box_tuple_* API. Requested field_no returned by next call to box_tuple_next(it).

Параметры:
  • it (box_tuple_iterator_t*) – a tuple iterator
  • field_no (uint32_t) – field number - zero-based position in MsgPack array

After:

  • box_tuple_position(it) == field_not if returned value is not NULL.
  • box_tuple_position(it) == box_tuple_field_count(tuple) if returned value is NULL.
const char *box_tuple_next(box_tuple_iterator_t *it)

Return the next tuple field from tuple iterator.

The result is a pointer to raw MessagePack data which can be decoded with mp_decode functions, for an example see the tutorial program read.c. The returned buffer is valid until next call to box_tuple_* API.

Параметры:
Результат:

NULL if there are no more fields

Результат:

MsgPack otherwise

Before: box_tuple_position() is zero-based ID of returned field.

After: box_tuple_position(it) == box_tuple_field_count(tuple) if returned value is NULL.

box_tuple_t *box_tuple_update(const box_tuple_t *tuple, const char *expr, const char *expr_end)
box_tuple_t *box_tuple_upsert(const box_tuple_t *tuple, const char *expr, const char *expr_end)