2015-06-01 21:08:21 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
*/
|
2015-06-22 21:45:42 +00:00
|
|
|
|
|
|
|
function ProtoParser(arrayBuffer, protobuf) {
|
|
|
|
this.protobuf = protobuf;
|
2015-06-03 19:51:37 +00:00
|
|
|
this.buffer = new dcodeIO.ByteBuffer();
|
|
|
|
this.buffer.append(arrayBuffer);
|
|
|
|
this.buffer.offset = 0;
|
|
|
|
this.buffer.limit = arrayBuffer.byteLength;
|
2015-06-01 21:08:21 +00:00
|
|
|
}
|
2015-06-22 21:45:42 +00:00
|
|
|
ProtoParser.prototype = {
|
|
|
|
constructor: ProtoParser,
|
|
|
|
next: function() {
|
2015-06-01 21:08:21 +00:00
|
|
|
try {
|
2015-06-17 22:59:14 +00:00
|
|
|
if (this.buffer.limit === this.buffer.offset) {
|
|
|
|
return undefined; // eof
|
|
|
|
}
|
2015-06-22 21:45:42 +00:00
|
|
|
var len = this.buffer.readVarint32();
|
|
|
|
var nextBuffer = this.buffer.slice(
|
|
|
|
this.buffer.offset, this.buffer.offset+len
|
|
|
|
).toArrayBuffer();
|
|
|
|
// TODO: de-dupe ByteBuffer.js includes in libaxo/libts
|
|
|
|
// then remove this toArrayBuffer call.
|
|
|
|
|
|
|
|
var proto = this.protobuf.decode(nextBuffer);
|
2015-06-01 21:08:21 +00:00
|
|
|
this.buffer.skip(len);
|
2015-06-22 21:45:42 +00:00
|
|
|
|
|
|
|
if (proto.avatar) {
|
|
|
|
var attachmentLen = proto.avatar.length;
|
|
|
|
proto.avatar.data = this.buffer.slice(
|
|
|
|
this.buffer.offset, this.buffer.offset + attachmentLen
|
|
|
|
).toArrayBuffer();
|
2015-06-17 22:59:14 +00:00
|
|
|
this.buffer.skip(attachmentLen);
|
|
|
|
}
|
2015-06-01 21:08:21 +00:00
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
if (proto.profileKey) {
|
|
|
|
proto.profileKey = proto.profileKey.toArrayBuffer();
|
|
|
|
}
|
|
|
|
|
2015-06-22 21:45:42 +00:00
|
|
|
return proto;
|
2015-06-01 21:08:21 +00:00
|
|
|
} catch(e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-06-22 21:45:42 +00:00
|
|
|
var GroupBuffer = function(arrayBuffer) {
|
|
|
|
ProtoParser.call(this, arrayBuffer, textsecure.protobuf.GroupDetails);
|
|
|
|
};
|
|
|
|
GroupBuffer.prototype = Object.create(ProtoParser.prototype);
|
|
|
|
GroupBuffer.prototype.constructor = GroupBuffer;
|
|
|
|
var ContactBuffer = function(arrayBuffer) {
|
|
|
|
ProtoParser.call(this, arrayBuffer, textsecure.protobuf.ContactDetails);
|
|
|
|
};
|
|
|
|
ContactBuffer.prototype = Object.create(ProtoParser.prototype);
|
|
|
|
ContactBuffer.prototype.constructor = ContactBuffer;
|