This is the proto file:
package net;
message msgBase {
optional string protoName = 1;
optional SendType sendType = 2;
//optional NetClient sendClient = 3;
optional float roomID = 4;
//optional NetClient tagClient = 5;
}
enum SendType
{
SendType_None = 0;
SendType_ALL = 1;
SendType_Self = 2;
SendType_Other = 3;
SendType_Tag = 4;
SendType_Specific = 5;
}
This is my Lua function:
local function msgBase()
pb.register_file("./proto/net.pb")
local msgbase = {
protoName = "msgDemo1",
sendType = SendType_Tag,
roomID = 7777,
}
local msg = pb.encode("net.msgBase",msgbase)
opp = msg
local tt = pb.decode("net.msgBase",msg)
if tt then
print(tt.protoName)
print(tt.sendType)
print(tt.roomID)
else
print("Error")
end
end
Result:
The value assigned to an enum and then decoded is always the first.
I am using PBC.
I coded C via ptotoB, where an error occurred for the enumeration type, which always shows the first value of the enumeration.

The example binding/lua53/test.lua shows that enums are specified by string value in Lua.
From the example, for the protocol (a snippet of addressbook.proto):
The following Lua code is used:
So you should use
otherwise the Lua variable
SendType_Tagresolves tonil, and the enum defaults to a zero value.