| 1945 | } |
| 1946 | |
| 1947 | static int lpbD_unpack(lpb_Env* e, const pb_Type* t) { |
| 1948 | lua_State* L = e->L; |
| 1949 | int top = lua_gettop(L); |
| 1950 | uint32_t tag; |
| 1951 | int last_index = 0; |
| 1952 | unsigned int decode_count = 0; |
| 1953 | pb_Field **list = pb_sortfield((pb_Type*)t); |
| 1954 | lua_settop(L, top + t->field_count); |
| 1955 | luaL_checkstack(L, t->field_count * 2, "not enough stack space for fields"); |
| 1956 | while (pb_readvarint32(e->s, &tag)) { |
| 1957 | const pb_Field* f = pb_field(t, pb_gettag(tag)); |
| 1958 | if (last_index && (!f || f->sort_index != last_index)) { |
| 1959 | decode_count++; |
| 1960 | lua_replace(L, top + last_index); |
| 1961 | last_index = 0; |
| 1962 | } |
| 1963 | last_index = lpb_unpackfield(e, f, tag, last_index); |
| 1964 | } |
| 1965 | if (last_index) { |
| 1966 | decode_count++; |
| 1967 | lua_replace(L, top + last_index); |
| 1968 | } |
| 1969 | if (decode_count != t->field_count) lpb_pushunpackdef(L, e->LS, t, list, top); |
| 1970 | return t->field_count; |
| 1971 | } |
| 1972 | |
| 1973 | static int Lpb_unpack(lua_State* L) { |
| 1974 | lpb_State* LS = lpb_lstate(L); |
no test coverage detected