[]微信小游戏中不能加载proto文件
5.17号别人问的问题,就回复了一个
同一个问题不少刷屏
那请问现在是能不能用Protobuf还是不能用,我现在用是不能用。那到底怎么才能用?请告知一个具体可行的方案。
request:fail invalid url "res/protobuf/Login.proto"
具体代码:
(function () {
var Loader = Laya.Loader;
var Browser = Laya.Browser;
var Handler = Laya.Handler;
console.log("!____________________________________")
var ProtoBuf = Browser.window.protobuf;
// Laya.init(550, 400);
ProtoBuf.load("res/protobuf/Login.proto", onAssetsLoaded);
function onAssetsLoaded(err, root) {
console.log("____________________________________")
if (err)
throw err;
// Obtain a message type
var AwesomeMessage = root.lookup("msg.LoginReq");
// Create a new message
var message = AwesomeMessage.create(
{
openid: "AwesomeString"
});
console.log(message.openid)
// Verify the message if necessary (i.e. when possibly incomplete or invalid)
var errMsg = AwesomeMessage.verify(message);
if (errMsg)
throw Error(errMsg);
// Encode a message to an Uint8Array (browser) or Buffer (node)
var buffer = AwesomeMessage.encode(message).finish();
// ... do something with buffer
// Or, encode a plain object
var buffer = AwesomeMessage.encode(
{
awesomeField: "AwesomeString"
}).finish();
// ... do something with buffer
// Decode an Uint8Array (browser) or Buffer (node) to a message
var message = AwesomeMessage.decode(buffer);
// ... do something with message
// If your application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
}
})();
同一个问题不少刷屏
那请问现在是能不能用Protobuf还是不能用,我现在用是不能用。那到底怎么才能用?请告知一个具体可行的方案。
request:fail invalid url "res/protobuf/Login.proto"
具体代码:
(function () {
var Loader = Laya.Loader;
var Browser = Laya.Browser;
var Handler = Laya.Handler;
console.log("!____________________________________")
var ProtoBuf = Browser.window.protobuf;
// Laya.init(550, 400);
ProtoBuf.load("res/protobuf/Login.proto", onAssetsLoaded);
function onAssetsLoaded(err, root) {
console.log("____________________________________")
if (err)
throw err;
// Obtain a message type
var AwesomeMessage = root.lookup("msg.LoginReq");
// Create a new message
var message = AwesomeMessage.create(
{
openid: "AwesomeString"
});
console.log(message.openid)
// Verify the message if necessary (i.e. when possibly incomplete or invalid)
var errMsg = AwesomeMessage.verify(message);
if (errMsg)
throw Error(errMsg);
// Encode a message to an Uint8Array (browser) or Buffer (node)
var buffer = AwesomeMessage.encode(message).finish();
// ... do something with buffer
// Or, encode a plain object
var buffer = AwesomeMessage.encode(
{
awesomeField: "AwesomeString"
}).finish();
// ... do something with buffer
// Decode an Uint8Array (browser) or Buffer (node) to a message
var message = AwesomeMessage.decode(buffer);
// ... do something with message
// If your application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
}
})();
没有找到相关结果
已邀请:
要回复问题请先登录
15 个回复
。
赞同来自: 132*****633
Aar0n
赞同来自:
Aar0n
赞同来自:
Vongola
赞同来自:
Laya.Browser.window.protobuf.load我用这个会加载不到文件
Prajna
赞同来自:
Aar0n
赞同来自:
Prajna
赞同来自:
Prajna
赞同来自:
Vongola
赞同来自:
proto自己会调用原生http下载,所以如果是远程的,要加上域名。
Laya.Browser.window.protobuf.load(Laya.URL.basePath+url)
proto会把https://变成https:/,微信下载就报错了。
在protobuf.js的function fetch_xhr方法最后把fileName改成//就可以load成功,
var names=filename.split('/');
if(names[0]=="http:"||names[0]=="https:"){
filename=names[0]+"/";
for(var i=1;i<names.length;i++){
filename+=('/'+names[i]);
}
}
xhr.open("GET", filename);
xhr.send();我是这么改的,可以成功把消息发出去了,但是解析又出了问题
gameThirdScriptError
Cannot read property 'apply' of undefined;at api request success callback function
TypeError: Cannot read property 'apply' of undefined
at Function.eof (http://127.0.0.1:34822/game/code.js:52215:69)
at Class (http://127.0.0.1:34822/game/code.js:52729:37)
at Type.get (http://127.0.0.1:34822/game/code.js:57693:48)
at Type.create (http://127.0.0.1:34822/game/code.js:57856:20)
at Proto.EncodeMessage (http://127.0.0.1:34822/game/code.js:63461:31)
at NetManager.HttpPostProto (http://127.0.0.1:34822/game/code.js:63513:33)
at NetController.login (http://127.0.0.1:34822/game/code.js:63611:25)
at NetController.loginCommon (http://127.0.0.1:34822/game/code.js:63597:18)
at NetController.Login (http://127.0.0.1:34822/game/code.js:63582:22)
at Main.login (http://127.0.0.1:34822/game/code.js:63904:22)
Aar0n
赞同来自:
Prajna
赞同来自:
Prajna
赞同来自:
Aar0n
赞同来自:
https://www.jianshu.com/p/fa67930cb4fa
只能帮到这里了,这个问题研究几天了。
Feng
赞同来自:
sdjkxhb
赞同来自: