void grn_output_int64(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, int64_t value) { put_delimiter(ctx, outbuf, output_type); switch (output_type) { case GRN_CONTENT_JSON: grn_text_lltoa(ctx, outbuf, value); break; case GRN_CONTENT_TSV: grn_text_lltoa(ctx, outbuf, value); break; case GRN_CONTENT_XML: GRN_TEXT_PUTS(ctx, outbuf, "<INT>"); grn_text_lltoa(ctx, outbuf, value); GRN_TEXT_PUTS(ctx, outbuf, "</INT>"); break; case GRN_CONTENT_MSGPACK : #ifdef HAVE_MESSAGE_PACK msgpack_pack_int64(&ctx->impl->msgpacker, value); #endif break; case GRN_CONTENT_NONE: break; } INCR_LENGTH; }
static void request_issue_add(uv_stream_t* target, msgpack_packer* pac, int32_t seq, int a, int b){ /* Pack request header */ msgpack_pack_array(pac,4); msgpack_pack_uint64(pac,0); msgpack_pack_uint64(pac,seq); msgpack_pack_raw(pac,3); msgpack_pack_raw_body(pac,"add",3); /* Pack request parameters */ msgpack_pack_array(pac,2); msgpack_pack_int64(pac,a); msgpack_pack_int64(pac,b); /* Send */ uvm_write(&write_nothing_to_do, target, pac); }
/* * Document-method: Bignum#to_msgpack * * call-seq: * bignum.to_msgpack(out = '') -> String * * Serializes the Bignum into raw bytes. */ static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self) { ARG_BUFFER(out, argc, argv); if(RBIGNUM_POSITIVE_P(self)) { msgpack_pack_uint64(out, rb_big2ull(self)); } else { msgpack_pack_int64(out, rb_big2ll(self)); } return out; }
/* * Document-method: Bignum#to_msgpack * * call-seq: * bignum.to_msgpack(out = '') -> String * * Serializes the Bignum into raw bytes. */ static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self) { ARG_BUFFER(out, argc, argv); // FIXME bignum if(RBIGNUM_SIGN(self)) { // positive msgpack_pack_uint64(out, rb_big2ull(self)); } else { // negative msgpack_pack_int64(out, rb_big2ll(self)); } return out; }
void msgpack_rpc_from_position(Position result, msgpack_packer *res) { msgpack_pack_array(res, 2);; msgpack_pack_int64(res, result.row); msgpack_pack_int64(res, result.col); }
void msgpack_rpc_from_integer(Integer result, msgpack_packer *res) { msgpack_pack_int64(res, result); }
static void msgpack_int(CTX ctx, void *pkp, kint_t i) { kpackAPI_t *pk = (kpackAPI_t *)pkp; msgpack_pack_int64(pk->pk, i); }
void MsgpackIODevice::send(int64_t i) { msgpack_pack_int64(&m_pk, i); }
int msgpack_pack_object(msgpack_packer* pk, msgpack_object d) { switch(d.type) { case MSGPACK_OBJECT_NIL: return msgpack_pack_nil(pk); case MSGPACK_OBJECT_BOOLEAN: if(d.via.boolean) { return msgpack_pack_true(pk); } else { return msgpack_pack_false(pk); } case MSGPACK_OBJECT_POSITIVE_INTEGER: return msgpack_pack_uint64(pk, d.via.u64); case MSGPACK_OBJECT_NEGATIVE_INTEGER: return msgpack_pack_int64(pk, d.via.i64); case MSGPACK_OBJECT_FLOAT32: return msgpack_pack_float(pk, (float)d.via.f64); case MSGPACK_OBJECT_FLOAT64: return msgpack_pack_double(pk, d.via.f64); case MSGPACK_OBJECT_STR: { int ret = msgpack_pack_str(pk, d.via.str.size); if(ret < 0) { return ret; } return msgpack_pack_str_body(pk, d.via.str.ptr, d.via.str.size); } case MSGPACK_OBJECT_BIN: { int ret = msgpack_pack_bin(pk, d.via.bin.size); if(ret < 0) { return ret; } return msgpack_pack_bin_body(pk, d.via.bin.ptr, d.via.bin.size); } case MSGPACK_OBJECT_EXT: { int ret = msgpack_pack_ext(pk, d.via.ext.size, d.via.ext.type); if(ret < 0) { return ret; } return msgpack_pack_ext_body(pk, d.via.ext.ptr, d.via.ext.size); } case MSGPACK_OBJECT_ARRAY: { int ret = msgpack_pack_array(pk, d.via.array.size); if(ret < 0) { return ret; } else { msgpack_object* o = d.via.array.ptr; msgpack_object* const oend = d.via.array.ptr + d.via.array.size; for(; o != oend; ++o) { ret = msgpack_pack_object(pk, *o); if(ret < 0) { return ret; } } return 0; } } case MSGPACK_OBJECT_MAP: { int ret = msgpack_pack_map(pk, d.via.map.size); if(ret < 0) { return ret; } else { msgpack_object_kv* kv = d.via.map.ptr; msgpack_object_kv* const kvend = d.via.map.ptr + d.via.map.size; for(; kv != kvend; ++kv) { ret = msgpack_pack_object(pk, kv->key); if(ret < 0) { return ret; } ret = msgpack_pack_object(pk, kv->val); if(ret < 0) { return ret; } } return 0; } } default: return -1; } }
int msgpack_pack_int64_wrap(msgpack_packer* pk, int64_t d) { return msgpack_pack_int64(pk, d); }
/* Receive a tokenized JSON message and convert it to MsgPack */ static char *tokens_to_msgpack(char *js, jsmntok_t *tokens, int arr_size, int *out_size) { int i; int flen; char *p; char *buf; jsmntok_t *t; msgpack_packer pck; msgpack_sbuffer sbuf; /* initialize buffers */ msgpack_sbuffer_init(&sbuf); msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write); for (i = 0; i < arr_size ; i++) { t = &tokens[i]; if (t->start == -1 || t->end == -1 || (t->start == 0 && t->end == 0)) { break; } flen = (t->end - t->start); switch (t->type) { case JSMN_OBJECT: msgpack_pack_map(&pck, t->size); break; case JSMN_ARRAY: msgpack_pack_array(&pck, t->size); break; case JSMN_STRING: msgpack_pack_bin(&pck, flen); msgpack_pack_bin_body(&pck, js + t->start, flen); break; case JSMN_PRIMITIVE: p = js + t->start; if (*p == 'f') { msgpack_pack_false(&pck); } else if (*p == 't') { msgpack_pack_true(&pck); } else if (*p == 'n') { msgpack_pack_nil(&pck); } else { if (is_float(p, flen)) { msgpack_pack_double(&pck, atof(p)); } else { msgpack_pack_int64(&pck, atol(p)); } } break; case JSMN_UNDEFINED: msgpack_sbuffer_destroy(&sbuf); return NULL; } } /* dump data back to a new buffer */ *out_size = sbuf.size; buf = malloc(sbuf.size); memcpy(buf, sbuf.data, sbuf.size); msgpack_sbuffer_destroy(&sbuf); return buf; }
int yar_pack_push_long(yar_packager *packager, long num) /* {{{ */ { msgpack_packer *pk = packager->pk; return msgpack_pack_int64(pk, num) < 0? 0 : 1; }
/* It parse a JSON string and convert it to MessagePack format */ char *flb_pack_json(char *js, size_t len, int *size) { int i; int flen; int arr_size; char *p; char *buf; jsmntok_t *t; jsmntok_t *tokens; msgpack_packer pck; msgpack_sbuffer sbuf; if (!js) { return NULL; } tokens = json_tokenise(js, len, &arr_size); if (!tokens) { return NULL; } flb_debug("JSON to pack: '%s'", js); /* initialize buffers */ msgpack_sbuffer_init(&sbuf); msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write); for (i = 0; i < arr_size ; i++) { t = &tokens[i]; if (t->start == -1 || t->end == -1 || (t->start == 0 && t->end == 0)) { break; } flen = (t->end - t->start); switch (t->type) { case JSMN_OBJECT: flb_debug("json_pack: token=%i is OBJECT (size=%i)", i, t->size); msgpack_pack_map(&pck, t->size); break; case JSMN_ARRAY: flb_debug("json_pack: token=%i is ARRAY (size=%i)", i, t->size); msgpack_pack_array(&pck, t->size); break; case JSMN_STRING: flb_debug("json_pack: token=%i is STRING (len=%i)\n", i, flen); msgpack_pack_bin(&pck, flen); msgpack_pack_bin_body(&pck, js + t->start, flen); break; case JSMN_PRIMITIVE: p = js + t->start; if (strncmp(p, "false", 5) == 0) { flb_debug("json_pack: token=%i is FALSE", i); msgpack_pack_false(&pck); } else if (strncmp(p, "true", 4) == 0) { flb_debug("json_pack: token=%i is TRUE", i); msgpack_pack_true(&pck); } else if (strncmp(p, "null", 4) == 0) { flb_debug("json_pack: token=%i is NULL", i); msgpack_pack_nil(&pck); } else { flb_debug("json_pack: token=%i is INT64", i); msgpack_pack_int64(&pck, atol(p)); } break; } } /* dump data back to a new buffer */ *size = sbuf.size; buf = malloc(sbuf.size); memcpy(buf, sbuf.data, sbuf.size); msgpack_sbuffer_destroy(&sbuf); free(tokens); return buf; }
int msgpack_pack_object(msgpack_packer* pk, msgpack_object d) { switch(d.type) { case MSGPACK_OBJECT_NIL: return msgpack_pack_nil(pk); case MSGPACK_OBJECT_BOOLEAN: if(d.via.boolean) { return msgpack_pack_true(pk); } else { return msgpack_pack_false(pk); } case MSGPACK_OBJECT_POSITIVE_INTEGER: return msgpack_pack_uint64(pk, d.via.u64); case MSGPACK_OBJECT_NEGATIVE_INTEGER: return msgpack_pack_int64(pk, d.via.i64); case MSGPACK_OBJECT_DOUBLE: return msgpack_pack_double(pk, d.via.dec); case MSGPACK_OBJECT_RAW: { int ret = msgpack_pack_raw(pk, d.via.raw.size); if(ret < 0) { return ret; } return msgpack_pack_raw_body(pk, d.via.raw.ptr, d.via.raw.size); } case MSGPACK_OBJECT_ARRAY: { int ret = msgpack_pack_array(pk, d.via.array.size); if(ret < 0) { return ret; } msgpack_object* o = d.via.array.ptr; msgpack_object* const oend = d.via.array.ptr + d.via.array.size; for(; o != oend; ++o) { ret = msgpack_pack_object(pk, *o); if(ret < 0) { return ret; } } return 0; } case MSGPACK_OBJECT_MAP: { int ret = msgpack_pack_map(pk, d.via.map.size); if(ret < 0) { return ret; } msgpack_object_kv* kv = d.via.map.ptr; msgpack_object_kv* const kvend = d.via.map.ptr + d.via.map.size; for(; kv != kvend; ++kv) { ret = msgpack_pack_object(pk, kv->key); if(ret < 0) { return ret; } ret = msgpack_pack_object(pk, kv->val); if(ret < 0) { return ret; } } return 0; } default: return -1; } }
void msgpack_rpc_from_int64_t(int64_t result, msgpack_packer *res) { msgpack_pack_int64(res, result); }