Configure `Long` before requiring compiled protobuf

This commit is contained in:
Fedor Indutny 2022-03-24 10:05:48 -07:00 committed by GitHub
parent 6d97976179
commit e8651afa0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 9 deletions

View File

@ -1,12 +1,8 @@
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as protobuf from 'protobufjs/minimal';
import Long from 'long';
import './wrap';
import { signalservice as SignalService } from './compiled';
protobuf.util.Long = Long;
protobuf.configure();
export { SignalService };

10
ts/protobuf/wrap.ts Normal file
View File

@ -0,0 +1,10 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as protobuf from 'protobufjs/minimal';
import Long from 'long';
protobuf.util.Long = Long;
protobuf.configure();
export default protobuf;

View File

@ -2,12 +2,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { Writer } from 'protobufjs';
import protobuf from '../protobuf/wrap';
import * as Bytes from '../Bytes';
import { SignalService as Proto } from '../protobuf';
import { ContactBuffer, GroupBuffer } from '../textsecure/ContactsParser';
const { Writer } = protobuf;
describe('ContactsParser', () => {
function generateAvatar(): Uint8Array {
const result = new Uint8Array(255);

View File

@ -3,7 +3,7 @@
/* eslint-disable max-classes-per-file */
import { Reader } from 'protobufjs';
import protobuf from '../protobuf/wrap';
import { SignalService as Proto } from '../protobuf';
import { normalizeUuid } from '../util/normalizeUuid';
@ -11,10 +11,12 @@ import * as log from '../logging/log';
import Avatar = Proto.ContactDetails.IAvatar;
const { Reader } = protobuf;
type OptionalAvatar = { avatar?: Avatar | null };
type DecoderBase<Message extends OptionalAvatar> = {
decodeDelimited(reader: Reader): Message | undefined;
decodeDelimited(reader: protobuf.Reader): Message | undefined;
};
export type MessageWithAvatar<Message extends OptionalAvatar> = Omit<
@ -32,7 +34,7 @@ class ParserBase<
Message extends OptionalAvatar,
Decoder extends DecoderBase<Message>
> {
protected readonly reader: Reader;
protected readonly reader: protobuf.Reader;
constructor(bytes: Uint8Array, private readonly decoder: Decoder) {
this.reader = new Reader(bytes);