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);
}
static void
sem_array_end(void *state)
{
	PackState			_state = (PackState) state;
	msgpack_sbuffer		*buf;
	JsonContainer		current_container, parent_container;
	msgpack_packer 		*pk;
	JsonArrayElement	element;
	size_t				packed_size;
	char				*packed_data;
	JsonValue			value;

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

	/* start to pack array */
	msgpack_pack_array(pk, current_container->via.array.length);

	/* pack each element */
	element = current_container->via.array.start;
	while (element != NULL) {
		/* pack value */
		pack_value(pk, element->value);
		/* next element */
		element = element->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);
}
Exemple #3
0
	char* release()
	{
		return msgpack_sbuffer_release(this);
	}