mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-05 02:39:26 +02:00
refactor(adb): let backends deserialize packets by themselves for better optimization
This commit is contained in:
parent
38a76a2e0c
commit
8a521c8d93
11 changed files with 61 additions and 70 deletions
|
@ -1,4 +1,4 @@
|
|||
import { AdbBackend, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream } from '@yume-chan/adb';
|
||||
import { AdbBackend, AdbPacket, AdbPacketSerializeStream, pipeFrom, ReadableStream, StructDeserializeStream, WrapReadableStream, WrapWritableStream, WritableStream } from '@yume-chan/adb';
|
||||
|
||||
declare global {
|
||||
interface TCPSocket {
|
||||
|
@ -55,6 +55,7 @@ export default class AdbDirectSocketsBackend implements AdbBackend {
|
|||
remotePort: this.port,
|
||||
noDelay: true,
|
||||
});
|
||||
|
||||
// Native streams can't `pipeTo()` or `pipeThrough()` polyfilled streams, so we need to wrap them
|
||||
return {
|
||||
readable: new WrapReadableStream<Uint8Array, ReadableStream<Uint8Array>, void>({
|
||||
|
@ -64,15 +65,15 @@ export default class AdbDirectSocketsBackend implements AdbBackend {
|
|||
state: undefined,
|
||||
};
|
||||
}
|
||||
}),
|
||||
writable: new WrapWritableStream({
|
||||
}).pipeThrough(new StructDeserializeStream(AdbPacket)),
|
||||
writable: pipeFrom(new WrapWritableStream({
|
||||
async start() {
|
||||
return {
|
||||
writable,
|
||||
state: undefined,
|
||||
};
|
||||
}
|
||||
}),
|
||||
}), new AdbPacketSerializeStream()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue