MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / mp_pack

Function mp_pack

deps/lua/src/lua_cmsgpack.c:512–545  ·  view source on GitHub ↗

* Packs all arguments as a stream for multiple upacking later. * Returns error if no arguments provided. */

Source from the content-addressed store, hash-verified

510 * Returns error if no arguments provided.
511 */
512int mp_pack(lua_State *L) {
513 int nargs = lua_gettop(L);
514 int i;
515 mp_buf *buf;
516
517 if (nargs == 0)
518 return luaL_argerror(L, 0, "MessagePack pack needs input.");
519
520 if (!lua_checkstack(L, nargs))
521 return luaL_argerror(L, 0, "Too many arguments for MessagePack pack.");
522
523 buf = mp_buf_new(L);
524 for(i = 1; i <= nargs; i++) {
525 /* Copy argument i to top of stack for _encode processing;
526 * the encode function pops it from the stack when complete. */
527 luaL_checkstack(L, 1, "in function mp_check");
528 lua_pushvalue(L, i);
529
530 mp_encode_lua_type(L,buf,0);
531
532 lua_pushlstring(L,(char*)buf->b,buf->len);
533
534 /* Reuse the buffer for the next operation by
535 * setting its free count to the total buffer size
536 * and the current position to zero. */
537 buf->free += buf->len;
538 buf->len = 0;
539 }
540 mp_buf_free(L, buf);
541
542 /* Concatenate all nargs buffers together */
543 lua_concat(L, nargs);
544 return 1;
545}
546
547/* ------------------------------- Decoding --------------------------------- */
548

Callers

nothing calls this directly

Calls 10

lua_gettopFunction · 0.85
luaL_argerrorFunction · 0.85
lua_checkstackFunction · 0.85
mp_buf_newFunction · 0.85
luaL_checkstackFunction · 0.85
lua_pushvalueFunction · 0.85
mp_encode_lua_typeFunction · 0.85
lua_pushlstringFunction · 0.85
mp_buf_freeFunction · 0.85
lua_concatFunction · 0.85

Tested by

no test coverage detected