void pack(Packer& pk, int index) const { int t = lua_type(L, index); switch (t) { case LUA_TNUMBER: packNumber(pk, index); break; case LUA_TBOOLEAN: packBoolean(pk, index); break; case LUA_TSTRING: packString(pk, index); break; case LUA_TTABLE: packTable(pk, index); break; case LUA_TUSERDATA: // TODO: support userdata serialization. // Calling __serialize meta-method may be good. // raise an error temporally luaL_error(L, "Packing userdata has not been supported yet. " "However, it will be implemented soon."); return; case LUA_TNIL: case LUA_TTHREAD: case LUA_TLIGHTUSERDATA: default: luaL_error(L, "invalid type for pack: %s", lua_typename(L, t)); break; } }
void packFilesIncoming( std::vector<char> &buf, const std::unordered_multimap<std::string, Transfer::FileIncoming> &map ) { packNumber(buf, map.size() ); for (auto it = map.cbegin(); map.cend() != it; ++it) { packString(buf, it->first); const Transfer::FileIncoming &file = it->second; packString(buf, file.getTmpName() ); packString(buf, file.getName() ); packString(buf, file.getType() ); packNumber(buf, file.getSize() ); } }