lua 中protobuf repeated 嵌套类 复合类型

PB基础知识科普

syntax = "proto2";
package PB;

message  Item
{
    required string name = 1;
}
message  Role
{
    required string name = 1;  
    optional string email = 2;  
    repeated string t =3;
    repeated Item item1 = 4;
    optional  Item item2 =5;  
}

lua中解析 required optional repeated 类型

   require "proto.player_pb"

    local role = player_pb.Role()
    role.name="444"   --require字段

    role.email ="eiail2222222" --optional
    role.t:append("111") --repeated 基本类型

    local tt =role.item1:add() -- repeated 嵌套类 复合类型
    tt.name ="555"

    role.item2.name = "6666" -- optional 嵌套类 复合类型

    local pb_data1 = role:SerializeToString()
    
    local msg = player_pb.Role()
    msg:ParseFromString(pb_data1)

    print(msg.email.."   "..msg.item1[1].name.."  "..msg.item2.name)