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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM