温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Egret之ProtoBuf(引用)

发布时间:2020-06-22 02:35:42 来源:网络 阅读:504 作者:Aonaufly 栏目:开发技术

前言 : 有时候 , 在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中 :
Egret之ProtoBuf(引用)
② , 我们可以看看生成的相关的.d.ts(protobuf-bundles.d.ts)
Egret之ProtoBuf(引用)

三 : 使用

        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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI