Use BinaryLike interface

This commit is contained in:
luaneko 2025-01-09 04:48:19 +11:00
parent 5dadd7c5a2
commit bdebb22a0e
Signed by: luaneko
GPG Key ID: 406809B8763FF07A

23
ser.ts
View File

@ -1,10 +1,15 @@
import { read_i8 } from "./lstd.ts"; import {
import { read_i16_be } from "./lstd.ts"; type BinaryLike,
import { read_i32_be } from "./lstd.ts"; encode_utf8,
import { write_i32_be } from "./lstd.ts"; from_utf8,
import { write_i16_be } from "./lstd.ts"; jit,
import { write_i8 } from "./lstd.ts"; read_i16_be,
import { encode_utf8, from_utf8, jit } from "./lstd.ts"; read_i32_be,
read_i8,
write_i16_be,
write_i32_be,
write_i8,
} from "./lstd.ts";
export class EncoderError extends Error { export class EncoderError extends Error {
override get name() { override get name() {
@ -114,7 +119,7 @@ export function byten(n: number): Encoder<Uint8Array> {
}; };
} }
export const byten_lp: Encoder<Uint8Array | string | null> = { export const byten_lp: Encoder<BinaryLike | null> = {
const_size: null, const_size: null,
allocs(s) { allocs(s) {
let size = 4; let size = 4;
@ -136,7 +141,7 @@ export const byten_lp: Encoder<Uint8Array | string | null> = {
}, },
}; };
export const byten_rest: Encoder<Uint8Array | string> = { export const byten_rest: Encoder<BinaryLike | string> = {
const_size: null, const_size: null,
allocs(s) { allocs(s) {
if (typeof s === "string") return s.length * 3; if (typeof s === "string") return s.length * 3;