本文整理汇总了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;
}
示例2: dump_to_file
void dump_to_file(PacketWriter &writer, int packet_count, PDU &packet) {
while(packet_count--) {
writer.write(packet);
}
}