Move to protobufjs in ts/groups.ts
This commit is contained in:
parent
972a4cba0c
commit
9f0c630574
30 changed files with 1424 additions and 964 deletions
57
ts/context/Bytes.ts
Normal file
57
ts/context/Bytes.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/* eslint-disable class-methods-use-this */
|
||||
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
export class Bytes {
|
||||
public fromBase64(value: string): Uint8Array {
|
||||
return Buffer.from(value, 'base64');
|
||||
}
|
||||
|
||||
public fromHex(value: string): Uint8Array {
|
||||
return Buffer.from(value, 'hex');
|
||||
}
|
||||
|
||||
// TODO(indutny): deprecate it
|
||||
public fromBinary(value: string): Uint8Array {
|
||||
return Buffer.from(value, 'binary');
|
||||
}
|
||||
|
||||
public fromString(value: string): Uint8Array {
|
||||
return Buffer.from(value);
|
||||
}
|
||||
|
||||
public toBase64(data: Uint8Array): string {
|
||||
return Buffer.from(data).toString('base64');
|
||||
}
|
||||
|
||||
public toHex(data: Uint8Array): string {
|
||||
return Buffer.from(data).toString('hex');
|
||||
}
|
||||
|
||||
// TODO(indutny): deprecate it
|
||||
public toBinary(data: Uint8Array): string {
|
||||
return Buffer.from(data).toString('binary');
|
||||
}
|
||||
|
||||
public toString(data: Uint8Array): string {
|
||||
return Buffer.from(data).toString();
|
||||
}
|
||||
|
||||
public concatenate(list: ReadonlyArray<Uint8Array>): Uint8Array {
|
||||
return Buffer.concat(list);
|
||||
}
|
||||
|
||||
public isEmpty(data: Uint8Array | null | undefined): boolean {
|
||||
if (!data) {
|
||||
return true;
|
||||
}
|
||||
return data.length === 0;
|
||||
}
|
||||
|
||||
public isNotEmpty(data: Uint8Array | null | undefined): data is Uint8Array {
|
||||
return !this.isEmpty(data);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue