You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
/*
|
|
* vim: ts=4:sw=4:expandtab
|
|
*/
|
|
function ContactBuffer(arrayBuffer) {
|
|
this.buffer = new dcodeIO.ByteBuffer();
|
|
this.buffer.append(arrayBuffer);
|
|
this.buffer.offset = 0;
|
|
this.buffer.limit = arrayBuffer.byteLength;
|
|
}
|
|
ContactBuffer.prototype = {
|
|
constructor: ContactBuffer,
|
|
readContact: function() {
|
|
try {
|
|
if (this.buffer.limit === this.buffer.offset) {
|
|
return undefined; // eof
|
|
}
|
|
var len = this.buffer.readVarint64().toNumber();
|
|
var contactInfoBuffer = this.buffer.slice(this.buffer.offset, this.buffer.offset+len);
|
|
var contactInfo = textsecure.protobuf.ContactDetails.decode(contactInfoBuffer);
|
|
this.buffer.skip(len);
|
|
if (contactInfo.avatar) {
|
|
var attachmentLen = contactInfo.avatar.length.toNumber();
|
|
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
|
this.buffer.skip(attachmentLen);
|
|
}
|
|
|
|
return contactInfo;
|
|
} catch(e) {
|
|
console.log(e);
|
|
}
|
|
}
|
|
};
|