예제 #1
0
/*
 * tnt_update_splice()
 *
 * write update splice operation to buffer stream;
 *
 * s      - stream buffer pointer
 * field  - field number
 * offset - splice offset
 * length - splice length
 * data   - splice operation data
 * value  - splice operation data size
 * 
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_update_splice(struct tnt_stream *s, uint32_t field,
		  uint32_t offset,
		  int32_t length, char *data, size_t size)
{
	/* calculating splice data sizes */
	uint32_t offset_len = tnt_enc_size(sizeof(offset)),
	         length_len = tnt_enc_size(sizeof(length)),
	         data_len   = tnt_enc_size(size);
	uint32_t sz = offset_len + sizeof(offset) +
		      length_len + sizeof(length) + data_len + size;
	/* allocating splice request buffer */
	char *buf = tnt_mem_alloc(sz);
	if (buf == NULL)
		return -1;
	/* filling splice request data */
	char *p = buf;
	tnt_enc_write(p, sizeof(offset));
	p += offset_len;
	memcpy(p, &offset, sizeof(offset));
	p += sizeof(offset);
	tnt_enc_write(p, sizeof(length));
	p += length_len;
	memcpy(p, &length, sizeof(length));
	p += sizeof(length);
	tnt_enc_write(p, size);
	p += data_len;
	memcpy(p, data, size);
	p += size;
	/* writing splice request */
	ssize_t rc = tnt_update_op(s, field, TNT_UPDATE_SPLICE, buf, sz);
	tnt_mem_free(buf);
	return rc;
}
예제 #2
0
ssize_t
tnt_update_delete(struct tnt_stream *ops, uint32_t fieldno,
		  uint32_t fieldcount) {
	char body[10], *data; data = body;
	data = mp_encode_uint(data, fieldcount);
	return tnt_update_op(ops, '#', fieldno, body, data - body);
}
예제 #3
0
ssize_t
tnt_update_assign(struct tnt_stream *ops, uint32_t fieldno,
		  struct tnt_stream *val) {
	if (tnt_object_verify(val, -1))
		return -1;
	return tnt_update_op(ops, '=', fieldno, TNT_SBUF_DATA(val),
			     TNT_SBUF_SIZE(val));
}
예제 #4
0
ssize_t
tnt_update_arith_double(struct tnt_stream *ops, uint32_t fieldno, char op,
		        double value) {
	if (op != '+' && op != '-') return -1;
	char body[10], *data; data = body;
	data = mp_encode_double(data, value);
	return tnt_update_op(ops, op, fieldno, body, data - body);
}
예제 #5
0
ssize_t
tnt_update_bit(struct tnt_stream *ops, uint32_t fieldno, char op,
	       uint64_t value) {
	if (op != '&' && op != '^' && op != '|') return -1;
	char body[10], *data; data = body;
	data = mp_encode_uint(data, value);
	return tnt_update_op(ops, op, fieldno, body, data - body);
}
예제 #6
0
ssize_t
tnt_update_arith_int(struct tnt_stream *ops, uint32_t fieldno, char op,
		     int64_t value) {
	if (op != '+' && op != '-') return -1;
	char body[10], *data; data = body;
	if (value >= 0)
		data = mp_encode_uint(data, value);
	else
		data = mp_encode_int(data, value);
	return tnt_update_op(ops, op, fieldno, body, data - body);
}
예제 #7
0
ssize_t
tnt_update_splice(struct tnt_stream *ops, uint32_t fieldno,
		  uint32_t position, uint32_t offset,
		  const char *buffer, size_t buffer_len) {
	size_t buf_size = mp_sizeof_uint(position) +
		          mp_sizeof_uint(offset) +
			  mp_sizeof_str(buffer_len);
	char *buf = tnt_mem_alloc(buf_size), *data = NULL;
	if (!buf) return -1;
	data = buf;
	data = mp_encode_uint(data, position);
	data = mp_encode_uint(data, offset);
	data = mp_encode_str(data, buffer, buffer_len);
	ssize_t retval = tnt_update_op(ops, ':', fieldno, buf, buf_size);
	tnt_mem_free(buf);
	return retval;
}
예제 #8
0
/*
 * tnt_update_arith_i32()
 *
 * write 32-bit arithmetic update operation to buffer stream;
 *
 * s     - stream buffer pointer
 * field - field number
 * op    - update operation type
 * value - update operation value
 * 
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_update_arith_i32(struct tnt_stream *s, uint32_t field,
		     uint8_t op, uint32_t value)
{
	return tnt_update_op(s, field, op, (char*)&value, sizeof(value));
}
예제 #9
0
ssize_t
tnt_update_insert(struct tnt_stream *s, uint32_t field,
			 char *data, uint32_t size)
{
	return tnt_update_op(s, field, TNT_UPDATE_INSERT, data, size);
}
예제 #10
0
/*
 * tnt_update_delete()
 *
 * write update delete operation to buffer stream;
 *
 * s      - stream buffer pointer
 * field  - field number
 *
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_update_delete(struct tnt_stream *s, uint32_t field)
{
	return tnt_update_op(s, field, TNT_UPDATE_DELETE, NULL, 0);
}
예제 #11
0
/*
 * tnt_update_assign()
 *
 * write assign update operation to buffer stream;
 *
 * s     - stream buffer pointer
 * field - field number
 * data  - update operation data
 * value - update operation data size
 * 
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_update_assign(struct tnt_stream *s, uint32_t field,
		  char *data, uint32_t size)
{
	return tnt_update_op(s, field, TNT_UPDATE_ASSIGN, data, size);
}