Exemple #1
0
static zmsg_t *create_call(const char *actionid, const char *module, const char *function, const char *data)
{
	zmsg_t *msg = zmsg_new();

    msgpack_sbuffer* pIntBuffer = msgpack_sbuffer_new();
    msgpack_packer* pk = msgpack_packer_new( pIntBuffer, msgpack_sbuffer_write );

    if (data && actionid && module)
    {
        msgpack_pack_map( pk, 3 );
        {
            m_pack_raw(pk, "command");
            m_pack_raw(pk, "call");

            m_pack_raw(pk, "body");
            msgpack_pack_map( pk, 5 );
            {
                m_pack_raw(pk, "module");
                m_pack_raw(pk, module);
                
                m_pack_raw(pk, "function");
                m_pack_raw(pk, function);
                
                m_pack_raw(pk, "version");
                msgpack_pack_uint64(pk, 1);
                
                m_pack_raw(pk, "parameters");
                msgpack_pack_map( pk, 1 );
                {
					m_pack_raw(pk, function);
					m_pack_raw(pk, data);
				}
                m_pack_raw(pk, "seqno");
                msgpack_pack_uint64(pk, 0);
            }
            m_pack_raw(pk, "actionid");
            m_pack_raw(pk, actionid);
        }
    }  else {
        return NULL;
    }
	
    zmsg_pushmem(msg, pIntBuffer->data, pIntBuffer->size);

    msgpack_sbuffer_free( pIntBuffer );
    msgpack_packer_free( pk );

    return msg;
}
Exemple #2
0
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;
}
Exemple #3
0
void
grn_output_uint64(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_ulltoa(ctx, outbuf, value);
    break;
  case GRN_CONTENT_TSV:
    grn_text_ulltoa(ctx, outbuf, value);
    break;
  case GRN_CONTENT_XML:
    GRN_TEXT_PUTS(ctx, outbuf, "<INT>");
    grn_text_ulltoa(ctx, outbuf, value);
    GRN_TEXT_PUTS(ctx, outbuf, "</INT>");
    break;
  case GRN_CONTENT_MSGPACK :
#ifdef HAVE_MESSAGE_PACK
    msgpack_pack_uint64(&ctx->impl->msgpacker, value);
#endif
    break;
  case GRN_CONTENT_NONE:
    break;
  }
  INCR_LENGTH;
}
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);
}
Exemple #5
0
std::string encodeRequest(const Request &r) {
    std::shared_ptr<msgpack_sbuffer> buffer{msgpack_sbuffer_new(), &msgpack_sbuffer_free};
    std::shared_ptr<msgpack_packer> pk{msgpack_packer_new(buffer.get(), msgpack_sbuffer_write), &msgpack_packer_free};

    msgpack_pack_map(pk.get(), 5);
    msgpack_pack_raw(pk.get(), 4);
    msgpack_pack_raw_body(pk.get(), "func", 4);
    msgpack_pack_raw(pk.get(), r.func.size());
    msgpack_pack_raw_body(pk.get(), r.func.data(), r.func.size());
    msgpack_pack_raw(pk.get(), 6);
    msgpack_pack_raw_body(pk.get(), "metric", 6);
    msgpack_pack_raw(pk.get(), r.metric.size());
    msgpack_pack_raw_body(pk.get(), r.metric.data(), r.metric.size());
    msgpack_pack_raw(pk.get(), 9);
    msgpack_pack_raw_body(pk.get(), "timestamp", 9);
    msgpack_pack_uint64(pk.get(), r.timestamp);

    msgpack_pack_raw(pk.get(), 5);
    msgpack_pack_raw_body(pk.get(), "value", 5);
    switch(r.value.type()) {
        case Value::Type::Nil:
            msgpack_pack_nil(pk.get());
            break;
        case Value::Type::Boolean:
            if(r.value.as<bool>())
                msgpack_pack_true(pk.get());
            else
                msgpack_pack_false(pk.get());
            break;
        case Value::Type::Numeric:
            msgpack_pack_double(pk.get(), r.value.as<double>());
            break;
        case Value::Type::String:
            {
                std::string b = r.value.as<std::string>();
                msgpack_pack_raw(pk.get(), b.size());
                msgpack_pack_raw_body(pk.get(), b.data(), b.size());
            }
            break;
        case Value::Type::Table:
            {
                // Hack
                std::string b = r.value.as<std::string>();
                if(b.empty())
                    msgpack_pack_nil(pk.get());
                else
                    msgpack_sbuffer_write(reinterpret_cast<void *>(buffer.get()), b.data(), b.size());
            }
            break;
    }

    msgpack_pack_raw(pk.get(), 5);
    msgpack_pack_raw_body(pk.get(), "state", 5);
    if(r.state.empty())
        msgpack_pack_nil(pk.get());
    else
        msgpack_sbuffer_write(reinterpret_cast<void *>(buffer.get()), r.state.data(), r.state.size());

    return std::string(buffer->data, buffer->size);
}
Exemple #6
0
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;
}
Exemple #7
0
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;
}
Exemple #8
0
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);
}
Exemple #9
0
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;
}
Exemple #10
0
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);
}
Exemple #11
0
/**
 * plume_req_reflection - Request UDP reflection service from the Plume server.
 */
int
plume_req_reflection(struct plume_client *client, uint64_t *cookie)
{
  struct yakyak yy;

  plume_req_init(&yy, client, "reflect", 1);
  msgpack_pack_uint64(yy.pk, *cookie);

  return plume_send(client, yakyak_data(&yy), yakyak_size(&yy));
}
Exemple #12
0
/*
 * 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;
}
Exemple #13
0
/*
 * 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;
}
Exemple #14
0
/* Callback to gather CPU usage between now and previous snapshot */
int in_cpu_collect(struct flb_config *config, void *in_context)
{
    int i;
    int maps;
    int len;
    double usage;
    double total;
    (void) config;
    struct flb_in_cpu_config *ctx = in_context;
    struct cpu_stats *cstats = &ctx->cstats;
    struct cpu_snapshot *s;

    /* Get the current CPU usage */
    total = proc_cpu_load(ctx->n_processors, cstats);
    cstats->load_now = total;

    /* Calculate the difference between the two samples */
    usage = fabs(cstats->load_now - cstats->load_pre) / ctx->cpu_ticks;
    total = (usage * 100) / ctx->n_processors;

    /* Put current load back */
    cstats->load_pre = cstats->load_now;

    /*
     * Store the new data into the MessagePack buffer,
     */
    msgpack_pack_array(&ctx->mp_pck, 2);
    msgpack_pack_uint64(&ctx->mp_pck, time(NULL));

    msgpack_pack_map(&ctx->mp_pck, (ctx->n_processors * 7 ) + 1);
    msgpack_pack_bin(&ctx->mp_pck, 3);
    msgpack_pack_bin_body(&ctx->mp_pck, "cpu", 3);
    msgpack_pack_double(&ctx->mp_pck, total);

    for (i = 1; i < ctx->n_processors + 1; i++) {
        s = &cstats->info[i];

        CPU_PACK_SNAP(s, user);
        CPU_PACK_SNAP(s, nice);
        CPU_PACK_SNAP(s, system);
        CPU_PACK_SNAP(s, idle);
        CPU_PACK_SNAP(s, iowait);
        CPU_PACK_SNAP(s, irq);
        CPU_PACK_SNAP(s, softirq);
    }

    flb_debug("[in_cpu] CPU %0.2f%%", total);

    flb_stats_update(in_cpu_plugin.stats_fd, 0, 1);
    return 0;
}
Exemple #15
0
static inline int process_line(char *line, struct flb_in_serial_config *ctx)
{
    int line_len;
    uint64_t val;
    char *p = line;
    char *end = NULL;
    char msg[1024];

    /* Increase buffer position */
    ctx->buffer_id++;

    errno = 0;
    val = strtol(p, &end, 10);
    if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
        || (errno != 0 && val == 0)) {
        goto fail;
    }

    /* Now process the human readable message */

    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;

 fail:
    ctx->buffer_id--;
    return -1;
}
Exemple #16
0
void in_xbee_rx_queue_raw(struct flb_in_xbee_config *ctx, const char *buf ,int len)
{
    /* Increase buffer position */

    pthread_mutex_lock(&ctx->mtx_mp);

    in_xbee_flush_if_needed(ctx);

    ctx->buffer_id++;

    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, 4);
    msgpack_pack_bin_body(&ctx->mp_pck, "data", 4);
    msgpack_pack_bin(&ctx->mp_pck, len);
    msgpack_pack_bin_body(&ctx->mp_pck, buf, len);

    pthread_mutex_unlock(&ctx->mtx_mp);
}
static inline int process_line(char *line, int len,
                               struct flb_in_serial_config *ctx)
{
    /* Increase buffer position */
    ctx->buffer_id++;

    /*
     * 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, len);
    msgpack_pack_bin_body(&ctx->mp_pck, line, len);

    flb_debug("[in_serial] message '%s'",
              (const char *) line);

    return 0;
}
Exemple #18
0
void
msgpack_pack_pax_uuid(msgpack_packer *pk, pax_uuid_t uuid)
{
  msgpack_pack_uint64(pk, uuid);
}
Exemple #19
0
/*
 * This plugin accepts following formats of MessagePack:
 *     { map => val, map => val, map => val }
 *  or [ time, { map => val, map => val, map => val } ]
 */
int in_xbee_rx_queue_msgpack(struct flb_in_xbee_config *ctx, const char *buf ,int len)
{
    msgpack_unpacked record;
    msgpack_unpacked field;
    msgpack_unpacked_init(&record);
    msgpack_unpacked_init(&field);

    size_t off = 0;
    size_t start = 0;
    size_t off2;
    size_t mp_offset;
    int queued = 0;
    uint64_t t;

    pthread_mutex_lock(&ctx->mtx_mp);

    while (msgpack_unpack_next(&record, buf, len, &off)) {
        if (record.data.type == MSGPACK_OBJECT_ARRAY && record.data.via.array.size == 2) {
            /*  [ time, { map => val, map => val, map => val } ] */

            msgpack_unpacked_destroy(&field);
            msgpack_unpacked_init(&field);
            off2 = 0;

            if (! msgpack_unpack_next(&field, buf + 1, len - 1, &off2))
                break;

            if (field.data.type != MSGPACK_OBJECT_POSITIVE_INTEGER)
                break;

            t = field.data.via.u64;
            mp_offset = off2;

            if (! msgpack_unpack_next(&field, buf + 1, len - 1, &off2))
                break;

            if (field.data.type != MSGPACK_OBJECT_MAP)
                break;

            in_xbee_flush_if_needed(ctx);
            ctx->buffer_id++;

            msgpack_pack_array(&ctx->mp_pck, 2);
            msgpack_pack_uint64(&ctx->mp_pck, t);
            msgpack_pack_bin_body(&ctx->mp_pck, (char*) buf + 1 + mp_offset, off2 - mp_offset);

        } else if (record.data.type == MSGPACK_OBJECT_MAP) {
            /*  { map => val, map => val, map => val } */

            in_xbee_flush_if_needed(ctx);
            ctx->buffer_id++;

            msgpack_pack_array(&ctx->mp_pck, 2);
            msgpack_pack_uint64(&ctx->mp_pck, time(NULL));
            msgpack_pack_bin_body(&ctx->mp_pck, buf + start, off - start);

        } else {
            break;

        }
        start = off;
        queued++;
    }

    msgpack_unpacked_destroy(&record);
    msgpack_unpacked_destroy(&field);
    pthread_mutex_unlock(&ctx->mtx_mp);
    return queued;
}
Exemple #20
0
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;
	}
}
Exemple #21
0
int yar_pack_push_ulong(yar_packager *packager, ulong num) /* {{{ */ {
	msgpack_packer *pk = packager->pk;

	return msgpack_pack_uint64(pk, num) < 0? 0 : 1;
}
Exemple #22
0
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);
      }
    }
Exemple #23
0
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;
    }
}
static void
log_send(struct evkeyvalq *output_headers, struct evbuffer *res_buf,
         thd_data *thd, struct evkeyvalq *get_args)
{
  uint64_t millisec;
  int threshold, limit;
  const char *callback, *types, *query, *client_id, *target_name,
             *learn_target_name;

  parse_keyval(get_args, &query, &types, &client_id, &target_name,
               &learn_target_name, &callback, &millisec, &threshold, &limit);

  /* send data to learn client */
  if (thd->zmq_sock && millisec && client_id && query && learn_target_name) {
    char c;
    size_t l;
    msgpack_packer pk;
    msgpack_sbuffer sbuf;
    int cnt, submit_flag = 0;

    msgpack_sbuffer_init(&sbuf);
    msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);

    cnt = 4;
    if (types && !strcmp(types, "submit")) {
      cnt++;
      types = NULL;
      submit_flag = 1;
    }
    msgpack_pack_map(&pk, cnt);

    c = 'i';
    msgpack_pack_raw(&pk, 1);
    msgpack_pack_raw_body(&pk, &c, 1);
    l = strlen(client_id);
    msgpack_pack_raw(&pk, l);
    msgpack_pack_raw_body(&pk, client_id, l);

    c = 'q';
    msgpack_pack_raw(&pk, 1);
    msgpack_pack_raw_body(&pk, &c, 1);
    l = strlen(query);
    msgpack_pack_raw(&pk, l);
    msgpack_pack_raw_body(&pk, query, l);

    c = 's';
    msgpack_pack_raw(&pk, 1);
    msgpack_pack_raw_body(&pk, &c, 1);
    msgpack_pack_uint64(&pk, millisec);

    c = 'l';
    msgpack_pack_raw(&pk, 1);
    msgpack_pack_raw_body(&pk, &c, 1);
    l = strlen(learn_target_name);
    msgpack_pack_raw(&pk, l);
    msgpack_pack_raw_body(&pk, learn_target_name, l);

    if (submit_flag) {
      c = 't';
      msgpack_pack_raw(&pk, 1);
      msgpack_pack_raw_body(&pk, &c, 1);
      msgpack_pack_true(&pk);
    }
    {
      zmq_msg_t msg;
      if (!zmq_msg_init_size(&msg, sbuf.size)) {
        memcpy((void *)zmq_msg_data(&msg), sbuf.data, sbuf.size);
        if (zmq_send(thd->zmq_sock, &msg, 0)) {
          print_error("zmq_send() error");
        }
        zmq_msg_close(&msg);
      }
    }
    msgpack_sbuffer_destroy(&sbuf);
  }
  /* make result */
  {
    int content_length;
    if (callback) {
      evhttp_add_header(output_headers,
                        "Content-Type", "text/javascript; charset=UTF-8");
      content_length = strlen(callback);
      evbuffer_add(res_buf, callback, content_length);
      evbuffer_add(res_buf, "(", 1);
      content_length += suggest_result(res_buf, types, query, target_name,
                                       threshold, limit,
                                       &(thd->cmd_buf), thd->ctx) + 3;
      evbuffer_add(res_buf, ");", 2);
    } else {
      evhttp_add_header(output_headers,
                        "Content-Type", "application/json; charset=UTF-8");
      content_length = suggest_result(res_buf, types, query, target_name,
                                      threshold, limit,
                                      &(thd->cmd_buf), thd->ctx);
    }
    if (content_length >= 0) {
      char num_buf[16];
      snprintf(num_buf, 16, "%d", content_length);
      evhttp_add_header(output_headers, "Content-Length", num_buf);
    }
  }
}
Exemple #25
0
void msgpack_rpc_from_uint64_t(uint64_t result, msgpack_packer *res)
{
  msgpack_pack_uint64(res, result);
}
Exemple #26
0
int msgpack_pack_uint64_wrap(msgpack_packer* pk, uint64_t d)
{
  return msgpack_pack_uint64(pk, d);
}
Exemple #27
0
void *in_kmsg_flush(void *in_context, int *size)
{
    int i;
    char *buf;
    msgpack_packer pck;
    msgpack_sbuffer sbuf;
    struct kmsg_line *entry;
    struct flb_in_kmsg_config *ctx = in_context;

    /* initialize buffers */
    msgpack_sbuffer_init(&sbuf);
    msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write);

    msgpack_pack_array(&pck, 2);

    /* Tag */
    msgpack_pack_raw(&pck, ctx->tag_len);
    msgpack_pack_raw_body(&pck, ctx->tag, ctx->tag_len);

    /* Primary Array: ['TAG', [ */
    msgpack_pack_array(&pck, ctx->buffer_id);

    /* Pack each data_array entry */
    for (i = 0; i < ctx->buffer_id; i++) {
        entry = &ctx->buffer[i];

        uint64_t t = ctx->boot_time.tv_sec + entry->tv.tv_sec;

        msgpack_pack_array(&pck, 2);
        msgpack_pack_uint64(&pck, t);

        msgpack_pack_map(&pck, 3);

        /* Priority */
        msgpack_pack_raw(&pck, 8);
        msgpack_pack_raw_body(&pck, "priority", 8);
        msgpack_pack_char(&pck, entry->priority);

        /* Sequence */
        msgpack_pack_raw(&pck, 8);
        msgpack_pack_raw_body(&pck, "sequence", 8);
        msgpack_pack_uint64(&pck, entry->sequence);

        /* Time: FIXME */

        /* Data message (line) */
        msgpack_pack_raw(&pck, 3);
        msgpack_pack_raw_body(&pck, "msg", 3);
        msgpack_pack_raw(&pck, entry->line_len);
        msgpack_pack_raw_body(&pck, entry->line, entry->line_len);
    }

    *size = sbuf.size;
    buf = malloc(sbuf.size);
    memcpy(buf, sbuf.data, sbuf.size);
    msgpack_sbuffer_destroy(&sbuf);

    ctx->buffer_id = 0;

    return buf;
}