MCPcopy Create free account
hub / github.com/Tencent/UnLua / lpb_readtype

Function lpb_readtype

Plugins/UnLuaExtensions/LuaProtobuf/Source/src/pb.cpp:458–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

456}
457
458static void lpb_readtype(lua_State *L, lpb_State *LS, int type, pb_Slice *s) {
459 lpb_Value v;
460 switch (type) {
461#define pushinteger(n,u) lpb_pushinteger((L), (n), (u), LS->int64_mode)
462 case PB_Tbool: case PB_Tenum:
463 case PB_Tint32: case PB_Tuint32: case PB_Tsint32:
464 case PB_Tint64: case PB_Tuint64: case PB_Tsint64:
465 if (pb_readvarint64(s, &v.u64) == 0)
466 luaL_error(L, "invalid varint value at offset %d", pb_pos(*s)+1);
467 switch (type) {
468 case PB_Tbool: lua_pushboolean(L, v.u64 != 0); break;
469 /*case PB_Tenum: pushinteger(v.u64); break; [> NOT REACHED <]*/
470 case PB_Tint32: pushinteger((int32_t)v.u64, 0); break;
471 case PB_Tuint32: pushinteger((uint32_t)v.u64, 1); break;
472 case PB_Tsint32: pushinteger(pb_decode_sint32((uint32_t)v.u64), 0); break;
473 case PB_Tint64: pushinteger((int64_t)v.u64, 0); break;
474 case PB_Tuint64: pushinteger((uint64_t)v.u64, 1); break;
475 case PB_Tsint64: pushinteger(pb_decode_sint64(v.u64), 0); break;
476 }
477 break;
478 case PB_Tfloat:
479 case PB_Tfixed32:
480 case PB_Tsfixed32:
481 if (pb_readfixed32(s, &v.u32) == 0)
482 luaL_error(L, "invalid fixed32 value at offset %d", pb_pos(*s)+1);
483 switch (type) {
484 case PB_Tfloat: lua_pushnumber(L, pb_decode_float(v.u32)); break;
485 case PB_Tfixed32: pushinteger(v.u32, 1); break;
486 case PB_Tsfixed32: pushinteger((int32_t)v.u32, 0); break;
487 }
488 break;
489 case PB_Tdouble:
490 case PB_Tfixed64:
491 case PB_Tsfixed64:
492 if (pb_readfixed64(s, &v.u64) == 0)
493 luaL_error(L, "invalid fixed64 value at offset %d", pb_pos(*s)+1);
494 switch (type) {
495 case PB_Tdouble: lua_pushnumber(L, pb_decode_double(v.u64)); break;
496 case PB_Tfixed64: pushinteger(v.u64, 1); break;
497 case PB_Tsfixed64: pushinteger((int64_t)v.u64, 0); break;
498 }
499 break;
500 case PB_Tbytes:
501 case PB_Tstring:
502 case PB_Tmessage:
503 lpb_readbytes(L, s, v.s);
504 push_slice(L, *v.s);
505 break;
506 default:
507 luaL_error(L, "unknown type %s (%d)", pb_typename(type, NULL), type);
508 }
509}
510
511
512/* io routines */

Callers 2

lpb_unpackfmtFunction · 0.85
lpbD_rawfieldFunction · 0.85

Calls 13

pb_readvarint64Function · 0.85
luaL_errorFunction · 0.85
pb_posFunction · 0.85
lua_pushbooleanFunction · 0.85
pb_decode_sint32Function · 0.85
pb_decode_sint64Function · 0.85
pb_readfixed32Function · 0.85
lua_pushnumberFunction · 0.85
pb_decode_floatFunction · 0.85
pb_readfixed64Function · 0.85
pb_decode_doubleFunction · 0.85
lpb_readbytesFunction · 0.85

Tested by

no test coverage detected