js解析protobuf
js如何解析protobuf。。。
1,服务端把数据经过protobuf,在经过64位编码发送到我客户端。
2,客户端用js解析。
(1),我在网上找到例子。把服务端给我的64位编码解析了。
(2),解析完以后,我要把它经过protobuf解析。(这里不会,我用的谷歌很早提供的protobuf-js也不行(它的js本身就有语法错误)。) http://blog.csdn.net/xnn2s/article/details/8580917博客说能够解决,但是我看到。(js plugin须要我们自己编译,步骤如下:1. 先下载整个protobuf,编译出protoc和各种lib库。)我遇到问题,1,它这个没法下载。2,我也不知道怎么编译。
不按照这个思路也行,只要js能解析protobuf就行。。。
(1)的例子在这儿
this.decode = function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = _keyStr.indexOf(input.charAt(i++));
enc2 = _keyStr.indexOf(input.charAt(i++));
enc3 = _keyStr.indexOf(input.charAt(i++));
enc4 = _keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = _utf8_decode(output);
return output;
}