Новая сериализация, оптимизации приема и парсинга пакетов

This commit is contained in:
RoyceDa
2026-03-26 22:28:43 +02:00
parent bd3c0eec69
commit fd3fac54f6
3 changed files with 359 additions and 126 deletions

View File

@@ -14,6 +14,12 @@ export interface Attachment {
blob: string;
type: AttachmentType;
preview: string;
transport_tag: string;
transport_server: string;
/**
* Обозначает, для кого закодировано это вложение, нужно для того, чтобы не кодировать и не загружать заново пересланные сообщения, если они уже были закодированы для этого диалога
*/
encoded_for: string;
}
export class PacketMessage extends Packet {
@@ -42,7 +48,7 @@ export class PacketMessage extends Packet {
this.toPublicKey = stream.readString();
this.content = stream.readString();
this.chachaKey = stream.readString();
this.timestamp = stream.readInt64();
this.timestamp = Number(stream.readInt64());
this.privateKey = stream.readString();
this.messageId = stream.readString();
let attachmentsCount = stream.readInt8();
@@ -51,7 +57,10 @@ export class PacketMessage extends Packet {
let preview = stream.readString();
let blob = stream.readString();
let type = stream.readInt8() as AttachmentType;
this.attachments.push({id, preview, type, blob});
let transport_tag = stream.readString();
let transport_server = stream.readString();
let encoded_for = stream.readString();
this.attachments.push({id, preview, type, blob, transport_tag, transport_server, encoded_for});
}
this.aesChachaKey = stream.readString();
}
@@ -63,7 +72,7 @@ export class PacketMessage extends Packet {
stream.writeString(this.toPublicKey);
stream.writeString(this.content);
stream.writeString(this.chachaKey);
stream.writeInt64(this.timestamp);
stream.writeInt64(BigInt(this.timestamp));
stream.writeString(this.privateKey);
stream.writeString(this.messageId);
stream.writeInt8(this.attachments.length);
@@ -72,6 +81,9 @@ export class PacketMessage extends Packet {
stream.writeString(this.attachments[i].preview);
stream.writeString(this.attachments[i].blob);
stream.writeInt8(this.attachments[i].type);
stream.writeString(this.attachments[i].transport_tag);
stream.writeString(this.attachments[i].transport_server);
stream.writeString(this.attachments[i].encoded_for);
}
stream.writeString(this.aesChachaKey);
return stream;