本文整理汇总了C++中ei_decode_version函数的典型用法代码示例。如果您正苦于以下问题:C++ ei_decode_version函数的具体用法?C++ ei_decode_version怎么用?C++ ei_decode_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ei_decode_version函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ei_rpc
/*
* A true RPC. It return a NULL pointer
* in case of failure, otherwise a valid
* (ETERM *) pointer containing the reply
*/
int ei_rpc(ei_cnode* ec, int fd, char *mod, char *fun,
const char* inbuf, int inbuflen, ei_x_buff* x)
{
int i, index;
ei_term t;
erlang_msg msg;
char rex[MAXATOMLEN];
if (ei_rpc_to(ec, fd, mod, fun, inbuf, inbuflen) < 0) {
return -1;
}
/* FIXME are we not to reply to the tick? */
while ((i = ei_rpc_from(ec, fd, ERL_NO_TIMEOUT, &msg, x)) == ERL_TICK)
;
if (i == ERL_ERROR) return -1;
/*ep = 'erl'_element(2,emsg.msg);*/ /* {RPC_Tag, RPC_Reply} */
index = 0;
if (ei_decode_version(x->buff, &index, &i) < 0
|| ei_decode_ei_term(x->buff, &index, &t) < 0)
return -1; /* FIXME ei_decode_version don't set erl_errno as before */
/* FIXME this is strange, we don't check correct "rex" atom
and we let it pass if not ERL_SMALL_TUPLE_EXT and arity == 2 */
if (t.ei_type == ERL_SMALL_TUPLE_EXT && t.arity == 2)
if (ei_decode_atom(x->buff, &index, rex) < 0)
return -1;
/* remove header */
x->index -= index;
memmove(x->buff, &x->buff[index], x->index);
return 0;
}
开发者ID:616050468,项目名称:otp,代码行数:36,代码来源:ei_connect.c
示例2: outputv
static void outputv(ErlDrvData handle, ErlIOVec *ev) {
ErlDrvPort port = (ErlDrvPort) handle;
SysIOVec *bin;
int i, n, index = 0;
unsigned long hash;
unsigned long seed;
//first piece of the iovec is the seed
// printf("ev->size %d\n", ev->size);
// printf("ev-vsize %d\n", ev->vsize);
//apparently we start counting at 1 round here?
bin = &ev->iov[1];
// printf("bin->orig_size %d\n", bin->iov_len);
// printf("bin->iov_base %s\n", bin->iov_base);
ei_decode_version(bin->iov_base, &index, NULL);
ei_decode_ulong(bin->iov_base, &index, &seed);
hash = (unsigned int) seed;
if (index < bin->iov_len) {
hash = MurmurHash2(&bin->iov_base[index], bin->iov_len - index, hash);
}
// printf("hash %d\n", hash);
for (i=2; i<ev->vsize; i++) {
bin = &ev->iov[i];
// printf("bin->orig_size %d\n", bin->iov_len);
hash = MurmurHash2(bin->iov_base, bin->iov_len, hash);
// printf("hashed %d\n", i);
}
send_hash(port, hash);
}
开发者ID:Jasson,项目名称:devdb,代码行数:28,代码来源:murmur_drv.c
示例3: 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");
}
开发者ID:tomaon,项目名称:ergen,代码行数:25,代码来源:ERGenDM_drv.C
示例4: get_bin_term
/*
* Reads an Erlang term.
*
* Only accepts 't' (term) or 'e' (end of test),
* exits program on error
* returns 1 on 'e', 0 on 't'
*/
int get_bin_term(ei_x_buff* x, ei_term* term)
{
int len, version;
ei_x_free(x);
x->buff = read_packet(&len);
x->buffsz = len;
x->index = 0;
switch (x->buff[x->index++]) {
case 'e':
return 1;
case 't':
if (ei_decode_version(x->buff, &x->index, &version) < 0
|| ei_decode_ei_term(x->buff, &x->index, term) < 0) {
fail("Failed to decode term");
exit(0);
}
return 0;
default:
fprintf(stderr, "Garbage received: ");
dump(x->buff, len, 16);
putc('\n', stderr);
fail("C program received garbage");
exit(1);
}
}
开发者ID:3112517927,项目名称:otp,代码行数:33,代码来源:ei_runner.c
示例5: prepared_clear_bindings
static int prepared_clear_bindings(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
unsigned int prepared_index;
long long_prepared_index;
int index = 0;
sqlite3_stmt *statement;
ei_decode_version(buffer, &index, NULL);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
#ifdef DEBUG
fprintf(drv->log, "Tried to clear bindings of prepared statement #%d, but maximum possible is #%d\n", prepared_index, drv->prepared_count - 1);
fflush(drv->log);
#endif
return output_error(drv, SQLITE_MISUSE,
"Trying to clear bindings of non-existent prepared statement");
}
#ifdef DEBUG
fprintf(drv->log, "Clearing bindings of prepared statement #%d\n", prepared_index);
fflush(drv->log);
#endif
statement = drv->prepared_stmts[prepared_index];
sqlite3_clear_bindings(statement);
return output_ok(drv);
}
开发者ID:mwpark,项目名称:sqlite-erlang,代码行数:27,代码来源:sqlite3_drv.c
示例6: prepared_finalize
static int prepared_finalize(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
unsigned int prepared_index;
long long_prepared_index;
int index = 0;
ei_decode_version(buffer, &index, NULL);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
#ifdef DEBUG
fprintf(drv->log, "Tried to finalize prepared statement #%d, but maximum possible is #%d\n", prepared_index, drv->prepared_count - 1);
fflush(drv->log);
#endif
return output_error(drv, SQLITE_MISUSE,
"Trying to finalize non-existent prepared statement");
}
#ifdef DEBUG
fprintf(drv->log, "Finalizing prepared statement #%d\n", prepared_index);
fflush(drv->log);
#endif
// finalize the statement and make sure it isn't accidentally executed again
sqlite3_finalize(drv->prepared_stmts[prepared_index]);
drv->prepared_stmts[prepared_index] = NULL;
// if the statement is at the end of the array, space can be reused;
// otherwise don't bother
if (prepared_index == drv->prepared_count - 1) {
drv->prepared_count--;
}
return output_ok(drv);
}
开发者ID:mwpark,项目名称:sqlite-erlang,代码行数:33,代码来源:sqlite3_drv.c
示例7: 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);
}
开发者ID:johnhamelink,项目名称:nerves_uart,代码行数:32,代码来源:nerves_uart.c
示例8: prepared_reset
static int prepared_reset(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
unsigned int prepared_index;
long long_prepared_index;
int index = 0;
sqlite3_stmt *statement;
ei_decode_version(buffer, &index, NULL);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
#ifdef DEBUG
fprintf(drv->log, "Tried to reset prepared statement #%d, but maximum possible is #%d\n", prepared_index, drv->prepared_count - 1);
fflush(drv->log);
#endif
return output_error(drv, SQLITE_MISUSE,
"Trying to reset non-existent prepared statement");
}
#ifdef DEBUG
fprintf(drv->log, "Resetting prepared statement #%d\n", prepared_index);
fflush(drv->log);
#endif
// don't bother about error code, any errors should already be shown by step
statement = drv->prepared_stmts[prepared_index];
sqlite3_reset(statement);
return output_ok(drv);
}
开发者ID:mwpark,项目名称:sqlite-erlang,代码行数:28,代码来源:sqlite3_drv.c
示例9: 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
}
}
开发者ID:mwpark,项目名称:sqlite-erlang,代码行数:32,代码来源:sqlite3_drv.c
示例10: 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};
}
}
开发者ID:mjamroz90,项目名称:erlCrawler,代码行数:28,代码来源:parse_html_driver.cpp
示例11: 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");
}
开发者ID:alepharchives,项目名称:ef_gd,代码行数:35,代码来源:gd_drv.c
示例12: reply
static void reply(erlang_msg *msg, ei_x_buff *recv_x_buf) {
int index = 0;
int version;
ei_decode_version(recv_x_buf->buff, &index, &version);
send_replies(recv_x_buf->buff, &index);
}
开发者ID:616050468,项目名称:gtknode,代码行数:7,代码来源:gtknode_cnode.c
示例13: 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");
}
开发者ID:alepharchives,项目名称:ef_gd,代码行数:34,代码来源:gd_drv.c
示例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;
}
开发者ID:trimnguye,项目名称:ChatServer,代码行数:59,代码来源:iconv_erl.c
示例15: erl_self
ETERM *erl_global_whereis(int fd, const char *name, char *node)
{
char buf[EISMALLBUF];
char *bufp=buf;
char tmpbuf[64];
int index = 0;
erlang_pid *self = erl_self();
erlang_pid epid;
ETERM *opid;
erlang_msg msg;
int i;
int version,arity,msglen;
self->num = fd; /* FIXME looks strange to change something?! */
ei_encode_version(buf,&index);
ei_encode_tuple_header(buf,&index,2);
ei_encode_pid(buf,&index,self); /* PidFrom */
ei_encode_tuple_header(buf,&index,5);
ei_encode_atom(buf,&index,"call"); /* call */
ei_encode_atom(buf,&index,"global"); /* Mod */
ei_encode_atom(buf,&index,"whereis_name"); /* Fun */
ei_encode_list_header(buf,&index,1); /* Args: [ name ] */
ei_encode_atom(buf,&index,name);
ei_encode_empty_list(buf,&index);
ei_encode_atom(buf,&index,"user"); /* user */
/* make the rpc call */
if (ei_send_reg_encoded(fd,self,"rex",buf,index)) return NULL;
while (1) {
index = EISMALLBUF;
if (!(i = ei_recv_internal(fd,&bufp,&index,&msg,&msglen,1,0))) continue;
else break;
}
if (i != ERL_SEND) return NULL;
/* expecting { rex, pid } */
index = 0;
if (ei_decode_version(buf,&index,&version)
|| ei_decode_tuple_header(buf,&index,&arity)
|| (arity != 2)
|| ei_decode_atom(buf,&index,tmpbuf)
|| strcmp(tmpbuf,"rex")
|| ei_decode_pid(buf,&index,&epid))
return NULL; /* bad response from other side */
/* put the pid into a format for the caller */
index = 0;
ei_encode_pid(buf,&index,&epid);
opid = erl_decode((unsigned char*)buf);
/* extract the nodename for the caller */
if (node) strcpy(node,epid.node);
return opid;
}
开发者ID:system,项目名称:erlang-otp,代码行数:58,代码来源:global_whereis.c
示例16: main
/*-----------------------------------------------------------------
* MAIN
*----------------------------------------------------------------*/
int main(int argc, char *argv[])
{
byte* buf;
int size = BUF_SIZE;
if (argc > 1) {
test(argc, argv);
return 0;
}
fprintf(stderr, "gssapi started\r\n");
if ((buf = malloc(size)) == NULL)
return -1;
while ( (buf = read_cmd(buf, &size)) ) {
int res = 0;
int index = 0;
int version, arity;
char command[MAXATOMLEN];
ei_x_buff result;
port_func func;
/* Ensure that we are receiving the binary term by reading and
* stripping the version byte */
EI(ei_decode_version(buf, &index, &version));
/* Our marshalling spec is that we are expecting a tuple {Command, Arg1} */
EI(ei_decode_tuple_header(buf, &index, &arity));
EI(arity != 2);
EI(ei_decode_atom(buf, &index, command));
/* Prepare the output buffer that will hold {ok, Result} or {error, Reason} */
EI(ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2));
/* fprintf(stderr, "command: %s\r\n", command); */
func = lookup_func(command);
if (func) {
res = func(buf, index, &result);
} else {
EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unsupported_command"));
}
write_cmd(&result);
ei_x_free(&result);
}
/* error: */
fprintf(stderr, "No more command, exiting\r\n");
return 0;
}
开发者ID:GlenWalker,项目名称:egssapi,代码行数:59,代码来源:gssapi_drv.c
示例17: eqmlTerm
eqmlTerm(const char * buf, int index = 0) : _buf(buf), _index(index)
{
if (index == 0)
ei_decode_version(_buf, &_index, NULL);
ei_get_type(_buf, &_index, &_type, &_size);
if (isTuple())
ei_decode_tuple_header(_buf, &_index, &_arity);
}
开发者ID:krant,项目名称:eqml,代码行数:10,代码来源:eqml.cpp
示例18: xbuff2xavp
int xbuff2xavp(sr_xavp_t **xavp, ei_x_buff *xbuff)
{
int i=0, version=0;
if (ei_decode_version(xbuff->buff,&i,&version))
{
LM_DBG("no version byte encoded in reply\n");
}
return xavp_decode(xbuff,&i,xavp,0);
}
开发者ID:GreenfieldTech,项目名称:kamailio,代码行数:10,代码来源:erl_api.c
示例19: init_state
// =============================================================================
// Utility functions
// =============================================================================
void init_state(state *st, char *args, int argslen) {
st->index = 0;
st->version = 0;
st->args = args;
st->argslen = argslen;
ei_decode_version(st->args, &(st->index), &(st->version));
assert(st->version != 0);
assert(st->index != 0);
ei_x_new_with_version(&(st->eixb));
}
开发者ID:Ma3aXuCT,项目名称:cecho,代码行数:13,代码来源:cecho.c
示例20: test_drv_call
static ErlDrvSSizeT test_drv_call(ErlDrvData drv_data, unsigned int command, char *buf, ErlDrvSizeT len, char **rbuf, ErlDrvSizeT rlen, unsigned int *flags) {
int index = 0, vsn;
char arg, res;
ei_decode_version(buf, &index, &vsn);
ei_decode_char(buf, &index, &arg);
res = (char) do_f((char) command, arg);
index = 0;
ei_encode_version(*rbuf, &index);
ei_encode_char(*rbuf, &index, res);
return index+1;
}
开发者ID:erszcz,项目名称:tracerl,代码行数:11,代码来源:test_driver.c
注:本文中的ei_decode_version函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论