当前位置: 首页>>代码示例>>C++>>正文


C++ PacketWriter::write方法代码示例

本文整理汇总了C++中PacketWriter::write方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketWriter::write方法的具体用法?C++ PacketWriter::write怎么用?C++ PacketWriter::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketWriter的用法示例。


在下文中一共展示了PacketWriter::write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LUAToXMLElement

bool LUAXML::LUAToXMLElement(Exception& ex, lua_State* pState, PacketWriter& writer) {
	// -1 => table

	lua_pushstring(pState, "__name");
	lua_rawget(pState, -2);
	const char* name(lua_tostring(pState, -1));
	lua_pop(pState, 1);
	if (!name) {
		ex.set(Exception::APPLICATION, "Impossible to write a XML element without name (__name)");
		return false;
	}

	// write attributes
	writer.write("<").write(name).write(" ");
	lua_pushnil(pState);  // first key 
	while (lua_next(pState, -2) != 0) {
		// uses 'key' (at index -2) and 'value' (at index -1) 
		if (lua_type(pState, -2) == LUA_TSTRING && strcmp(lua_tostring(pState, -2),"__name")!=0 && lua_isstring(pState, -1))
			writer.write(lua_tostring(pState, -2)).write("=\"").write(lua_tostring(pState, -1)).write("\" ");
		lua_pop(pState, 1);
	}
	if (lua_objlen(pState, -1) == 0) {
		writer.write("/>");
		return true;
	}

	writer.write(">");

	// write elements
	lua_pushnil(pState);  // first key 
	while (lua_next(pState, -2) != 0) {
		// uses 'key' (at index -2) and 'value' (at index -1) 
		if (lua_isnumber(pState, -2)) {
			if (lua_istable(pState, -1))
				LUAToXMLElement(ex, pState, writer); // table child
			else if (lua_isstring(pState, -1))
				writer.write(lua_tostring(pState, -1), lua_objlen(pState, -1)); // __value
			else
				ex.set(Exception::APPLICATION, "Impossible to convert the value of type ", lua_typename(pState, lua_type(pState, -1)), "to a correct XML value of ",name);
		} else if (lua_type(pState, -2) != LUA_TSTRING)
			ex.set(Exception::APPLICATION, "Impossible to convert the key of type ",lua_typename(pState,lua_type(pState,-2)),"to a correct XML element of ",name);
		lua_pop(pState, 1);
	}

	writer.write("</").write(name).write(">");
	return true;
}
开发者ID:8088,项目名称:MonaServer,代码行数:47,代码来源:LUAXML.cpp

示例2: dump_to_file

void dump_to_file(PacketWriter &writer, int packet_count, PDU &packet) {
    while(packet_count--) {
        writer.write(packet);
    }
}
开发者ID:LXiong,项目名称:packet-capture-benchmarks,代码行数:5,代码来源:generator.cpp


注:本文中的PacketWriter::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。