Use protopiler for protocol buffers

Co-authored-by: Jamie Kyle <jamie@signal.org>
This commit is contained in:
Fedor Indutny
2026-03-10 15:31:29 -07:00
committed by GitHub
parent b0e19f334e
commit c4ee32e9ee
97 changed files with 6197 additions and 6362 deletions

View File

@@ -15,7 +15,6 @@ import { pipeline } from 'node:stream/promises';
import { Transform } from 'node:stream';
import fse from 'fs-extra';
import protobuf from '../protobuf/wrap.std.js';
import { createLogger } from '../logging/log.std.js';
import * as Bytes from '../Bytes.std.js';
import * as Errors from '../types/errors.std.js';
@@ -33,6 +32,7 @@ import {
} from '../textsecure/ContactsParser.preload.js';
import type { ContactDetailsWithAvatar } from '../textsecure/ContactsParser.preload.js';
import { strictAssert } from '../util/assert.std.js';
import { encodeDelimited } from '../util/encodeDelimited.std.js';
import { toAciObject } from '../util/ServiceId.node.js';
import {
generateKeys,
@@ -41,8 +41,6 @@ import {
const log = createLogger('ContactsParser_test');
const { Writer } = protobuf;
const DEFAULT_ACI = generateAci();
describe('ContactsParser', () => {
@@ -115,7 +113,7 @@ describe('ContactsParser', () => {
try {
const bytes = Bytes.concatenate([
generatePrefixedContact(undefined),
...generatePrefixedContact(undefined),
getTestBuffer(),
]);
@@ -195,7 +193,7 @@ function getTestBuffer(): Uint8Array {
const chunks: Array<Uint8Array> = [];
for (let i = 0; i < 3; i += 1) {
chunks.push(prefixedContact);
chunks.push(...prefixedContact);
chunks.push(avatarBuffer);
}
@@ -205,20 +203,21 @@ function getTestBuffer(): Uint8Array {
function generatePrefixedContact(
avatarBuffer: Uint8Array | undefined,
aci: AciString | null = DEFAULT_ACI
) {
): [Uint8Array, Uint8Array] {
const contactInfoBuffer = Proto.ContactDetails.encode({
name: 'Zero Cool',
number: '+10000000000',
aci: null,
aciBinary: aci == null ? null : toAciObject(aci).getRawUuidBytes(),
avatar: avatarBuffer
? { contentType: 'image/jpeg', length: avatarBuffer.length }
: undefined,
}).finish();
: null,
expireTimer: null,
expireTimerVersion: null,
inboxPosition: null,
});
const writer = new Writer();
writer.bytes(contactInfoBuffer);
const prefixedContact = writer.finish();
return prefixedContact;
return encodeDelimited(contactInfoBuffer);
}
async function verifyContact(