int in_mem_collect(struct flb_config *config, void *in_context) { struct sysinfo info; (void) config; struct flb_in_mem_config *ctx = in_context; uint32_t totalram, freeram; sysinfo(&info); totalram = info.totalram / 1024; freeram = info.freeram / 1024; msgpack_pack_map(&ctx->pckr, 3); msgpack_pack_raw(&ctx->pckr, 4); msgpack_pack_raw_body(&ctx->pckr, "time", 4); msgpack_pack_uint64(&ctx->pckr, time(NULL)); msgpack_pack_raw(&ctx->pckr, 5); msgpack_pack_raw_body(&ctx->pckr, "total", 5); msgpack_pack_uint32(&ctx->pckr, totalram); msgpack_pack_raw(&ctx->pckr, 4); msgpack_pack_raw_body(&ctx->pckr, "free", 4); msgpack_pack_uint32(&ctx->pckr, freeram); flb_debug("[in_mem] memory total %d kb, free %d kb (buffer=%i)", info.totalram, info.freeram, ctx->idx); ++ctx->idx; return 0; }
void test() { size_t size = 10000000; msgpack_sbuffer buf; msgpack_packer * pk; size_t upk_pos = 0; msgpack_unpacked msg; msgpack_sbuffer_init(&buf); pk = msgpack_packer_new(&buf, msgpack_sbuffer_write); msgpack_pack_array(pk, size); { int idx = 0; for (; idx < size; ++idx) msgpack_pack_uint32(pk, 1); } msgpack_packer_free(pk); msgpack_unpacked_init(&msg); while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) { } msgpack_sbuffer_destroy(&buf); }
int nmb_pack_values_to_msgpack(struct nmb_values *values, struct msgpack *packer) { MSN msn = values->msn; msn = ((msn << 8) | values->type); msgpack_pack_uint64(packer, msn); msgpack_pack_uint64(packer, values->xidpair.child_xid); msgpack_pack_uint64(packer, values->xidpair.parent_xid); msgpack_pack_uint32(packer, values->key.size); msgpack_pack_nstr(packer, values->key.data, values->key.size); if (values->type != MSG_DELETE) { msgpack_pack_uint32(packer, values->val.size); msgpack_pack_nstr(packer, values->val.data, values->val.size); } return NESS_OK; }
void api_request_status(rpc_io *rpcio, msgpack_object *request_obj, msgpack_packer *response_msg) { int rc; char *program_name = NULL; size_t program_len = 0; rc = obj_get(request_obj, "program", MSGPACK_OBJECT_RAW, &program_name, &program_len); /* A missing 'program' field is OK. It means we want all programs */ msgpack_pack_map(response_msg, 1); msgpack_pack_string(response_msg, "programs", -1); /* programs is a map of: * programname => { * command: "string", * args: "string", * uid: uid, * gid: gid, * nice: nice, * ionice: ionice, * is_running: boolean * instances: { * pid: ... * state: ... * admin_state: ... * start: ... * duration: ... * } * } */ msgpack_pack_map(response_msg, rpcio->procnanny->programs_len); pn_prog_each(rpcio->procnanny, i, program, { if (program_name != NULL && strncmp(program->name, program_name, program_len)) { continue; } msgpack_pack_string(response_msg, program->name, program->name_len); msgpack_pack_map(response_msg, 8); /* 8 fields */ msgpack_pack_string(response_msg, "command", -1); msgpack_pack_string(response_msg, program->command, program->command_len); msgpack_pack_string(response_msg, "args", -1); msgpack_pack_array(response_msg, program->args_len); int argind = 0; for (argind = 0; argind < program->args_len; argind++) { msgpack_pack_string(response_msg, program->args[argind], -1); } msgpack_pack_string(response_msg, "uid", -1); msgpack_pack_uint32(response_msg, program->uid); msgpack_pack_string(response_msg, "gid", -1); msgpack_pack_uint32(response_msg, program->gid); msgpack_pack_string(response_msg, "nice", -1); msgpack_pack_int32(response_msg, program->nice); msgpack_pack_string(response_msg, "ionice", -1); msgpack_pack_int32(response_msg, program->ionice); msgpack_pack_string(response_msg, "active", -1); msgpack_pack_true(response_msg); msgpack_pack_string(response_msg, "instances", -1); msgpack_pack_map(response_msg, program->nprocs); pn_prog_proc_each(program, instance, process, { msgpack_pack_uint32(response_msg, instance); msgpack_pack_map(response_msg, 5); msgpack_pack_string(response_msg, "pid", -1); msgpack_pack_uint32(response_msg, process->pid); msgpack_pack_string(response_msg, "state", -1); switch (process->state) { case PROCESS_STATE_STARTING: msgpack_pack_string(response_msg, "starting", -1); break; case PROCESS_STATE_RUNNING: msgpack_pack_string(response_msg, "running", -1); break; case PROCESS_STATE_STOPPING: msgpack_pack_string(response_msg, "stopping", -1); break; case PROCESS_STATE_EXITED: msgpack_pack_string(response_msg, "exited", -1); break; case PROCESS_STATE_BACKOFF: msgpack_pack_string(response_msg, "backoff", -1); break; case PROCESS_STATE_NEW: msgpack_pack_string(response_msg, "new", -1); break; default: msgpack_pack_string(response_msg, "unknown", -1); break; } msgpack_pack_string(response_msg, "exitcode", -1); msgpack_pack_uint8(response_msg, process->exit_status); msgpack_pack_string(response_msg, "exitsignal", -1); msgpack_pack_uint8(response_msg, process->exit_signal); msgpack_pack_string(response_msg, "admin_state", -1); switch (process->admin_state) { case ADMIN_STATE_DOWN: msgpack_pack_string(response_msg, "down", -1); break; case ADMIN_STATE_UP: msgpack_pack_string(response_msg, "up", -1); break; default: msgpack_pack_string(response_msg, "unknown", -1); break; } }) });
void unit_message_deserialize_response(UNUSED(void **state)) { struct api_error error = ERROR_INIT; msgpack_sbuffer sbuf; msgpack_packer pk; msgpack_zone mempool; msgpack_object deserialized; struct message_response response; 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_uint32(&pk, 1234); msgpack_pack_nil(&pk); msgpack_pack_array(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); free_params(response.params); /* wrong type type */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_nil(&pk); msgpack_pack_uint32(&pk, 1234); msgpack_pack_nil(&pk); msgpack_pack_array(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); /* wrong type */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 0); msgpack_pack_uint32(&pk, 1234); msgpack_pack_nil(&pk); msgpack_pack_array(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); /* wrong msgid */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 1); msgpack_pack_int(&pk, -1234); msgpack_pack_nil(&pk); msgpack_pack_array(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); /* wrong msgid value*/ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 1); msgpack_pack_uint32(&pk, UINT32_MAX); msgpack_pack_nil(&pk); msgpack_pack_array(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); /* wrong nil */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 1); msgpack_pack_uint32(&pk, 1234); msgpack_pack_uint8(&pk, 1); msgpack_pack_array(&pk, 1); msgpack_pack_uint8(&pk, 0); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); /* wrong params */ msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); msgpack_pack_array(&pk, 4); msgpack_pack_uint8(&pk, 1); msgpack_pack_uint32(&pk, 1234); msgpack_pack_nil(&pk); msgpack_pack_nil(&pk); msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized); assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, &error)); msgpack_sbuffer_clear(&sbuf); /* null input params */ assert_int_not_equal(0, message_deserialize_response(&response, &deserialized, NULL)); assert_int_not_equal(0, message_deserialize_response(&response, NULL, &error)); assert_int_not_equal(0, message_deserialize_response(NULL, &deserialized, &error)); msgpack_zone_destroy(&mempool); msgpack_sbuffer_destroy(&sbuf); }
int msgpack_pack_uint32_wrap(msgpack_packer* pk, uint32_t d) { return msgpack_pack_uint32(pk, d); }
void msgpack_pack_paxid(msgpack_packer *pk, paxid_t paxid) { msgpack_pack_uint32(pk, paxid); }
static inline void rbtrace__send_event(int nargs, const char *name, ...) { if (!rbtracer.attached_pid || !rbtracer.sbuf || !rbtracer.msgpacker || rbtracer.mqo_fd == -1) return; int n; msgpack_sbuffer_clear(rbtracer.sbuf); msgpack_packer *pk = rbtracer.msgpacker; msgpack_pack_array(pk, nargs+1); msgpack_pack_raw(pk, strlen(name)); msgpack_pack_raw_body(pk, name, strlen(name)); if (nargs > 0) { int type; int sint; uint32_t uint; uint64_t uint64; unsigned long ulong; char *str; va_list ap; va_start(ap, name); for (n=0; n<nargs; n++) { type = va_arg(ap, int); switch (type) { case 'b': // boolean if (va_arg(ap, int)) msgpack_pack_true(pk); else msgpack_pack_false(pk); break; case 'd': // signed int sint = va_arg(ap, int); msgpack_pack_int(pk, sint); break; case 'u': // unsigned int uint = va_arg(ap, uint32_t); msgpack_pack_uint32(pk, uint); break; case 'l': // unsigned long (VALUE/ID) ulong = va_arg(ap, unsigned long); msgpack_pack_unsigned_long(pk, ulong); break; case 't': // uint64 (timestamps) uint64 = va_arg(ap, uint64_t); msgpack_pack_uint64(pk, uint64); break; case 'n': // current timestamp msgpack_pack_uint64(pk, timeofday_usec()); break; case 's': // string str = va_arg(ap, char *); if (!str) str = (char *)""; msgpack_pack_raw(pk, strlen(str)); msgpack_pack_raw_body(pk, str, strlen(str)); break; default: fprintf(stderr, "unknown type (%d) passed to rbtrace__send_event for %s\n", (int)type, name); } }
void ANetworkController::SendData() { if (!TcpSocket) { return; } // Clear the data if there is anything on the stream TryReceiveData(); AVehiclestats* Stats = NULL; for (TActorIterator<AVehiclestats> ObjIt(GetWorld()); ObjIt; ++ObjIt) { Stats = *ObjIt; break; } if (Stats == NULL) { return; } // Send crashlog msgpack_sbuffer sbuf; msgpack_sbuffer_init(&sbuf); msgpack_packer pk; msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); for (auto Iter = Stats->IncidentLog.CreateConstIterator(); Iter; ++Iter) { msgpack_pack_array(&pk, 2); msgpack_pack_uint16(&pk, EPacketType::PT_IncidentLog); Pack(&pk, *Iter); } Stats->IncidentLog.Empty(); // Send the statestics msgpack_pack_array(&pk, 2); msgpack_pack_uint16(&pk, EPacketType::PT_GetStats); msgpack_pack_map(&pk, 6); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "spawned", 7); msgpack_pack_uint32(&pk, Stats->GetNumVehiclesSpawned()); msgpack_pack_str(&pk, 6); msgpack_pack_str_body(&pk, "onroad", 6); msgpack_pack_uint32(&pk, Stats->GetNumVehiclesOnTheRoad()); msgpack_pack_str(&pk, 7); msgpack_pack_str_body(&pk, "crashed", 7); msgpack_pack_uint32(&pk, Stats->GetNumVehiclesCrashed()); msgpack_pack_str(&pk, 9); msgpack_pack_str_body(&pk, "incidents", 9); msgpack_pack_uint32(&pk, Stats->GetNumVehiclesIncidents()); TArray<float> Throughputs; for (TActorIterator<AMeasurementGate> ObjIt(GetWorld()); ObjIt; ++ObjIt) { AMeasurementGate* Gate = *ObjIt; Throughputs.Add(Gate->GetThroughput(0)); Throughputs.Add(Gate->GetThroughput(1)); } msgpack_pack_str(&pk, 11); msgpack_pack_str_body(&pk, "throughputs", 11); msgpack_pack_array(&pk, Throughputs.Num()); for (auto Iter = Throughputs.CreateConstIterator(); Iter; ++Iter) { msgpack_pack_float(&pk, *Iter); } msgpack_pack_str(&pk, 4); msgpack_pack_str_body(&pk, "time", 4); msgpack_pack_float(&pk, Stats->GetTime()); int32 BytesLeft = sbuf.size; while (BytesLeft > 0) { int32 Index = sbuf.size - BytesLeft; int32 BytesSent; TcpSocket->Send((uint8*)sbuf.data + Index, BytesLeft, BytesSent); BytesLeft = BytesLeft - BytesSent; if (BytesSent == -1) { break; } } msgpack_sbuffer_destroy(&sbuf); }