本文整理汇总了C++中ei_decode_tuple_header函数的典型用法代码示例。如果您正苦于以下问题:C++ ei_decode_tuple_header函数的具体用法?C++ ei_decode_tuple_header怎么用?C++ ei_decode_tuple_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ei_decode_tuple_header函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_pointer
couchfile_pointer_info* read_pointer(char* buf, int pos)
{
//Parse KP pair into a couchfile_pointer_info {K, {ptr, reduce_value, subtreesize}}
couchfile_pointer_info *p = malloc(sizeof(couchfile_pointer_info));
p->writerq_resource = NULL;
//DBG("%u,%u,%u,%u\n", buf[pos+0], buf[pos+1], buf[pos+2], buf[pos+3]);
ei_decode_tuple_header(buf, &pos, NULL); //arity 2
term_to_buf(&p->key, buf, &pos);
ei_decode_tuple_header(buf, &pos, NULL); //arity 3
ei_decode_ulonglong(buf, &pos, (unsigned long long*) &p->pointer);
term_to_buf(&p->reduce_value, buf, &pos);
ei_decode_ulonglong(buf, &pos, (unsigned long long*) &p->subtreesize);
return p;
}
示例2: find_first_gteq
int find_first_gteq(char* buf, int pos, void* key, compare_info* lu, int at_least)
{
int list_arity, inner_arity;
int list_pos = 0, cmp_val;
off_t pair_pos = 0;
if(ei_decode_list_header(buf, &pos, &list_arity) < 0)
{
return ERROR_PARSE;
}
while(list_pos < list_arity)
{
//{<<"key", some other term}
pair_pos = pos; //Save pos of kv/kp pair tuple
if(ei_decode_tuple_header(buf, &pos, &inner_arity) < 0)
{
return ERROR_PARSE;
}
lu->last_cmp_key = (*lu->from_ext)(lu, buf,pos);
cmp_val = (*lu->compare) (lu->last_cmp_key, key);
lu->last_cmp_val = cmp_val;
lu->list_pos = list_pos;
if(cmp_val >= 0 && list_pos >= at_least)
{
break;
}
ei_skip_term(buf, &pos); //skip over the key
ei_skip_term(buf, &pos); //skip over the value
list_pos++;
}
return pair_pos;
}
示例3: cmd_ei_send_funs
static void cmd_ei_send_funs(char* buf, int len)
{
int index = 0, n;
long fd;
erlang_pid pid;
ei_x_buff x;
erlang_fun fun1, fun2;
if (ei_decode_long(buf, &index, &fd) < 0)
fail("expected long");
if (ei_decode_pid(buf, &index, &pid) < 0)
fail("expected pid (node)");
if (ei_decode_tuple_header(buf, &index, &n) < 0)
fail("expected tuple");
if (n != 2)
fail("expected tuple");
if (ei_decode_fun(buf, &index, &fun1) < 0)
fail("expected Fun1");
if (ei_decode_fun(buf, &index, &fun2) < 0)
fail("expected Fun2");
if (ei_x_new_with_version(&x) < 0)
fail("ei_x_new_with_version");
if (ei_x_encode_tuple_header(&x, 2) < 0)
fail("encode tuple header");
if (ei_x_encode_fun(&x, &fun1) < 0)
fail("encode fun1");
if (ei_x_encode_fun(&x, &fun2) < 0)
fail("encode fun2");
free_fun(&fun1);
free_fun(&fun2);
send_errno_result(ei_send(fd, &pid, x.buff, x.index));
ei_x_free(&x);
}
示例4: prepared_bind
static int prepared_bind(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
int result;
unsigned int prepared_index;
long long_prepared_index;
int index = 0, type, size;
sqlite3_stmt *statement;
#ifdef DEBUG
fprintf(drv->log, "Finalizing prepared statement: %.*s\n", buffer_size, buffer);
fflush(drv->log);
#endif
ei_decode_version(buffer, &index, NULL);
ei_decode_tuple_header(buffer, &index, &size);
// assert(size == 2);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
return output_error(drv, SQLITE_MISUSE,
"Trying to bind non-existent prepared statement");
}
statement = drv->prepared_stmts[prepared_index];
result =
bind_parameters(drv, buffer, buffer_size, &index, statement, &type, &size);
if (result == SQLITE_OK) {
return output_ok(drv);
} else {
return result; // error has already been output
}
}
示例5: handle_write
static void handle_write(const char *req, int *req_index)
{
if (!uart_is_open(uart)) {
send_error_response("ebadf");
return;
}
int term_size;
if (ei_decode_tuple_header(req, req_index, &term_size) < 0 ||
term_size != 2)
errx(EXIT_FAILURE, "expecting {data, timeout}");
int term_type;
if (ei_get_type(req, req_index, &term_type, &term_size) < 0 ||
term_type != ERL_BINARY_EXT)
errx(EXIT_FAILURE, "expecting data as a binary");
uint8_t *to_write = malloc(term_size);
long amount_to_write;
if (ei_decode_binary(req, req_index, to_write, &amount_to_write) < 0)
errx(EXIT_FAILURE, "decode binary error?");
long timeout;
if (ei_decode_long(req, req_index, &timeout) < 0)
errx(EXIT_FAILURE, "expecting timeout");
// uart_write always invokes a callback when it completes (error or no error).
uart_write(uart, to_write, amount_to_write, timeout);
}
示例6: resize
static void resize(Cmd *cmd) {
char *buff = cmd->data;
int len = cmd->size;
Gd *gd = cmd->gd;
int index = 0;
unsigned long width, height, srcW, srcH;
gdImagePtr destination = NULL;
ei_decode_version(buff, &index, NULL);
ei_decode_tuple_header(buff, &index, NULL);
ei_decode_ulong(buff, &index, &width);
ei_decode_ulong(buff, &index, &height);
if (NULL == gd->image) {
driver_failure_atom(gd->port, "null_image");
return;
}
srcW = gdImageSX(gd->image);
srcH = gdImageSY(gd->image);
destination = gdImageCreateTrueColor(width, height);
if (NULL == destination) {
driver_failure_posix(gd->port, ENOMEM);
return;
}
gdImageCopyResampled(destination, gd->image, 0, 0, 0, 0, width, height, srcW, srcH);
gdImageDestroy(gd->image);
gd->image = destination;
send_atom(gd->port, "ok");
}
示例7: my_decode_tuple_header
int my_decode_tuple_header(const char *buf, int *index, struct my_obj* obj)
{
int ret = ei_decode_tuple_header(buf, index, &obj->u.arity);
if (ret == 0 && obj)
obj->nterms = obj->u.arity;
return ret;
}
示例8: crop
static void crop(Cmd *cmd) {
char *buff = cmd->data;
int len = cmd->size;
Gd *gd = cmd->gd;
int index = 0;
long width, height;
int srcW, srcH, srcX, srcY, destX, destY, playX, playY;
gdImagePtr destination = NULL;
ei_decode_version(buff, &index, NULL);
ei_decode_tuple_header(buff, &index, NULL);
ei_decode_long(buff, &index, &width);
ei_decode_long(buff, &index, &height);
if (NULL == gd->image) {
driver_failure_atom(gd->port, "null_image");
return;
}
srcW = gdImageSX(gd->image);
srcH = gdImageSY(gd->image);
destination = gdImageCreateTrueColor(width, height);
if (NULL == destination) {
driver_failure_posix(gd->port, ENOMEM);
return;
}
gdImageFilledRectangle(destination, 0, 0, width, height, gdImageColorAllocate(destination, 255, 255, 255));
destX = (width - srcW) / 2;
destY = (height - srcH) / 2;
gdImageCopy(destination, gd->image, destX, destY, 0, 0, srcW, srcH);
gdImageDestroy(gd->image);
gd->image = destination;
send_atom(gd->port, "ok");
}
示例9: process_data
decode_result process_data(ErlDrvData handle,unsigned char* buf, ErlDrvSizeT* sz,char*& html_content,char*& url_address){
int index = 0,size=0,type=0,ver=0;
if (ei_decode_version((char*)buf, &index,&ver)){
//data encoding version mismatch
return decode_result{false,std::pair<std::string,std::string>("",""),
"data encoding version mismatch"};
}
else if (ei_get_type((char*)buf,&index,&type,&size)){
//must be a binary
return decode_result{false,std::pair<std::string,std::string>("",""),
"must be a binary"};
} else{
int tuple_arity;
ei_decode_tuple_header((char*)buf,&index,&tuple_arity);
ei_get_type((char*)buf,&index,&type,&size);
url_address = (char*)driver_alloc((size+2)*sizeof(char));
ei_decode_string((char*)buf,&index,url_address);
ei_get_type((char*)buf,&index,&type,&size);
//cout << "Html Content Size " << size << endl;
html_content = (char*)driver_alloc((size+2)*sizeof(char));
ei_decode_string((char*)buf,&index,html_content);
*sz = size;
std::string url_address_str(url_address);
std::string html_content_str(html_content);
return decode_result{true,std::pair<std::string,std::string>(url_address_str,html_content_str),NULL};
}
}
示例10: next_pointer
int next_pointer(GEOSCommand *command, int argc, char *name, void** data) {
int arity;
char atom[MAXATOMLEN];
unsigned long pointer;
//decode tuple
if(ei_decode_tuple_header(command->param_bytes, &command->index, &arity)) {
return -1;
}
//verify if it's the right label
if(arity!=argc) {
return -1;
}
//decode pointer label
if(ei_decode_atom(command->param_bytes,&command->index, atom)) {
return -1;
}
if(strcmp(atom,name)) {
return -1;
}
//decode the pointer
if(ei_decode_ulong(command->param_bytes, &command->index, &pointer)) {
return -1;
}
*data = (void *) pointer;
return 0;
}
示例11: output
static void output(ErlDrvData drv_data, char *buf, ErlDrvSizeT) {
driver_data_t *data = (driver_data_t *)drv_data;
int result = 0;
int index = 0, version, arity;
ei_decode_version(buf, &index, &version);
ei_decode_tuple_header(buf, &index, &arity);
if (2 == arity) {
result = ergen_driver_do_txn(data->driver, buf, &index);
if(result) {
ergen_drv_output_bool(data->port, result);
} else {
ergen_drv_output_error1(data->port, "badmatch", "cmd");
}
return;
}
ergen_drv_output_error0(data->port, "badarg");
}
示例12: handle_elixir_request
/**
* @brief Decode and forward requests from Elixir to the appropriate handlers
* @param req the undecoded request
* @param cookie
*/
static void handle_elixir_request(const char *req, void *cookie)
{
(void) cookie;
// Commands are of the form {Command, Arguments}:
// { atom(), term() }
int req_index = sizeof(uint16_t);
if (ei_decode_version(req, &req_index, NULL) < 0)
errx(EXIT_FAILURE, "Message version issue?");
int arity;
if (ei_decode_tuple_header(req, &req_index, &arity) < 0 ||
arity != 2)
errx(EXIT_FAILURE, "expecting {cmd, args} tuple");
char cmd[MAXATOMLEN];
if (ei_decode_atom(req, &req_index, cmd) < 0)
errx(EXIT_FAILURE, "expecting command atom");
for (struct request_handler *rh = request_handlers; rh->name != NULL; rh++) {
if (strcmp(cmd, rh->name) == 0) {
rh->handler(req, &req_index);
return;
}
}
errx(EXIT_FAILURE, "unknown command: %s", cmd);
}
示例13: trace_file_output
/*
** Data sent from erlang to port.
*/
static void trace_file_output(ErlDrvData handle, char *buf,
ErlDrvSizeT len)
{
int index = 1;
ei_print_term(stdout, buf, &index);
erts_printf("\n");
/* erts_printf("output: %d: %u\n", rc, (unsigned char)buff[0]); */
int arity;
char atom[MAXATOMLEN];
char type[MAXATOMLEN];
char pidstr[100];
index = 1;
erlang_pid pid;
if(!ei_decode_tuple_header(buf, &index, &arity)) {
if(!ei_decode_atom(buf, &index, atom)) {
if(strcmp("trace", atom) == 0) {
if(!ei_decode_pid(buf, &index, &pid)) {
if(!ei_decode_atom(buf, &index, type)) {
snprintf(pidstr, 100, "<0.%d.%d>", pid.num, pid.serial);
erts_printf("%s: %s\n", pidstr, type);
dispatch(pidstr, type, index, buf);
}
}
}
}
}
}
示例14: iconv_erl_control
static int iconv_erl_control(ErlDrvData drv_data,
unsigned int command,
char *buf, int len,
char **rbuf, int rlen)
{
int i;
int size;
int index = 0;
int avail;
size_t inleft, outleft;
ErlDrvBinary *b;
char *from, *to, *string, *stmp, *rstring, *rtmp;
iconv_t cd;
ei_decode_version(buf, &index, &i);
ei_decode_tuple_header(buf, &index, &i);
ei_get_type(buf, &index, &i, &size);
from = malloc(size + 1);
ei_decode_string(buf, &index, from);
ei_get_type(buf, &index, &i, &size);
to = malloc(size + 1);
ei_decode_string(buf, &index, to);
ei_get_type(buf, &index, &i, &size);
stmp = string = malloc(size + 1);
ei_decode_string(buf, &index, string);
cd = iconv_open(to, from);
if(cd == (iconv_t) -1)
{
cd = iconv_open("ascii", "ascii");
if(cd == (iconv_t) -1)
{
cd = iconv_open("ascii", "ascii");
}
}
outleft = avail = 4*size;
inleft = size;
rtmp = rstring = malloc(avail);
iconv(cd, &stmp, &inleft, &rtmp, &outleft);
size = rtmp - rstring;
//printf("size=%d, res=%s\r\n", size, rstring);
*rbuf = (char*)(b = driver_alloc_binary(size));
memcpy(b->orig_bytes, rstring, size);
free(from);
free(to);
free(string);
free(rstring);
iconv_close(cd);
return size;
}
示例15: do_wattroff
void do_wattroff(state *st) {
int arity;
long slot, attrs;
ei_decode_tuple_header(st->args, &(st->index), &arity);
ei_decode_long(st->args, &(st->index), &slot);
ei_decode_long(st->args, &(st->index), &attrs);
encode_ok_reply(st, wattroff(st->win[slot], (int)attrs));
}