2015-06-01 21:08:21 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
*/
|
|
|
|
function ContactBuffer(arrayBuffer) {
|
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
|
|
|
}
|
|
|
|
ContactBuffer.prototype = {
|
|
|
|
constructor: ContactBuffer,
|
|
|
|
readContact: function() {
|
|
|
|
try {
|
|
|
|
var len = this.buffer.readVarint32();
|
2015-06-03 19:51:37 +00:00
|
|
|
var contactInfoBuffer = this.buffer.slice(this.buffer.offset, this.buffer.offset+len);
|
|
|
|
var contactInfo = textsecure.protobuf.ContactDetails.decode(contactInfoBuffer);
|
2015-06-01 21:08:21 +00:00
|
|
|
this.buffer.skip(len);
|
2015-06-03 19:51:37 +00:00
|
|
|
var attachmentLen = contactInfo.avatar.length.toNumber();
|
|
|
|
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
2015-06-01 21:08:21 +00:00
|
|
|
this.buffer.skip(attachmentLen);
|
|
|
|
|
|
|
|
return contactInfo;
|
|
|
|
} catch(e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|