예제 #1
0
static void pack_obj_destroyed_event(rbkit_obj_destroyed_event *event, msgpack_packer *packer) {
  msgpack_pack_map(packer, 3);
  pack_event_header(packer, event->event_header.event_type);

  msgpack_pack_int(packer, rbkit_message_field_payload);
  msgpack_pack_map(packer, 1);
  msgpack_pack_int(packer, rbkit_message_field_object_id);
  msgpack_pack_unsigned_long_long(packer, event->object_id);
}
예제 #2
0
static void pack_hash_event(rbkit_hash_event *event, msgpack_packer *packer) {
  VALUE hash;
  int size;
  msgpack_pack_map(packer, 3);
  pack_event_header(packer, event->event_header.event_type);
  hash = event->hash;
  size = (int)RHASH_SIZE(hash);
  msgpack_pack_int(packer, rbkit_message_field_payload);
  msgpack_pack_map(packer, size);
  rb_hash_foreach(hash, hash_pack_iterator, (VALUE)packer);
}
예제 #3
0
static void pack_obj_created_event(rbkit_obj_created_event *event, msgpack_packer *packer) {
  msgpack_pack_map(packer, 3);
  pack_event_header(packer, event->event_header.event_type);

  msgpack_pack_int(packer, rbkit_message_field_payload);
  msgpack_pack_map(packer, 2);
  msgpack_pack_int(packer, rbkit_message_field_object_id);
  msgpack_pack_unsigned_long_long(packer, event->object_id);
  msgpack_pack_int(packer, rbkit_message_field_class_name);
  pack_string(packer, event->klass);
  //TODO: pack allocation info as well
}
예제 #4
0
파일: broker.c 프로젝트: ybalt/ModBusServer
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;
}
예제 #5
0
파일: Encode.cpp 프로젝트: orofarne/lutop
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);
}
예제 #6
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;
}
예제 #7
0
파일: output.c 프로젝트: ueno/groonga
void
grn_output_map_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_PUTS(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_map_open nelements (%d) for <%s>",
              nelements,
              name);
    }
    msgpack_pack_map(&ctx->impl->msgpacker, nelements / 2);
#endif
    break;
  case GRN_CONTENT_NONE:
    break;
  }
  INCR_DEPTH(1);
}
예제 #8
0
파일: msgpack.c 프로젝트: 9612jhf/webdis
static void
msg_hgetall_reply(msgpack_packer* pk, const redisReply *r) {

	/* zip keys and values together in a msgpack object */

	unsigned int i;

	if(r->elements % 2 != 0) {
		return;
	}

	msgpack_pack_map(pk, r->elements / 2);
	for(i = 0; i < r->elements; i += 2) {
		redisReply *k = r->element[i], *v = r->element[i+1];

		/* keys and values need to be strings */
		if(k->type != REDIS_REPLY_STRING || v->type != REDIS_REPLY_STRING) {
			return;
		}

		/* key */
		msgpack_pack_raw(pk, k->len);
		msgpack_pack_raw_body(pk, k->str, k->len);

		/* value */
		msgpack_pack_raw(pk, v->len);
		msgpack_pack_raw_body(pk, v->str, v->len);
	}
}
예제 #9
0
파일: in_mem.c 프로젝트: enukane/fluent-bit
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;
}
예제 #10
0
/*
 * Document-method: Hash#to_msgpack
 *
 * call-seq:
 *   hash.to_msgpack(out = '') -> String
 *
 * Serializes the Hash into raw bytes.
 * This calls to_msgpack method reflectively for internal keys and values.
 */
static VALUE MessagePack_Hash_to_msgpack(int argc, VALUE *argv, VALUE self)
{
    ARG_BUFFER(out, argc, argv);
    msgpack_pack_map(out, RHASH_SIZE(self));
    rb_hash_foreach(self, MessagePack_Hash_to_msgpack_foreach, out);
    return out;
}
예제 #11
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;
}
예제 #12
0
/*
 * Document-method: Hash#to_msgpack
 *
 * call-seq:
 *   hash.to_msgpack(out = '') -> String
 *
 * Serializes the Hash into raw bytes.
 * This calls to_msgpack method reflectively for internal keys and values.
 */
static VALUE MessagePack_Hash_to_msgpack(int argc, VALUE *argv, VALUE self)
{
	ARG_BUFFER(out, argc, argv);
	// FIXME check sizeof(st_index_t) > sizeof(unsigned int) && RARRAY_LEN(self) > UINT_MAX
	msgpack_pack_map(out, (unsigned int)RHASH_SIZE(self));
	rb_hash_foreach(self, MessagePack_Hash_to_msgpack_foreach, out);
	return out;
}
예제 #13
0
void api_respond_error(msgpack_object *request_obj,
                       msgpack_packer *response_msg, const char *error) {
  msgpack_pack_map(response_msg, 2);
  msgpack_pack_string(response_msg, "error", -1);
  msgpack_pack_string(response_msg, error, -1);
  msgpack_pack_string(response_msg, "request", -1);
  msgpack_pack_object(response_msg, *request_obj);
} 
예제 #14
0
void api_request_dance(rpc_io *rpcio, msgpack_object *request,
                       msgpack_packer *response_msg) {
  printf("Dance dance dance. La la la.\n");

  msgpack_pack_map(response_msg, 1);
  msgpack_pack_string(response_msg, "danced", 6);
  msgpack_pack_true(response_msg);
}
예제 #15
0
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;
}
예제 #16
0
void msgpack_rpc_from_dictionary(Dictionary result, msgpack_packer *res)
{
  msgpack_pack_map(res, result.size);

  for (size_t i = 0; i < result.size; i++) {
    msgpack_rpc_from_string(result.items[i].key, res);
    msgpack_rpc_from_object(result.items[i].value, res);
  }
}
예제 #17
0
파일: msgpack.c 프로젝트: 9612jhf/webdis
/**
 * Parse info message and return object.
 */
void
msg_info_reply(msgpack_packer* pk, const char *s, size_t sz) {

	const char *p = s;
	unsigned int count = 0;

	/* TODO: handle new format */

	/* count number of lines */
	while(p < s + sz) {
		p = strchr(p, '\r');
		if(!p) break;

		p++;
		count++;
	}

	/* create msgpack object */
	msgpack_pack_map(pk, count);

	p = s;
	while(p < s + sz) {
		char *key, *val, *nl, *colon;
		size_t key_sz, val_sz;

		/* find key */
		colon = strchr(p, ':');
		if(!colon) {
			break;
		}
		key_sz = colon - p;
		key = calloc(key_sz + 1, 1);
		memcpy(key, p, key_sz);
		p = colon + 1;

		/* find value */
		nl = strchr(p, '\r');
		if(!nl) {
			free(key);
			break;
		}
		val_sz = nl - p;
		val = calloc(val_sz + 1, 1);
		memcpy(val, p, val_sz);
		p = nl + 1;
		if(*p == '\n') p++;

		/* add to object */
		msgpack_pack_raw(pk, key_sz);
		msgpack_pack_raw_body(pk, key, key_sz);
		msgpack_pack_raw(pk, val_sz);
		msgpack_pack_raw_body(pk, val, val_sz);

		free(key);
		free(val);
	}
}
예제 #18
0
static void pack_cpu_sample_event(rbkit_cpu_sample_event *event, msgpack_packer *packer) {
  rbkit_cpu_sample *sample;
  size_t count;

  msgpack_pack_map(packer, 3);
  sample = event->sample;

  // Keys 1 & 2 - event type and timestamp
  pack_event_header(packer, event->event_header.event_type);

  // Key 3 : Payload
  msgpack_pack_int(packer, rbkit_message_field_payload);
  // Value 3: Array of samples
  msgpack_pack_array(packer, sample->frame_count);

  for(count = 0; count != sample->frame_count; count++){
    msgpack_pack_map(packer, 6);

    // method_name
    msgpack_pack_int(packer, rbkit_message_field_method_name);
    pack_string(packer, sample->frames[count].method_name);

    // label
    msgpack_pack_int(packer, rbkit_message_field_label);
    pack_string(packer, sample->frames[count].label);

    // file
    msgpack_pack_int(packer, rbkit_message_field_file);
    pack_string(packer, sample->frames[count].file);

    // line
    msgpack_pack_int(packer, rbkit_message_field_line);
    msgpack_pack_unsigned_long(packer, sample->frames[count].line);

    // singleton_method
    msgpack_pack_int(packer, rbkit_message_field_singleton_method);
    msgpack_pack_int(packer, sample->frames[count].is_singleton_method);

    // thread_od
    msgpack_pack_int(packer, rbkit_message_field_thread_id);
    msgpack_pack_unsigned_long(packer, sample->frames[count].thread_id);
  }
}
예제 #19
0
static void pack_event_collection_event(rbkit_event_collection_event *event, msgpack_packer *packer) {
  msgpack_sbuffer *sbuf = packer->data;
  msgpack_pack_map(packer, 4);
  pack_event_header(packer, event->event_header.event_type);
  msgpack_pack_int(packer, rbkit_message_field_message_counter);
  msgpack_pack_unsigned_long(packer, get_message_counter());
  msgpack_pack_int(packer, rbkit_message_field_payload);
  msgpack_pack_array(packer, event->message_count);
  sbuf->data = realloc(sbuf->data, event->buffer_size + sbuf->size);
  memcpy(sbuf->data + sbuf->size, event->buffer, event->buffer_size);
  sbuf->size += event->buffer_size;
}
예제 #20
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;
}
예제 #21
0
파일: msgpack.c 프로젝트: KokaKiwi/libkdon
static void kdon_object_to_msgpack(kdon_t *kdon, msgpack_packer *packer)
{
    size_t size = kdon_object_size(kdon);
    void *iter;
    const char *key;
    kdon_t *value;

    msgpack_pack_map(packer, size);

    kdon_object_foreach(kdon, iter, key, value)
    {
        msgpack_pack_raw(packer, strlen(key));
        msgpack_pack_raw_body(packer, key, strlen(key));
        kdon_to_msgpack(value, packer);
    }
예제 #22
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;
}
예제 #23
0
void publish_output(process_t *process, struct proc_data *procdata,
                    const char *ioname, const char *data, ssize_t length) {
  /* TODO(sissel): move this to a separate file for 'event' streaming */
  zmq_msg_t event;
  int rc;
  size_t msgsize;
  program_t *program = pn_proc_program(process);
  procnanny_t *pn = program->data;

  fprintf(stdout, "%s[%d]: (%d bytes) %.*s\n", pn_proc_program(process)->name,
          pn_proc_instance(process), length, length, data);

  /* Fields:
   *  - data (the string read)
   *  - program name
   *  - process instance
   *  - stdout or stderr
   */

  msgpack_sbuffer *buffer = msgpack_sbuffer_new();
  msgpack_packer *output_msg = msgpack_packer_new(buffer, msgpack_sbuffer_write);

  msgpack_pack_map(output_msg, 5);

  /* "event" => "data" */
  msgpack_pack_string(output_msg, "event", -1);
  msgpack_pack_string(output_msg, "data", -1);

  msgpack_pack_string(output_msg, "program", -1);
  msgpack_pack_string(output_msg, program->name, program->name_len);

  msgpack_pack_string(output_msg, "instance", -1);
  msgpack_pack_int(output_msg, process->instance);

  msgpack_pack_string(output_msg, "source", -1);
  msgpack_pack_string(output_msg, ioname, -1);

  msgpack_pack_string(output_msg, "data", -1);
  msgpack_pack_string(output_msg, data, length);

  zmq_msg_init_data(&event, buffer->data, buffer->size, free_msgpack_buffer, buffer); 
  zmq_send(pn->eventsocket, &event, 0);
  zmq_msg_close(&event);

  msgpack_packer_free(output_msg);
} /* publish_output */
예제 #24
0
static void
sem_object_end(void *state)
{
	PackState		_state = (PackState) state;
	msgpack_sbuffer	*buf;
	JsonContainer	current_container, parent_container;
	msgpack_packer 	*pk;
	JsonObjectField	field;
	size_t			packed_size;
	char			*packed_data;
	JsonValue		value;

	current_container = _state->current_container;
	pk = _state->pk;

	/* start to pack map */
	msgpack_pack_map(pk, current_container->via.object.length);

	/* pack each field */
	field = current_container->via.object.start;
	while (field != NULL) {
		/* pack key */
		pack_string(pk, field->key);
		/* pack value */
		pack_value(pk, field->value);
		/* next field*/
		field = field->next;
	}

	/* retrieve packed binary and reset buffer of packer */
	buf = _state->buf;
	packed_size = buf->size;
	packed_data = msgpack_sbuffer_release(buf);

	/* set packed binary to the last value of parent conationer */
	parent_container = current_container->parent;
	value = value_to_be_set(parent_container);
	value->type = MSGPACK_BINARY;
	value->via.msg.size = packed_size;
	value->via.msg.data = packed_data;

	/* step back to parent level */
	_state->current_container = parent_container;
	destroy_container(current_container);
}
예제 #25
0
void send_trigger(mdcli_t * client, char * target_worker, char * rule_id,  int ival, char * user_id) {
  zclock_log("activating trigger\ntarget=%s\nvalue=%d\nuser=%s",
             target_worker, ival, user_id);
  struct timeval tval;
  gettimeofday(&tval, NULL);
  // make a messagepack hash
  msgpack_sbuffer * buffer =  msgpack_sbuffer_new();
  msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
  // value chunk
  msgpack_pack_map(pk, 3);
  // key
  msgpack_pack_raw(pk, 5);
  msgpack_pack_raw_body(pk, "value", 5);
  // value
  msgpack_pack_int(pk, ival);

  //time chunk

  // key
  msgpack_pack_raw(pk, 5);
  msgpack_pack_raw_body(pk, "epoch", 5);
  // time
  msgpack_pack_int(pk, tval.tv_sec);

  msgpack_pack_raw(pk, 6);
  msgpack_pack_raw_body(pk, "micros", 6);
  // time
  msgpack_pack_int(pk, tval.tv_usec);


  zmsg_t * msg = zmsg_new();
  // really, the user_id should be being added by a
  // gatekeeper, not the block itself, or it's a security
  // hole. will do for now FIX
  
  zmsg_pushstr(msg, user_id);
  // zmsg_pushmem(msg, &trigger.line_id, sizeof(int));

  zmsg_pushmem(msg, buffer->data, buffer->size);
  zmsg_pushstr(msg, rule_id);
  zmsg_pushstr(msg, "DoAction");
  mdcli_send(client, target_worker, &msg);
}
예제 #26
0
yar_packager * yar_pack_start(yar_data_type type, uint size) /* {{{ */ {
	yar_packager *packager = malloc(sizeof(yar_packager));
	
	packager->bf = msgpack_sbuffer_new();
	packager->pk = msgpack_packer_new(packager->bf, msgpack_sbuffer_write);

	switch (type) {
		case YAR_DATA_ARRAY:
			msgpack_pack_array(packager->pk, size);
			break;
		case YAR_DATA_MAP:
			msgpack_pack_map(packager->pk, size);
			break;
		default:
			break;
	}

	return packager;
}
예제 #27
0
void
dump_oid_info(msgpack_packer *pk, struct oid_info *oi)
{
	#define DUMPi(field) msgpack_pack_named_int(pk, #field, oi->field)
	msgpack_pack_map(pk, 6);

	DUMPi(sid);
	DUMPi(cid);
	DUMPi(fd);
	DUMPi(max_repetitions);
	msgpack_pack_string(pk, "oid");
	msgpack_pack_oid(pk, oi->oid);
	msgpack_pack_string(pk, "value");
	if (!oi->value.buf)
		msgpack_pack_nil(pk);
	else
		msgpack_pack_ber(pk, oi->value);

	#undef DUMPi
}
예제 #28
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);
}
예제 #29
0
파일: helper.c 프로젝트: nanopack/redd
void
save_data(char *filename, save_data_function pack_function)
{
	msgpack_sbuffer *buffer = NULL;
	msgpack_packer *packer  = NULL;
	char *save_file_name;
	FILE *save_file;

	if ((save_file_name = get_save_file_path(filename)) == NULL) {
		red_log(REDD_WARNING, "get_save_file_path returned NULL");
		return;
	}

	buffer = msgpack_sbuffer_new();
	msgpack_sbuffer_init(buffer);

	packer = msgpack_packer_new((void *)buffer, msgpack_sbuffer_write);

	msgpack_pack_map(packer, 1);
	pack_function(packer);

	if ((save_file = fopen(save_file_name, "w")) != NULL) {
		size_t written;
		written = fwrite((void *)&buffer->data[0], 1, buffer->size, save_file);
		fclose(save_file);
		if (written != buffer->size) {
			red_log(REDD_WARNING, "Failed to write to %s", save_file_name);
		}
	} else {
		red_log(REDD_WARNING, "Failed to open %s", save_file_name);
	}

	free(save_file_name);
	save_file_name = NULL;
	msgpack_packer_free(packer);
	packer = NULL;
	msgpack_sbuffer_free(buffer);
	buffer = NULL;
}
예제 #30
0
파일: rpc.c 프로젝트: 40a/experiments
rpc_call_t *rpc_call_new(void *zmq, struct ev_loop *ev, const char *address,
                         const char *method) {
  rpc_call_t *rpc = calloc(1, sizeof(rpc_call_t));
  rpc->zmq = zmq;
  rpc->ev = ev;
  rpc->address = address;

  rpc->pack_buffer = msgpack_sbuffer_new();
  rpc->request = msgpack_packer_new(rpc->pack_buffer, msgpack_sbuffer_write);

  msgpack_pack_map(rpc->request, 2); /* method and args */
  msgpack_pack_string(rpc->request, "method", 6);
  msgpack_pack_string(rpc->request, method, strlen(method));
  msgpack_pack_string(rpc->request, "args", 4);

  /* The rest of the packing is up to the invoker of the rpc call.
   * Add whatever arguments are necessary later to rpc->request */

  printf("Created new rpc call object targeting %s method %s\n",
         address, method);
  return rpc;
} /* rpc_call_new */