Fix fetching rpc_error instead of Vector

This commit is contained in:
Eduard Kuzmenko 2021-07-23 15:23:17 +03:00
parent 6e53c8f443
commit 6f9db2c422

View File

@ -634,6 +634,19 @@ class TLDeserialization {
return bytes; return bytes;
} }
private fetchVector(type: string, field?: string) {
const len = this.readInt(field + '[count]');
const result: any[] = new Array(len);
if(len > 0) {
const itemType = type.substr(7, type.length - 8); // for "Vector<itemType>"
for(let i = 0; i < len; ++i) {
result[i] = this.fetchObject(itemType, field + '[' + i + ']');
}
}
return result;
}
public fetchObject(type: string, field?: string): any { public fetchObject(type: string, field?: string): any {
switch(type) { switch(type) {
@ -662,33 +675,8 @@ class TLDeserialization {
field = field || type || 'Object'; field = field || type || 'Object';
if(type.charAt(0).toLowerCase() === 'v' && type.substr(1, 5) === 'ector') { if(type.charAt(0) === 'v' && type.substr(1, 5) === 'ector') {
if(type.charAt(0) === 'V') { return this.fetchVector(type, field);
const constructorCmp = this.readInt(field + '[id]');
if(constructorCmp === gzipPacked) { // Gzip packed
const compressed = this.fetchBytes(field + '[packed_string]');
const uncompressed = gzipUncompress(compressed) as Uint8Array;
const newDeserializer = new TLDeserialization(uncompressed);
return newDeserializer.fetchObject(type, field);
}
if(constructorCmp !== vector) {
throw new Error('Invalid vector constructor ' + constructorCmp);
}
}
const len = this.readInt(field + '[count]');
const result: any[] = new Array(len);
if(len > 0) {
const itemType = type.substr(7, type.length - 8); // for "Vector<itemType>"
for(let i = 0; i < len; ++i) {
result[i] = this.fetchObject(itemType, field + '[' + i + ']');
}
}
return result;
} }
const schema = this.mtproto ? Schema.MTProto : Schema.API; const schema = this.mtproto ? Schema.MTProto : Schema.API;
@ -716,6 +704,10 @@ class TLDeserialization {
return newDeserializer.fetchObject(type, field); return newDeserializer.fetchObject(type, field);
} }
if(constructorCmp === vector) {
return this.fetchVector(type, field);
}
let index = schema.constructorsIndex; let index = schema.constructorsIndex;
if(!index) { if(!index) {