前言 : 有时候 , 在proto中的一个类需要引用另一个类 . 本篇既是为解释这一问题的.




一 : test.proto(在protobuf\protofile中)

package Test;message LVO{ required string message = 1; required int32 priority = 2;}message Login{ required string userName = 1; required string password = 2; optional int32 sex = 3; required LVO lvo = 4; required bool isFirstLogin = 5; repeated string param = 6;}

① , Login引用了LVO

二 : 使用命令pb-egret generate

① , 必须注意的是 : proto文件在protobuf\protofile中,这样使用pb-egret generate后,会生成文件在protobuf\bundles中 :

② , 我们可以看看生成的相关的.d.ts(protobuf-bundles.d.ts)

三 : 使用

let $login : Test.ILogin = new Test.Login({ userName:"Aonaufly", password:"123456", sex:1, lvo:{ message : "Snow", priority : 1 }, isFirstLogin:false, param:["test", "array", "param"] });

① , 使用Login中的lvo数据 $login.lvo.message