UNPKG

@yume-chan/adb

Version:

TypeScript implementation of Android Debug Bridge (ADB) protocol.

32 lines 1.27 kB
import { encodeUtf8, struct, u32 } from "@yume-chan/struct"; import { adbSyncEncodeId } from "./response.js"; export const AdbSyncRequestId = { List: adbSyncEncodeId("LIST"), ListV2: adbSyncEncodeId("LIS2"), Send: adbSyncEncodeId("SEND"), SendV2: adbSyncEncodeId("SND2"), Lstat: adbSyncEncodeId("STAT"), Stat: adbSyncEncodeId("STA2"), LstatV2: adbSyncEncodeId("LST2"), Data: adbSyncEncodeId("DATA"), Done: adbSyncEncodeId("DONE"), Receive: adbSyncEncodeId("RECV"), }; export const AdbSyncNumberRequest = struct({ id: u32, arg: u32 }, { littleEndian: true }); export async function adbSyncWriteRequest(writable, id, value) { if (typeof id === "string") { id = adbSyncEncodeId(id); } if (typeof value === "number") { await writable.write(AdbSyncNumberRequest.serialize({ id, arg: value })); return; } if (typeof value === "string") { value = encodeUtf8(value); } // `writable` is buffered, it copies inputs to an internal buffer, // so don't concatenate headers and data here, that will be an unnecessary copy. await writable.write(AdbSyncNumberRequest.serialize({ id, arg: value.length })); await writable.write(value); } //# sourceMappingURL=request.js.map