Skip to main content
Module

x/structurae/index.ts>BitFieldConstructor

Data structures for high-performance JavaScript applications.
Latest
interface BitFieldConstructor
import { type BitFieldConstructor } from "https://deno.land/x/structurae@4.0.1/index.ts";

Type Parameters

K extends PropertyKey
optional
N extends number | bigint = number

Properties

schema: Record<K, N>
fields: Array<K>
masks: Record<K, N>
offsets: Record<K, N>
mask: N
size: N

Methods

new(data?:
| N
| Array<number>
| Record<K, number>
): BitFieldStructure<K, N>
decode(data: N): Record<K, number>

Decodes a numeric value into its object representation according to the schema.

encode(data: Array<number> | Record<K, number>): N

Encodes a given list of numbers or map of fields and their respective values into a single numeric value according to the schema.

getMatcher(matcher: Partial<Record<K, number>>): [N, N]

Creates a tuple of values to be used as a matcher to efficiently match against multiple instances.

getMinSize(value: number): number

Returns the minimum amount of bits necessary to hold a given number.

isValid(data: Partial<Record<K, number>>): boolean

Checks if a given set of values are valid according to the schema.

match(value: N, matcher: [N, N]): boolean

The static version of BitField#match, matches a given value against a precomputed matcher.