Loading .changeset/some-tigers-hide.md 0 → 100644 +5 −0 Original line number Diff line number Diff line --- "@yume-chan/struct": major --- Refactor struct package to allow `struct`s to be used as `field` libraries/adb-daemon-webusb/src/device.ts +1 −25 Original line number Diff line number Diff line Loading @@ -19,8 +19,7 @@ import { ReadableStream, pipeFrom, } from "@yume-chan/stream-extra"; import type { ExactReadable } from "@yume-chan/struct"; import { EmptyUint8Array } from "@yume-chan/struct"; import { EmptyUint8Array, Uint8ArrayExactReadable } from "@yume-chan/struct"; import { DeviceBusyError as _DeviceBusyError } from "./error.js"; import type { UsbInterfaceFilter, UsbInterfaceIdentifier } from "./utils.js"; Loading Loading @@ -52,29 +51,6 @@ export function mergeDefaultAdbInterfaceFilter( } } class Uint8ArrayExactReadable implements ExactReadable { #data: Uint8Array; #position: number; get position() { return this.#position; } constructor(data: Uint8Array) { this.#data = data; this.#position = 0; } readExactly(length: number): Uint8Array { const result = this.#data.subarray( this.#position, this.#position + length, ); this.#position += length; return result; } } export class AdbDaemonWebUsbConnection implements ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>> { Loading libraries/adb/src/commands/reverse.ts +5 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import { BufferedReadableStream } from "@yume-chan/stream-extra"; import { encodeUtf8, ExactReadableEndedError, extend, string, struct, } from "@yume-chan/struct"; Loading Loading @@ -49,11 +50,11 @@ export class AdbReverseNotSupportedError extends AdbReverseError { } } const AdbReverseErrorResponse = struct( /* #__PURE__ */ (() => AdbReverseStringResponse.fields)(), const AdbReverseErrorResponse = extend( AdbReverseStringResponse, {}, { littleEndian: true, postDeserialize: (value) => { postDeserialize(value) { // https://issuetracker.google.com/issues/37066218 // ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over Wi-Fi), // and returns this confusing "more than one device/emulator" error. Loading libraries/adb/src/commands/sync/list.ts +7 −17 Original line number Diff line number Diff line import type { StructValue } from "@yume-chan/struct"; import { string, struct, u32 } from "@yume-chan/struct"; import { extend, string, u32 } from "@yume-chan/struct"; import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js"; import { AdbSyncResponseId, adbSyncReadResponses } from "./response.js"; Loading @@ -15,25 +15,15 @@ export interface AdbSyncEntry extends AdbSyncStat { name: string; } export const AdbSyncEntryResponse = /* #__PURE__ */ (() => struct( { ...AdbSyncLstatResponse.fields, export const AdbSyncEntryResponse = extend(AdbSyncLstatResponse, { name: string(u32), }, { littleEndian: true, extra: AdbSyncLstatResponse.extra }, ))(); }); export type AdbSyncEntryResponse = StructValue<typeof AdbSyncEntryResponse>; export const AdbSyncEntry2Response = /* #__PURE__ */ (() => struct( { ...AdbSyncStatResponse.fields, export const AdbSyncEntry2Response = extend(AdbSyncStatResponse, { name: string(u32), }, { littleEndian: true, extra: AdbSyncStatResponse.extra }, ))(); }); export type AdbSyncEntry2Response = StructValue<typeof AdbSyncEntry2Response>; Loading libraries/adb/src/commands/sync/response.ts +3 −3 Original line number Diff line number Diff line import { getUint32LittleEndian } from "@yume-chan/no-data-view"; import type { AsyncExactReadable, StructLike } from "@yume-chan/struct"; import type { AsyncExactReadable, StructDeserializer } from "@yume-chan/struct"; import { decodeUtf8, string, struct, u32 } from "@yume-chan/struct"; function encodeAsciiUnchecked(value: string): Uint8Array { Loading Loading @@ -49,7 +49,7 @@ export const AdbSyncFailResponse = struct( export async function adbSyncReadResponse<T>( stream: AsyncExactReadable, id: number | string, type: StructLike<T>, type: StructDeserializer<T>, ): Promise<T> { if (typeof id === "string") { id = adbSyncEncodeId(id); Loading @@ -72,7 +72,7 @@ export async function adbSyncReadResponse<T>( export async function* adbSyncReadResponses<T>( stream: AsyncExactReadable, id: number | string, type: StructLike<T>, type: StructDeserializer<T>, ): AsyncGenerator<T, void, void> { if (typeof id === "string") { id = adbSyncEncodeId(id); Loading Loading
.changeset/some-tigers-hide.md 0 → 100644 +5 −0 Original line number Diff line number Diff line --- "@yume-chan/struct": major --- Refactor struct package to allow `struct`s to be used as `field`
libraries/adb-daemon-webusb/src/device.ts +1 −25 Original line number Diff line number Diff line Loading @@ -19,8 +19,7 @@ import { ReadableStream, pipeFrom, } from "@yume-chan/stream-extra"; import type { ExactReadable } from "@yume-chan/struct"; import { EmptyUint8Array } from "@yume-chan/struct"; import { EmptyUint8Array, Uint8ArrayExactReadable } from "@yume-chan/struct"; import { DeviceBusyError as _DeviceBusyError } from "./error.js"; import type { UsbInterfaceFilter, UsbInterfaceIdentifier } from "./utils.js"; Loading Loading @@ -52,29 +51,6 @@ export function mergeDefaultAdbInterfaceFilter( } } class Uint8ArrayExactReadable implements ExactReadable { #data: Uint8Array; #position: number; get position() { return this.#position; } constructor(data: Uint8Array) { this.#data = data; this.#position = 0; } readExactly(length: number): Uint8Array { const result = this.#data.subarray( this.#position, this.#position + length, ); this.#position += length; return result; } } export class AdbDaemonWebUsbConnection implements ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>> { Loading
libraries/adb/src/commands/reverse.ts +5 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import { BufferedReadableStream } from "@yume-chan/stream-extra"; import { encodeUtf8, ExactReadableEndedError, extend, string, struct, } from "@yume-chan/struct"; Loading Loading @@ -49,11 +50,11 @@ export class AdbReverseNotSupportedError extends AdbReverseError { } } const AdbReverseErrorResponse = struct( /* #__PURE__ */ (() => AdbReverseStringResponse.fields)(), const AdbReverseErrorResponse = extend( AdbReverseStringResponse, {}, { littleEndian: true, postDeserialize: (value) => { postDeserialize(value) { // https://issuetracker.google.com/issues/37066218 // ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over Wi-Fi), // and returns this confusing "more than one device/emulator" error. Loading
libraries/adb/src/commands/sync/list.ts +7 −17 Original line number Diff line number Diff line import type { StructValue } from "@yume-chan/struct"; import { string, struct, u32 } from "@yume-chan/struct"; import { extend, string, u32 } from "@yume-chan/struct"; import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js"; import { AdbSyncResponseId, adbSyncReadResponses } from "./response.js"; Loading @@ -15,25 +15,15 @@ export interface AdbSyncEntry extends AdbSyncStat { name: string; } export const AdbSyncEntryResponse = /* #__PURE__ */ (() => struct( { ...AdbSyncLstatResponse.fields, export const AdbSyncEntryResponse = extend(AdbSyncLstatResponse, { name: string(u32), }, { littleEndian: true, extra: AdbSyncLstatResponse.extra }, ))(); }); export type AdbSyncEntryResponse = StructValue<typeof AdbSyncEntryResponse>; export const AdbSyncEntry2Response = /* #__PURE__ */ (() => struct( { ...AdbSyncStatResponse.fields, export const AdbSyncEntry2Response = extend(AdbSyncStatResponse, { name: string(u32), }, { littleEndian: true, extra: AdbSyncStatResponse.extra }, ))(); }); export type AdbSyncEntry2Response = StructValue<typeof AdbSyncEntry2Response>; Loading
libraries/adb/src/commands/sync/response.ts +3 −3 Original line number Diff line number Diff line import { getUint32LittleEndian } from "@yume-chan/no-data-view"; import type { AsyncExactReadable, StructLike } from "@yume-chan/struct"; import type { AsyncExactReadable, StructDeserializer } from "@yume-chan/struct"; import { decodeUtf8, string, struct, u32 } from "@yume-chan/struct"; function encodeAsciiUnchecked(value: string): Uint8Array { Loading Loading @@ -49,7 +49,7 @@ export const AdbSyncFailResponse = struct( export async function adbSyncReadResponse<T>( stream: AsyncExactReadable, id: number | string, type: StructLike<T>, type: StructDeserializer<T>, ): Promise<T> { if (typeof id === "string") { id = adbSyncEncodeId(id); Loading @@ -72,7 +72,7 @@ export async function adbSyncReadResponse<T>( export async function* adbSyncReadResponses<T>( stream: AsyncExactReadable, id: number | string, type: StructLike<T>, type: StructDeserializer<T>, ): AsyncGenerator<T, void, void> { if (typeof id === "string") { id = adbSyncEncodeId(id); Loading