コード例 #1
0
ファイル: riakdrv.c プロジェクト: dhull/riak-c-driver
int riak_put(RIAK_CONN * connstruct, char * bucket, char * key, char * data) {
	RpbPutReq putReq;
	RpbContent content;
	RpbPutResp * putResp;
	RpbErrorResp * errorResp;
	int reqSize;
	char * buffer;
	RIAK_OP command, result;

	rpb_put_req__init(&putReq);
	rpb_content__init(&content);

	putReq.bucket.data = bucket;
	putReq.bucket.len = strlen(bucket);
	putReq.key.data = key;
	putReq.key.len = strlen(key);
	content.value.data = data;
	content.value.len = strlen(data);
	content.links = NULL;
	content.usermeta = NULL;
	putReq.content = &content;

	reqSize = rpb_put_req__get_packed_size(&putReq);
	buffer = malloc(reqSize);
	rpb_put_req__pack(&putReq,buffer);

	command.msgcode = RPB_PUT_REQ;
	command.msg = buffer;
	command.length = reqSize+1;
	result.msg = NULL;

	connstruct->last_error = RERR_OK;

	if(riak_exec_op(connstruct, &command, &result)!=0)
		return 1;

	/* Received correct response */
	if(result.msgcode == RPB_PUT_RESP) {
		/* not used right now */
		/*putResp = rpb_put_resp__unpack(NULL, result.length-1, result.msg);

		rpb_put_resp__free_unpacked(putResp, NULL);*/
		/* Riak reported an error */
	} else if(result.msgcode == RPB_ERROR_RESP) {
		errorResp = rpb_error_resp__unpack(NULL, result.length-1, result.msg);

		connstruct->last_error = RERR_BUCKET_LIST;
		riak_copy_error(connstruct, errorResp);

		rpb_error_resp__free_unpacked(errorResp, NULL);
		return 1;
		/* Something really bad happened. :( */
	} else {
		connstruct->last_error = RERR_UNKNOWN;
		return 1;
	}

	return 0;
}
コード例 #2
0
ファイル: riack.c プロジェクト: fumpierrez/riack
void riack_got_error_response(struct RIACK_CLIENT *client, struct RIACK_PB_MSG *msg)
{
	RpbErrorResp *resp;
	ProtobufCAllocator pb_allocator;
	if (msg->msg_code == mc_RpbErrorResp) {
		pb_allocator = riack_pb_allocator(&client->allocator);
		resp = rpb_error_resp__unpack(&pb_allocator, msg->msg_len, msg->msg);
		if (client->last_error) {
			RFREE(client, client->last_error);
		}
		client->last_error_code = resp->errcode;
		riack_copy_buffer_to_string(client, &resp->errmsg, &client->last_error);
		rpb_error_resp__free_unpacked(resp, &pb_allocator);
	}
}