We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
lua代码:
protoc:load([[ syntax = "proto3"; message TestNumber { double a = 1; float b = 2; int32 c = 3; } ]]) local tt = { a = 100, b = 200, c = 300 } local s = pb.encode("TestNumber", tt) PBTestNumber(s)
C++代码:
int PBTestNumber(lua_State* L) { string s = lua_tostring(L, 1); TestNumber* msg = new TestNumber(); msg->ParseFromString(s); std::cout << "in PBTestNumber msg=" << msg->ShortDebugString() << std::endl; return 0; }
这里输出的是:in PBTestNumber msg=c: 300
The text was updated successfully, but these errors were encountered:
我感觉ParseFromString有问题,得到的是二进制数据,你没取长度会在0的地方截断
Sorry, something went wrong.
用ParseFromArray,改成下面这样就ok了。多谢大佬。
int PBTestNumber(lua_State* L) { size_t len; const char* s = lua_tolstring(L, 1, &len); TestNumber * msg = new TestNumber(); msg->ParseFromArray(s, len); std::cout << "in PBTestNumber msg=" << msg->ShortDebugString() << std::endl; return 0; }
No branches or pull requests
lua代码:
C++代码:
这里输出的是:in PBTestNumber msg=c: 300
The text was updated successfully, but these errors were encountered: