[Updt] Mtp 0.3.0
Some checks failed
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Test native MTP (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
/ build-web (push) Failing after 3m32s
/ build-desktop (linux) (push) Failing after 2m47s
/ build-mobile (push) Failing after 5m29s
/ release (push) Has been skipped
Some checks failed
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Test native MTP (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
/ build-web (push) Failing after 3m32s
/ build-desktop (linux) (push) Failing after 2m47s
/ build-mobile (push) Failing after 5m29s
/ release (push) Has been skipped
This commit is contained in:
parent
57c7ceb27a
commit
2a55c87df1
33 changed files with 1825 additions and 785 deletions
24
packages/mtp/src/requestIds.ts
Normal file
24
packages/mtp/src/requestIds.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const MAX_MTP_REQUEST_ID = 0xffff_ffff;
|
||||
|
||||
export class RequestIdAllocator {
|
||||
#next: number;
|
||||
|
||||
constructor(next = 1) {
|
||||
if (
|
||||
!Number.isSafeInteger(next) ||
|
||||
next <= 0 ||
|
||||
next > MAX_MTP_REQUEST_ID + 1
|
||||
) {
|
||||
throw new RangeError("invalid MTP request ID allocator state");
|
||||
}
|
||||
this.#next = next;
|
||||
}
|
||||
|
||||
allocate(): number {
|
||||
if (this.#next > MAX_MTP_REQUEST_ID) {
|
||||
throw new Error("MTP request ID space exhausted for this connection");
|
||||
}
|
||||
|
||||
return this.#next++;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue