Initial Commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
|
||||
<!-- begin:auto-docs -->
|
||||
_(no submodules)_
|
||||
<!-- end:auto-docs -->
|
||||
## boolean
|
||||
|
||||
**Path:** `bitpacker-strategies/src/strategies/boolean/boolean.ts`
|
||||
**Export:** See source for details.
|
||||
|
||||
### What it does
|
||||
|
||||
Packing strategy for @suaveplan/bitpacker.
|
||||
@@ -0,0 +1,23 @@
|
||||
import type {
|
||||
BitPackerSchema,
|
||||
PackingContext,
|
||||
PackingStrategy,
|
||||
} from "@suaveplan/bitpacker";
|
||||
|
||||
export class BooleanPackingStrategy implements PackingStrategy {
|
||||
canHandle(schema: BitPackerSchema): boolean {
|
||||
return typeof schema === "boolean";
|
||||
}
|
||||
|
||||
pack(
|
||||
data: unknown,
|
||||
_schema: BitPackerSchema,
|
||||
context: PackingContext
|
||||
): void {
|
||||
context.writer.writeBool(Boolean(data));
|
||||
}
|
||||
|
||||
unpack(_schema: BitPackerSchema, context: PackingContext): unknown {
|
||||
return context.reader.readBool();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user