static int lua_proto_get_ok_packet (lua_State *L) {
	size_t packet_len;
	const char *packet_str = luaL_checklstring(L, 1, &packet_len);
	network_mysqld_ok_packet_t *ok_packet;
	network_packet packet;
	GString s;
	int err = 0;

	s.str = (char *)packet_str;
	s.len = packet_len;

	packet.data = &s;
	packet.offset = 0;

	ok_packet = network_mysqld_ok_packet_new();

	err = err || network_mysqld_proto_get_ok_packet(&packet, ok_packet);
	if (err) {
		network_mysqld_ok_packet_free(ok_packet);

		luaL_error(L, "%s: network_mysqld_proto_get_ok_packet() failed", G_STRLOC);
		return 0;
	}

	lua_newtable(L);
	LUA_EXPORT_INT(ok_packet, server_status);
	LUA_EXPORT_INT(ok_packet, insert_id);
	LUA_EXPORT_INT(ok_packet, warnings);
	LUA_EXPORT_INT(ok_packet, affected_rows);

	network_mysqld_ok_packet_free(ok_packet);

	return 1;
}
void t_ok_packet_append(void) {
	network_mysqld_ok_packet_t *ok_packet;
	network_packet *packet;

	ok_packet = network_mysqld_ok_packet_new();
	packet = network_packet_new();
	packet->data = g_string_new(NULL);

	/* check if a empty ok-packet is encoded correctly */
	g_assert_cmpint(0, ==, network_mysqld_proto_append_ok_packet(packet->data, ok_packet));
	g_assert_cmpint(7, ==, packet->data->len);
	g_assert_cmpint(TRUE, ==, g_memeq(S(packet->data), C("\x00\x00\x00\x00\x00\x00\x00")));

	g_assert_cmpint(0, ==, network_mysqld_proto_get_ok_packet(packet, ok_packet));

	/* check if encoding and decoding works */
	ok_packet->warnings = 1;
	ok_packet->server_status = 2;
	ok_packet->insert_id = 3;
	ok_packet->affected_rows = 4;

	g_string_truncate(packet->data, 0);
	packet->offset = 0;

	g_assert_cmpint(0, ==, network_mysqld_proto_append_ok_packet(packet->data, ok_packet));
	g_assert_cmpint(7, ==, packet->data->len);
	g_assert_cmpint(TRUE, ==, g_memeq(S(packet->data), C("\x00\x04\x03\x02\x00\x01\x00")));
	
	network_mysqld_ok_packet_free(ok_packet);

	ok_packet = network_mysqld_ok_packet_new();
	g_assert_cmpint(0, ==, network_mysqld_proto_get_ok_packet(packet, ok_packet));
	g_assert_cmpint(1, ==, ok_packet->warnings);
	g_assert_cmpint(2, ==, ok_packet->server_status);
	g_assert_cmpint(3, ==, ok_packet->insert_id);
	g_assert_cmpint(4, ==, ok_packet->affected_rows);

	network_mysqld_ok_packet_free(ok_packet);

	/* check if too-short packet is denied */
	ok_packet = network_mysqld_ok_packet_new();
	g_string_truncate(packet->data, 0);
	packet->offset = 0;
	g_assert_cmpint(-1, ==, network_mysqld_proto_get_ok_packet(packet, ok_packet));

	network_mysqld_ok_packet_free(ok_packet);

	g_string_free(packet->data, TRUE);
	network_packet_free(packet);
}
/*@{*/
void t_ok_packet_new(void) {
	network_mysqld_ok_packet_t *ok_packet;

	ok_packet = network_mysqld_ok_packet_new();
	g_assert(ok_packet);

	network_mysqld_ok_packet_free(ok_packet);
}
static int lua_proto_append_ok_packet (lua_State *L) {
	GString *packet;
	network_mysqld_ok_packet_t *ok_packet;

	luaL_checktype(L, 1, LUA_TTABLE);

	ok_packet = network_mysqld_ok_packet_new();

	LUA_IMPORT_INT(ok_packet, server_status);
	LUA_IMPORT_INT(ok_packet, insert_id);
	LUA_IMPORT_INT(ok_packet, warnings);
	LUA_IMPORT_INT(ok_packet, affected_rows);

	packet = g_string_new(NULL);	
	network_mysqld_proto_append_ok_packet(packet, ok_packet);

	network_mysqld_ok_packet_free(ok_packet);
	
	lua_pushlstring(L, S(packet));
	
	g_string_free(packet, TRUE);

	return 1;
}