static void pack_from(lua_State *L, struct write_block *b, int from) { int n = lua_gettop(L) - from; int i; for (i=1;i<=n;i++) { pack_one(L, b , from + i, 0); } }
void Message <Args...>::pack_one (StreamBinOut & sbo, const std::map <U, V> & val) { sbo << uint64_t (val.size ()); for (const auto & sub_val : val) { pack_one (sbo, sub_val); } }
static void wb_table_hash(lua_State *L, struct write_block * wb, int index, int depth, int array_size) { lua_pushnil(L); while (lua_next(L, index) != 0) { if (lua_type(L,-2) == LUA_TNUMBER) { if (lua_isinteger(L, -2)) { lua_Integer x = lua_tointeger(L,-2); if (x>0 && x<=array_size) { lua_pop(L,1); continue; } } } pack_one(L,wb,-2,depth); pack_one(L,wb,-1,depth); lua_pop(L, 1); } wb_nil(wb); }
typename std::enable_if < !std::is_same <U, uint8_t>::value >::type Message <Args...>::pack_one (StreamBinOut & sbo, const std::vector <U> & val) { sbo << uint64_t (val.size ()); for (const auto & sub_val : val) { pack_one (sbo, sub_val); } }
static void wb_table_metapairs(lua_State *L, struct write_block *wb, int index, int depth) { uint8_t n = COMBINE_TYPE(TYPE_TABLE, 0); wb_push(wb, &n, 1); lua_pushvalue(L, index); lua_call(L, 1, 3); for(;;) { lua_pushvalue(L, -2); lua_pushvalue(L, -2); lua_copy(L, -5, -3); lua_call(L, 2, 2); int type = lua_type(L, -2); if (type == LUA_TNIL) { lua_pop(L, 4); break; } pack_one(L, wb, -2, depth); pack_one(L, wb, -1, depth); lua_pop(L, 1); } wb_nil(wb); }
static int wb_table_array(lua_State *L, struct write_block * wb, int index, int depth) { int array_size = lua_rawlen(L,index); if (array_size >= MAX_COOKIE-1) { uint8_t n = COMBINE_TYPE(TYPE_TABLE, MAX_COOKIE-1); wb_push(wb, &n, 1); wb_integer(wb, array_size); } else { uint8_t n = COMBINE_TYPE(TYPE_TABLE, array_size); wb_push(wb, &n, 1); } int i; for (i=1;i<=array_size;i++) { lua_rawgeti(L,index,i); pack_one(L, wb, -1, depth); lua_pop(L,1); } return array_size; }
void Message <Args...>::pack (StreamBinOut & sbo, U val, Args2... args) { pack_one (sbo, val); pack (sbo, args...); }
void Message <Args...>::pack (StreamBinOut & sbo, U val) { pack_one (sbo, val); pack (sbo); }
void Message <Args...>::pack_one (StreamBinOut & sbo, const std::pair <U, V> & val) { pack_one (sbo, val.first); pack_one (sbo, val.second); }