[]静态protobuf

dcodeIO是有静态protobuf方式,即生成.proto对应的js文件。请问layaair内置的protobuf.js支持这种方式吗
已邀请:

qian

赞同来自:

LayaAir中protobuf用的是github上的,你直接去官网看下吧

田 浩

赞同来自:

用@egret/protobuf是比较简单的,而且不用改 tsconfig.json就可以用额
https://blog.csdn.net/sjt223857130/article/details/79658158
 
可以支持proto3
msgScheme.proto 放到 protofile 文件夹下
syntax = "proto3";
option java_package = "msgScheme";
package msgScheme;
message AMsg {
enum Head {
Undefined_Msg = 0;
Undefined_Request = 1;
Undefined_Response = 2;
Login_Request = 100001;
Login_Response = 100002; 
CreateRoom_Request = 100003;
CreateRoom_Response = 100004;
}
Head head = 1; 
oneof body {
LoginRequest loginRequest = 2;
LoginResponse loginResponse = 3;
UndefinedMsg undefinedMsg = 4;
UndefinedRequest undefinedRequest = 5;
UndefinedResponse undefinedResponse = 6;

}
//0
message UndefinedMsg { 
}
//1
message UndefinedRequest { 
}
//2
message UndefinedResponse { 

//100001
message LoginRequest {
string userId = 1;
string password = 2; 
}
//100002
message LoginResponse {
bool ok = 1; 
}
发消息时比较简单
let msg = msgScheme.AMsg.create({
head: msgScheme.AMsg.Head.Login_Request,
loginRequest: {
userId: this.TextInput.text,
password: "bbb"
}
})
let buffer = msgScheme.AMsg.encode(msg).finish()
this.socket.send(buffer)
 
收消息时要先装到byte里再decode出来
private receiveHandler(msg): void { 
 
this.byte.clear()
this.byte.writeArrayBuffer(msg)
this.byte.pos = 0
let aMsg = msgScheme.AMsg.decode(this.byte.readUint8Array(0, 100000))

要回复问题请先

商务合作
商务合作