Skip to content

Commit 99f5456

Browse files
authored
fix(struct): fix some overloads of buffer ignores specified value converter (#814)
1 parent d1eca46 commit 99f5456

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

.changeset/sweet-teams-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@yume-chan/struct": patch
3+
---
4+
5+
Fix an issue that some overloads of `buffer` (and `string`) ignores specified value converter
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as assert from "node:assert";
2+
import { describe, it } from "node:test";
3+
4+
import { encodeUtf8, Uint8ArrayExactReadable } from "@yume-chan/struct";
5+
import { AdbReverseErrorResponse } from "./reverse.js";
6+
7+
describe("AdbReverseErrorResponse", () => {
8+
it("should throw AdbReverseNotSupportedError", () => {
9+
assert.throws(
10+
() =>
11+
AdbReverseErrorResponse.deserialize(
12+
new Uint8ArrayExactReadable(
13+
encodeUtf8("001Dmore than one device/emulator"),
14+
),
15+
),
16+
/ADB reverse tunnel is not supported on this device when connected wirelessly./,
17+
);
18+
});
19+
});

libraries/adb/src/commands/reverse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AdbReverseNotSupportedError extends AdbReverseError {
5252
}
5353
}
5454

55-
const AdbReverseErrorResponse = extend(
55+
export const AdbReverseErrorResponse = extend(
5656
AdbReverseStringResponse,
5757
{},
5858
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as assert from "node:assert";
2+
import { describe, it } from "node:test";
3+
4+
import { string } from "./string.js";
5+
import { Uint8ArrayExactReadable } from "./readable.js";
6+
7+
describe("string", () => {
8+
it("should decode buffer as UTF-8", () => {
9+
const buffer = new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]);
10+
const result = string(buffer.length).deserialize(
11+
new Uint8ArrayExactReadable(buffer),
12+
{ dependencies: {} as never, littleEndian: true },
13+
);
14+
assert.strictEqual(result, "hello");
15+
});
16+
});

0 commit comments

Comments
 (0)