void report_call_change(struct tcsipcall* call, void *arg) { int cstate, reason; char *ckey = tcsipcall_ckey(call); msgpack_packer *pk = arg; tcsipcall_dirs(call, NULL, &cstate, &reason, NULL); if((cstate & CSTATE_ALIVE) == 0) { tcsipcall_remove(call); // wrong place for this msgpack_pack_array(pk, 3); push_cstr("sip.call.del"); push_cstr_len(ckey); msgpack_pack_int(pk, reason); return; } if(cstate & CSTATE_EST) { msgpack_pack_array(pk, 2); push_cstr("sip.call.est"); push_cstr_len(ckey); return; } }
static apr_status_t log_fluentd_writer(request_rec *r, void *handle, const char **strs, int *strl, int nelts, apr_size_t len) { fluentd_log *log = (fluentd_log *)handle; apr_status_t result; if (log->write_local == 1) { if (log->normal_handle) { result = normal_log_writer(r, log->normal_handle, strs, strl, nelts, len); } } else { int i =0; char *str; msgpack_sbuffer sbuf; msgpack_packer pk; msgpack_sbuffer_init(&sbuf); msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 3); msgpack_pack_raw(&pk,log->tag_len); msgpack_pack_raw_body(&pk, log->tag, log->tag_len); msgpack_pack_int(&pk, 1329275765); msgpack_pack_array(&pk,nelts); for (i = 0; i < nelts; i++) { msgpack_pack_raw(&pk,strl[i]); msgpack_pack_raw_body(&pk, strs[i], strl[i]); } log_fluentd_post(log,&sbuf); msgpack_sbuffer_destroy(&sbuf); } return OK; }
void unit_message_is_response(UNUSED(void **state)) { msgpack_sbuffer sbuf; msgpack_packer pk; msgpack_zone mempool; msgpack_object deserialized; msgpack_sbuffer_init(&sbuf); msgpack_zone_init(&mempool, 2048); /* positiv test */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_pack_uint8(&pk, 0); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_true(message_is_response(&deserialized)); msgpack_sbuffer_clear(&sbuf); /* wrong type test */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 0); msgpack_pack_uint8(&pk, 1); msgpack_pack_uint8(&pk, 1); msgpack_pack_uint8(&pk, 1); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_false(message_is_response(&deserialized)); msgpack_sbuffer_clear(&sbuf); /* no array test */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_uint8(&pk, 1); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_false(message_is_response(&deserialized)); msgpack_sbuffer_clear(&sbuf); /* NULL test */ assert_false(message_is_response(NULL)); msgpack_sbuffer_clear(&sbuf); msgpack_zone_destroy(&mempool); msgpack_sbuffer_destroy(&sbuf); }
void report_lp(int err, struct pl*token, void*arg) { msgpack_packer *pk = arg; if(err ==1 ) { msgpack_pack_array(pk, 3); } else { msgpack_pack_array(pk, 2); } push_cstr("api.login_phone"); msgpack_pack_int(pk, err); if(err==1) push_pl((*token)); }
int mfl_packfn(msgpack_packer * pk, void *mfl) { struct mlockfile_list *itr = mfl; msgpack_pack_array(pk, 2); msgpack_pack_true(pk); msgpack_pack_array(pk, mfl_length(mfl)); while (itr != NULL) { mlockfile_pack(pk, itr->file); itr = itr->next; } return (0); }
void report_hist(int err, char *idx, struct list*hlist, void*arg) { int cnt; msgpack_packer *pk = arg; msgpack_pack_array(pk, err ? 2 : 4); push_cstr("hist.res"); msgpack_pack_int(pk, err); if(err) return; push_cstr_len(idx); cnt = list_count(hlist); msgpack_pack_array(pk, cnt); list_apply(hlist, true, write_history_el, arg); }
void report_ctlist(int err, struct list*ctlist, void*arg) { int cnt; msgpack_packer *pk = arg; msgpack_pack_array(pk, err ? 2 : 3); push_cstr("contacts.res"); msgpack_pack_int(pk, err); if(err) return; cnt = list_count(ctlist); msgpack_pack_array(pk, cnt); list_apply(ctlist, true, write_contact_el, arg); }
void ANetworkController::ReceivedSeekAndPauseReplay(msgpack_object* Data) { AReplayPlayer* Player = NULL; for (TActorIterator<AReplayPlayer> ObjIt(GetWorld()); ObjIt; ++ObjIt) { Player = *ObjIt; break; } check(Player != NULL); float Seconds = Unpack<double>(Data); Player->SeekAndPause(Seconds); msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 2); msgpack_pack_uint16(&pk, EPacketType::PT_SeekAndPauseReplay); msgpack_pack_float(&pk, Player->GetTime()); int32 BytesSent; TcpSocket->Send((uint8*)sbuf.data, sbuf.size, BytesSent); msgpack_sbuffer_destroy(&sbuf); }
int main(void) { msgpack_sbuffer sbuf; msgpack_packer pk; msgpack_zone mempool; msgpack_object deserialized; /* msgpack::sbuffer is a simple buffer implementation. */ msgpack_sbuffer_init(&sbuf); /* serialize values into the buffer using msgpack_sbuffer_write callback function. */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); /* deserialize the buffer into msgpack_object instance. */ /* deserialized object is valid during the msgpack_zone instance alive. */ msgpack_zone_init(&mempool, 2048); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); /* print the deserialized object. */ msgpack_object_print(stdout, deserialized); puts(""); msgpack_zone_destroy(&mempool); msgpack_sbuffer_destroy(&sbuf); return 0; }
virtual void encode() { mImgs = boost::shared_ptr<boost::circular_buffer<CameraImage> >(new boost::circular_buffer<CameraImage>(60)); while(1) { if(mImgs->size() == 0) { usleep(3000); continue; } printf("encoding!\n"); CameraImage i = mImgs->back(); mImgs->pop_back(); encodeImage(i); msgpack_sbuffer buffer; msgpack_packer pk; msgpack_sbuffer_init(&buffer); msgpack_packer_init(&pk, &buffer, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_int(&pk, 1); msgpack_pack_int(&pk, i.camera_timestamp); msgpack_pack_raw(&pk, i.encoded.size); msgpack_pack_raw_body(&pk, (void*)i.encoded.buffer.get(), i.encoded.size); write(mFile, buffer.data, buffer.size); msgpack_sbuffer_destroy(&buffer); } }
static inline int process_pack(struct tcp_conn *conn, char *pack, size_t size) { size_t off = 0; msgpack_unpacked result; msgpack_object entry; struct flb_in_tcp_config *ctx; ctx = conn->ctx; /* First pack the results, iterate concatenated messages */ msgpack_unpacked_init(&result); while (msgpack_unpack_next(&result, pack, size, &off)) { entry = result.data; msgpack_pack_array(&ctx->mp_pck, 2); msgpack_pack_uint64(&ctx->mp_pck, time(NULL)); msgpack_pack_map(&ctx->mp_pck, 1); msgpack_pack_bin(&ctx->mp_pck, 3); msgpack_pack_bin_body(&ctx->mp_pck, "msg", 3); msgpack_pack_object(&ctx->mp_pck, entry); ctx->buffer_id++; } msgpack_unpacked_destroy(&result); return 0; }
void grn_output_array_open(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, const char *name, int nelements) { put_delimiter(ctx, outbuf, output_type); switch (output_type) { case GRN_CONTENT_JSON: GRN_TEXT_PUTC(ctx, outbuf, '['); break; case GRN_CONTENT_XML: GRN_TEXT_PUTC(ctx, outbuf, '<'); GRN_TEXT_PUTS(ctx, outbuf, name); GRN_TEXT_PUTC(ctx, outbuf, '>'); grn_vector_add_element(ctx, &ctx->impl->names, name, strlen(name), 0, GRN_DB_SHORT_TEXT); break; case GRN_CONTENT_TSV: if (DEPTH > 2) { GRN_TEXT_PUTS(ctx, outbuf, "[\t"); } break; case GRN_CONTENT_MSGPACK : #ifdef HAVE_MESSAGE_PACK if (nelements < 0) { GRN_LOG(ctx, GRN_LOG_DEBUG, "grn_output_array_open nelements (%d) for <%s>", nelements, name); } msgpack_pack_array(&ctx->impl->msgpacker, nelements); #endif break; case GRN_CONTENT_NONE: break; } INCR_DEPTH(0); }
/* Given a series of tasks, serialize into a series of array objects * using messagepack and return pointer to the buffer containing the * serialized data */ msgpack_sbuffer * oolong_serialize(msgpack_sbuffer *sbuf, oolong_task **tasks, int size) { int i; oolong_task *task; msgpack_packer *pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write); for(i = 0; i < size; i++) { task = tasks[i]; /* Begin array packing */ msgpack_pack_array(pk, 3); /* Pack description */ msgpack_pack_raw(pk, sizeof(task->description) + 1); msgpack_pack_raw_body(pk, task->description, sizeof(task->description) + 1); /* Pack completed */ msgpack_pack_int(pk, task->completed); /* Pack due */ msgpack_pack_int(pk, task->due); } msgpack_packer_free(pk); return sbuf; }
/** * Handle request message * * [type(0), msgid(uint), method(bin), args([...])] */ void MsgpackIODevice::dispatchRequest(msgpack_object& req) { uint64_t msgid = req.via.array.ptr[1].via.u64; QByteArray errmsg("Unknown method"); QVariant params; QByteArray method; if (!m_reqHandler) { goto err; } if (decodeMsgpack(req.via.array.ptr[2], method)) { qDebug() << "Found unexpected method in request" << req; goto err; } if (decodeMsgpack(req.via.array.ptr[3], params)) { qDebug() << "Found unexpected parameters in request" << req; goto err; } m_reqHandler->handleRequest(this, msgid, method, params.toList()); return; err: // Send error reply [type(1), msgid, error, NIL] msgpack_pack_array(&m_pk, 4); msgpack_pack_int(&m_pk, 1); msgpack_pack_int(&m_pk, msgid); msgpack_pack_bin(&m_pk, errmsg.size()); msgpack_pack_bin_body(&m_pk, errmsg.constData(), errmsg.size()); msgpack_pack_nil(&m_pk); }
static inline int process_line(char *line, struct flb_in_serial_config *ctx) { int line_len; char *p = line; char *end = NULL; char msg[1024]; /* Increase buffer position */ ctx->buffer_id++; line_len = strlen(p); strncpy(msg, p, line_len); msg[line_len] = '\0'; /* * Store the new data into the MessagePack buffer, * we handle this as a list of maps. */ msgpack_pack_array(&ctx->mp_pck, 2); msgpack_pack_uint64(&ctx->mp_pck, time(NULL)); msgpack_pack_map(&ctx->mp_pck, 1); msgpack_pack_bin(&ctx->mp_pck, 3); msgpack_pack_bin_body(&ctx->mp_pck, "msg", 3); msgpack_pack_bin(&ctx->mp_pck, line_len); msgpack_pack_bin_body(&ctx->mp_pck, p, line_len); flb_debug("[in_serial] '%s'", (const char *) msg); return 0; }
void test() { uint64_t test_u64 = 0xFFF0000000000001LL; size_t size = 10000000; msgpack_sbuffer buf; msgpack_sbuffer_init(&buf); msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write); msgpack_pack_array(pk, size); { int idx = 0; for (; idx < size; ++idx) msgpack_pack_uint64(pk, test_u64); } msgpack_packer_free(pk); size_t upk_pos = 0; msgpack_unpacked msg; msgpack_unpacked_init(&msg); while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) { } msgpack_sbuffer_destroy(&buf); }
int main(void) { /* creates buffer and serializer instance. */ msgpack_sbuffer* buffer = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write); /* serializes ["Hello", "MessagePack"]. */ msgpack_pack_array(pk, 2); msgpack_pack_raw(pk, 5); msgpack_pack_raw_body(pk, "Hello", 5); msgpack_pack_raw(pk, 11); msgpack_pack_raw_body(pk, "MessagePack", 11); /* deserializes it. */ msgpack_unpacked msg; msgpack_unpacked_init(&msg); bool success = msgpack_unpack_next(&msg, buffer->data, buffer->size, NULL); /* prints the deserialized object. */ msgpack_object obj = msg.data; msgpack_object_print(stdout, obj); /*=> ["Hello", "MessagePack"] */ puts(""); // msgpack_pack_object/pk /* cleaning */ msgpack_sbuffer_free(buffer); msgpack_packer_free(pk); }
void paxos_instance_pack(struct yakyak *yy, struct paxos_instance *inst) { msgpack_pack_array(yy->pk, 3); paxos_header_pack(yy, &inst->pi_hdr); inst->pi_committed ? msgpack_pack_true(yy->pk) : msgpack_pack_false(yy->pk); paxos_value_pack(yy, &inst->pi_val); }
void paxos_request_pack(struct yakyak *yy, struct paxos_request *req) { msgpack_pack_array(yy->pk, 2); paxos_value_pack(yy, &req->pr_val); msgpack_pack_raw(yy->pk, req->pr_size); msgpack_pack_raw_body(yy->pk, req->pr_data, req->pr_size); }
int mlockfile_packfn(msgpack_packer * pk, void *file) { msgpack_pack_array(pk, 2); msgpack_pack_true(pk); mlockfile_pack(pk, file); return (0); }
void report_signup(int err, struct list*elist, void *arg) { msgpack_packer *pk = arg; if(err == 1) { msgpack_pack_array(pk, 3); } else { msgpack_pack_array(pk, 2); } push_cstr("api.signup"); msgpack_pack_int(pk, err); if(err==1) { msgpack_pack_array(pk, list_count(elist)); list_apply(elist, true, write_field_err, arg); } }
void yakyak_init(struct yakyak *yy, size_t n) { yy->buf = msgpack_sbuffer_new(); yy->pk = msgpack_packer_new(yy->buf, msgpack_sbuffer_write); msgpack_pack_array(yy->pk, n); }
void paxos_acceptor_pack(struct yakyak *yy, struct paxos_acceptor *acc) { msgpack_pack_array(yy->pk, 2); msgpack_pack_paxid(yy->pk, acc->pa_paxid); msgpack_pack_raw(yy->pk, acc->pa_size); msgpack_pack_raw_body(yy->pk, acc->pa_desc, acc->pa_size); }
void msgpack_rpc_from_stringarray(StringArray result, msgpack_packer *res) { msgpack_pack_array(res, result.size); for (size_t i = 0; i < result.size; i++) { msgpack_rpc_from_string(result.items[i], res); } }
void mlockfile_pack(msgpack_packer * pk, struct mlockfile *lf) { size_t path_length = strlen(lf->path); msgpack_pack_array(pk, 2); msgpack_pack_raw(pk, path_length); msgpack_pack_raw_body(pk, lf->path, path_length); msgpack_pack_uint64(pk, lf->mmappedsize); }
void do_write_ctel(msgpack_packer *pk, struct contact_el *ctel) { msgpack_pack_array(pk, 3); push_cstr_len(ctel->login); push_cstr_len(ctel->name); push_cstr_len(ctel->phone); }
void msgpack_rpc_from_array(Array result, msgpack_packer *res) { msgpack_pack_array(res, result.size); for (size_t i = 0; i < result.size; i++) { msgpack_rpc_from_object(result.items[i], res); } }
int LogInLog_to_msgpack(msgpack_packer *pk, LogInLog *arg) { msgpack_pack_array(pk, 13); UserInfo_to_msgpack(pk, &arg->user); msgpack_pack_int(pk, arg->site); msgpack_pack_int(pk, arg->num); msgpack_pack_array(pk, arg->sites_size); for (int _i = 0; _i < arg->sites_size; ++_i) { msgpack_pack_int(pk, arg->sites[_i]); } msgpack_pack_map(pk, arg->sites2_size); for (int _i = 0; _i < arg->sites2_size; ++_i) { if (arg->sites2_keys[_i]) { size_t _l = strlen(arg->sites2_keys[_i]); msgpack_pack_raw(pk, _l); msgpack_pack_raw_body(pk, arg->sites2_keys[_i], _l); } else { msgpack_pack_nil(pk); } msgpack_pack_int(pk, arg->sites2_vals[_i]); } if (arg->s1) { size_t _l = strlen(arg->s1); msgpack_pack_raw(pk, _l); msgpack_pack_raw_body(pk, arg->s1, _l); } else { msgpack_pack_nil(pk); } arg->b1 ? msgpack_pack_true(pk) : msgpack_pack_false(pk); msgpack_pack_raw(pk, arg->r1_size); msgpack_pack_raw_body(pk, arg->r1, arg->r1_size); msgpack_pack_double(pk, arg->d1); msgpack_pack_int(pk, arg->i2); my_type_x_to_msgpack(pk, &arg->my1); msgpack_pack_array(pk, arg->user_list_size); for (int _i = 0; _i < arg->user_list_size; ++_i) { UserInfo_to_msgpack(pk, &arg->user_list[_i]); } msgpack_pack_map(pk, arg->user_map_size); for (int _i = 0; _i < arg->user_map_size; ++_i) { UserInfo_to_msgpack(pk, &arg->user_map_keys[_i]); UserInfo_to_msgpack(pk, &arg->user_map_vals[_i]); } return 0; }
void prepare(msgpack_sbuffer* sbuf) { msgpack_packer pk; msgpack_packer_init(&pk, sbuf, msgpack_sbuffer_write); /* 1st object */ msgpack_pack_array(&pk, 3); msgpack_pack_int(&pk, 1); msgpack_pack_true(&pk); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "example", 7); /* 2nd object */ msgpack_pack_str(&pk, 6); msgpack_pack_str_body(&pk, "second", 6); /* 3rd object */ msgpack_pack_array(&pk, 2); msgpack_pack_int(&pk, 42); msgpack_pack_false(&pk); }
/** * Start an RPC request * * Use send() to pass on each of the call parameters * * Returns a MsgpackRequest object. You can connect to * its finished() SIGNAL to handle the response */ MsgpackRequest* MsgpackIODevice::startRequestUnchecked(const QString& method, quint32 argcount) { quint32 msgid = msgId(); // [type(0), msgid, method, args] msgpack_pack_array(&m_pk, 4); msgpack_pack_int(&m_pk, 0); msgpack_pack_int(&m_pk, msgid); const QByteArray& utf8 = method.toUtf8(); msgpack_pack_bin(&m_pk, utf8.size()); msgpack_pack_bin_body(&m_pk, utf8.constData(), utf8.size()); msgpack_pack_array(&m_pk, argcount); MsgpackRequest *r = new MsgpackRequest( msgid, this); connect(r, &MsgpackRequest::timeout, this, &MsgpackIODevice::requestTimeout); m_requests.insert(msgid, r); return r; }