mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 01:39:21 +02:00
refactor: improve tree-shaking
This commit is contained in:
parent
ef0e1c6bcf
commit
a29268426d
13 changed files with 107 additions and 96 deletions
|
@ -33,7 +33,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yume-chan/adb": "workspace:^",
|
"@yume-chan/adb": "workspace:^",
|
||||||
"@yume-chan/async": "^2.2.0",
|
"@yume-chan/async": "^4.0.0",
|
||||||
"@yume-chan/event": "workspace:^",
|
"@yume-chan/event": "workspace:^",
|
||||||
"@yume-chan/scrcpy": "workspace:^",
|
"@yume-chan/scrcpy": "workspace:^",
|
||||||
"@yume-chan/stream-extra": "workspace:^",
|
"@yume-chan/stream-extra": "workspace:^",
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
"test": "run-test"
|
"test": "run-test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yume-chan/async": "^2.2.0",
|
"@yume-chan/async": "^4.0.0",
|
||||||
"@yume-chan/event": "workspace:^",
|
"@yume-chan/event": "workspace:^",
|
||||||
"@yume-chan/no-data-view": "workspace:^",
|
"@yume-chan/no-data-view": "workspace:^",
|
||||||
"@yume-chan/stream-extra": "workspace:^",
|
"@yume-chan/stream-extra": "workspace:^",
|
||||||
|
|
|
@ -33,7 +33,7 @@ export type LogId = (typeof LogId)[keyof typeof LogId];
|
||||||
|
|
||||||
const LogIdName =
|
const LogIdName =
|
||||||
/* #__PURE__ */
|
/* #__PURE__ */
|
||||||
Object.fromEntries(Object.entries(LogId).map(([k, v]) => [v, k]));
|
(() => Object.fromEntries(Object.entries(LogId).map(([k, v]) => [v, k])))();
|
||||||
|
|
||||||
// https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/android/log.h;l=73;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
|
// https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/android/log.h;l=73;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
|
||||||
export const AndroidLogPriority = {
|
export const AndroidLogPriority = {
|
||||||
|
@ -96,7 +96,7 @@ export interface LogcatOptions {
|
||||||
ids?: LogId[];
|
ids?: LogId[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const NANOSECONDS_PER_SECOND = BigInt(1e9);
|
const NANOSECONDS_PER_SECOND = /* #__PURE__ */ BigInt(1e9);
|
||||||
|
|
||||||
// https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/log/log_read.h;l=39;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
|
// https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/log/log_read.h;l=39;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
|
||||||
export const LoggerEntry =
|
export const LoggerEntry =
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"test": "run-test"
|
"test": "run-test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yume-chan/async": "^2.2.0"
|
"@yume-chan/async": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.7.7",
|
"@types/node": "^22.7.7",
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"prepublishOnly": "npm run build"
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yume-chan/async": "^2.2.0",
|
"@yume-chan/async": "^4.0.0",
|
||||||
"@yume-chan/event": "workspace:^",
|
"@yume-chan/event": "workspace:^",
|
||||||
"@yume-chan/scrcpy": "workspace:^",
|
"@yume-chan/scrcpy": "workspace:^",
|
||||||
"@yume-chan/stream-extra": "workspace:^",
|
"@yume-chan/stream-extra": "workspace:^",
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"test": "run-test"
|
"test": "run-test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yume-chan/async": "^2.2.0",
|
"@yume-chan/async": "^4.0.0",
|
||||||
"@yume-chan/no-data-view": "workspace:^",
|
"@yume-chan/no-data-view": "workspace:^",
|
||||||
"@yume-chan/stream-extra": "workspace:^",
|
"@yume-chan/stream-extra": "workspace:^",
|
||||||
"@yume-chan/struct": "workspace:^"
|
"@yume-chan/struct": "workspace:^"
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
"test": "run-test"
|
"test": "run-test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yume-chan/async": "^2.2.0",
|
"@yume-chan/async": "^4.0.0",
|
||||||
"@yume-chan/struct": "workspace:^"
|
"@yume-chan/struct": "workspace:^"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -47,9 +47,17 @@ export class BigIntFieldVariant {
|
||||||
this.serialize = serialize;
|
this.serialize = serialize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly Int64 = new BigIntFieldVariant(8, getInt64, setInt64);
|
static readonly Int64 = /* #__PURE__ */ new BigIntFieldVariant(
|
||||||
|
8,
|
||||||
|
getInt64,
|
||||||
|
setInt64,
|
||||||
|
);
|
||||||
|
|
||||||
static readonly Uint64 = new BigIntFieldVariant(8, getUint64, setUint64);
|
static readonly Uint64 = /* #__PURE__ */ new BigIntFieldVariant(
|
||||||
|
8,
|
||||||
|
getUint64,
|
||||||
|
setUint64,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BigIntFieldDefinition<
|
export class BigIntFieldDefinition<
|
||||||
|
|
|
@ -53,7 +53,8 @@ export abstract class BufferFieldConverter<
|
||||||
export class Uint8ArrayBufferFieldConverter<
|
export class Uint8ArrayBufferFieldConverter<
|
||||||
TTypeScriptType = Uint8Array,
|
TTypeScriptType = Uint8Array,
|
||||||
> extends BufferFieldConverter<Uint8Array, TTypeScriptType> {
|
> extends BufferFieldConverter<Uint8Array, TTypeScriptType> {
|
||||||
static readonly Instance = new Uint8ArrayBufferFieldConverter();
|
static readonly Instance =
|
||||||
|
/* #__PURE__ */ new Uint8ArrayBufferFieldConverter();
|
||||||
|
|
||||||
protected constructor() {
|
protected constructor() {
|
||||||
super();
|
super();
|
||||||
|
@ -76,7 +77,7 @@ export class Uint8ArrayBufferFieldConverter<
|
||||||
export class StringBufferFieldConverter<
|
export class StringBufferFieldConverter<
|
||||||
TTypeScriptType = string,
|
TTypeScriptType = string,
|
||||||
> extends BufferFieldConverter<string, TTypeScriptType> {
|
> extends BufferFieldConverter<string, TTypeScriptType> {
|
||||||
static readonly Instance = new StringBufferFieldConverter();
|
static readonly Instance = /* #__PURE__ */ new StringBufferFieldConverter();
|
||||||
|
|
||||||
override toBuffer(value: string): Uint8Array {
|
override toBuffer(value: string): Uint8Array {
|
||||||
return encodeUtf8(value);
|
return encodeUtf8(value);
|
||||||
|
|
70
libraries/struct/src/types/number-namespace.ts
Normal file
70
libraries/struct/src/types/number-namespace.ts
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
import {
|
||||||
|
getInt16,
|
||||||
|
getInt32,
|
||||||
|
getInt8,
|
||||||
|
getUint16,
|
||||||
|
getUint32,
|
||||||
|
setInt16,
|
||||||
|
setInt32,
|
||||||
|
setUint16,
|
||||||
|
setUint32,
|
||||||
|
} from "@yume-chan/no-data-view";
|
||||||
|
import type { NumberFieldVariant } from "./number-reexports.js";
|
||||||
|
|
||||||
|
export const Uint8: NumberFieldVariant = {
|
||||||
|
signed: false,
|
||||||
|
size: 1,
|
||||||
|
deserialize(array) {
|
||||||
|
return array[0]!;
|
||||||
|
},
|
||||||
|
serialize(array, offset, value) {
|
||||||
|
array[offset] = value;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Int8: NumberFieldVariant = {
|
||||||
|
signed: true,
|
||||||
|
size: 1,
|
||||||
|
deserialize(array) {
|
||||||
|
return getInt8(array, 0);
|
||||||
|
},
|
||||||
|
serialize(array, offset, value) {
|
||||||
|
array[offset] = value;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Uint16: NumberFieldVariant = {
|
||||||
|
signed: false,
|
||||||
|
size: 2,
|
||||||
|
deserialize(array, littleEndian) {
|
||||||
|
return getUint16(array, 0, littleEndian);
|
||||||
|
},
|
||||||
|
serialize: setUint16,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Int16: NumberFieldVariant = {
|
||||||
|
signed: true,
|
||||||
|
size: 2,
|
||||||
|
deserialize(array, littleEndian) {
|
||||||
|
return getInt16(array, 0, littleEndian);
|
||||||
|
},
|
||||||
|
serialize: setInt16,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Uint32: NumberFieldVariant = {
|
||||||
|
signed: false,
|
||||||
|
size: 4,
|
||||||
|
deserialize(array, littleEndian) {
|
||||||
|
return getUint32(array, 0, littleEndian);
|
||||||
|
},
|
||||||
|
serialize: setUint32,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Int32: NumberFieldVariant = {
|
||||||
|
signed: true,
|
||||||
|
size: 4,
|
||||||
|
deserialize(array, littleEndian) {
|
||||||
|
return getInt32(array, 0, littleEndian);
|
||||||
|
},
|
||||||
|
serialize: setInt32,
|
||||||
|
};
|
13
libraries/struct/src/types/number-reexports.ts
Normal file
13
libraries/struct/src/types/number-reexports.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
export * as NumberFieldVariant from "./number-namespace.js";
|
||||||
|
|
||||||
|
export interface NumberFieldVariant {
|
||||||
|
signed: boolean;
|
||||||
|
size: number;
|
||||||
|
deserialize(array: Uint8Array, littleEndian: boolean): number;
|
||||||
|
serialize(
|
||||||
|
array: Uint8Array,
|
||||||
|
offset: number,
|
||||||
|
value: number,
|
||||||
|
littleEndian: boolean,
|
||||||
|
): void;
|
||||||
|
}
|
|
@ -1,15 +1,3 @@
|
||||||
import {
|
|
||||||
getInt16,
|
|
||||||
getInt32,
|
|
||||||
getInt8,
|
|
||||||
getUint16,
|
|
||||||
getUint32,
|
|
||||||
setInt16,
|
|
||||||
setInt32,
|
|
||||||
setUint16,
|
|
||||||
setUint32,
|
|
||||||
} from "@yume-chan/no-data-view";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
AsyncExactReadable,
|
AsyncExactReadable,
|
||||||
ExactReadable,
|
ExactReadable,
|
||||||
|
@ -19,78 +7,9 @@ import type {
|
||||||
import { StructFieldDefinition, StructFieldValue } from "../basic/index.js";
|
import { StructFieldDefinition, StructFieldValue } from "../basic/index.js";
|
||||||
import { SyncPromise } from "../sync-promise.js";
|
import { SyncPromise } from "../sync-promise.js";
|
||||||
import type { ValueOrPromise } from "../utils.js";
|
import type { ValueOrPromise } from "../utils.js";
|
||||||
|
import type { NumberFieldVariant } from "./number-reexports.js";
|
||||||
|
|
||||||
export interface NumberFieldVariant {
|
export * from "./number-reexports.js";
|
||||||
signed: boolean;
|
|
||||||
size: number;
|
|
||||||
deserialize(array: Uint8Array, littleEndian: boolean): number;
|
|
||||||
serialize(
|
|
||||||
array: Uint8Array,
|
|
||||||
offset: number,
|
|
||||||
value: number,
|
|
||||||
littleEndian: boolean,
|
|
||||||
): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace NumberFieldVariant {
|
|
||||||
export const Uint8: NumberFieldVariant = {
|
|
||||||
signed: false,
|
|
||||||
size: 1,
|
|
||||||
deserialize(array) {
|
|
||||||
return array[0]!;
|
|
||||||
},
|
|
||||||
serialize(array, offset, value) {
|
|
||||||
array[offset] = value;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Int8: NumberFieldVariant = {
|
|
||||||
signed: true,
|
|
||||||
size: 1,
|
|
||||||
deserialize(array) {
|
|
||||||
return getInt8(array, 0);
|
|
||||||
},
|
|
||||||
serialize(array, offset, value) {
|
|
||||||
array[offset] = value;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Uint16: NumberFieldVariant = {
|
|
||||||
signed: false,
|
|
||||||
size: 2,
|
|
||||||
deserialize(array, littleEndian) {
|
|
||||||
return getUint16(array, 0, littleEndian);
|
|
||||||
},
|
|
||||||
serialize: setUint16,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Int16: NumberFieldVariant = {
|
|
||||||
signed: true,
|
|
||||||
size: 2,
|
|
||||||
deserialize(array, littleEndian) {
|
|
||||||
return getInt16(array, 0, littleEndian);
|
|
||||||
},
|
|
||||||
serialize: setInt16,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Uint32: NumberFieldVariant = {
|
|
||||||
signed: false,
|
|
||||||
size: 4,
|
|
||||||
deserialize(array, littleEndian) {
|
|
||||||
return getUint32(array, 0, littleEndian);
|
|
||||||
},
|
|
||||||
serialize: setUint32,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Int32: NumberFieldVariant = {
|
|
||||||
signed: true,
|
|
||||||
size: 4,
|
|
||||||
deserialize(array, littleEndian) {
|
|
||||||
return getInt32(array, 0, littleEndian);
|
|
||||||
},
|
|
||||||
serialize: setInt32,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class NumberFieldDefinition<
|
export class NumberFieldDefinition<
|
||||||
TVariant extends NumberFieldVariant = NumberFieldVariant,
|
TVariant extends NumberFieldVariant = NumberFieldVariant,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
"eslint": "^9.13.0",
|
"eslint": "^9.13.0",
|
||||||
"eslint-plugin-import-x": "^4.3.1",
|
"eslint-plugin-import-x": "^4.3.1",
|
||||||
"typescript": "^5.6.3",
|
"typescript": "^5.6.3",
|
||||||
"typescript-eslint": "^8.10.0"
|
"typescript-eslint": "^8.11.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^3.3.3"
|
"prettier": "^3.3.3"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue