Module regex_automata::util::wire
source Β· Expand description
Types and routines that support the wire format of finite automata.
Currently, this module just exports a few error types and some small helpers for deserializing dense DFAs using correct alignment.
Structs§
- A hack to align a smaller type
B
with a bigger typeT
. - An error that occurs when deserializing an object defined in this crate.
- An error that occurs when serializing an object from this crate.
Enums§
- BE πBig endian writing.
- DeserializeErrorKind π
- LE πLittle endian writing.
Traits§
- Endian πA simple trait for writing code generic over endianness.
Functions§
- add πAdd the given numbers, and on overflow, return an error that includes βwhatβ in the error message.
- alloc_aligned_buffer πAllocate a byte buffer of the given size, along with some initial padding such that
buf[padding..]
has the same alignment asT
, where the alignment ofT
must be at most8
. In particular, callers should treat the first N bytes (second return value) as padding bytes that must not be overwritten. In all cases, the following identity holds: - check_alignment πChecks that the given slice has an alignment that matches
T
. - check_slice_len πChecks that the given slice has some minimal length. If itβs smaller than the bound given, then a βbuffer too smallβ error is returned with
what
describing what the buffer represents. - mul πMultiply the given numbers, and on overflow, return an error that includes βwhatβ in the error message.
- padding_len πReturns the number of additional bytes required to add to the given length in order to make the total length a multiple of 4. The return value is always less than 4.
- Reads the endianness check from the beginning of the given slice and confirms that the endianness of the serialized object matches the expected endianness. If the slice is too small or if the endianness check fails, this returns an error.
- read_label πReads a NUL terminated label starting at the beginning of the given slice.
- read_pattern_id πReads a pattern ID from the given slice. If the slice has insufficient length, then this panics. If the deserialized integer exceeds the pattern ID limit for the current target, then this returns an error.
- Reads a pattern ID from the given slice. If the slice has insufficient length, then this panics. Otherwise, the deserialized integer is assumed to be a valid pattern ID.
- read_state_id πReads a state ID from the given slice. If the slice has insufficient length, then this panics. If the deserialized integer exceeds the state ID limit for the current target, then this returns an error.
- Reads a state ID from the given slice. If the slice has insufficient length, then this panics. Otherwise, the deserialized integer is assumed to be a valid state ID.
- read_u16 πRead a u16 from the beginning of the given slice in native endian format. If the slice has fewer than 2 bytes, then this panics.
- read_u32 πRead a u32 from the beginning of the given slice in native endian format. If the slice has fewer than 4 bytes, then this panics.
- read_u128 πRead a u128 from the beginning of the given slice in native endian format. If the slice has fewer than 16 bytes, then this panics.
- read_version πReads a version number from the beginning of the given slice and confirms that is matches the expected version number given. If the slice is too small or if the version numbers arenβt equivalent, this returns an error.
- shl πShift
a
left byb
, and on overflow, return an error that includes βwhatβ in the error message. - skip_initial_padding πReads a possibly empty amount of padding, up to 7 bytes, from the beginning of the given slice. All padding bytes must be NUL bytes.
- try_read_state_id πAttempts to read a state ID from the given slice. If the slice has an insufficient number of bytes or if the state ID exceeds the limit for the current target, then this returns an error.
- try_read_u16 πTry to read a u16 from the beginning of the given slice in native endian format. If the slice has fewer than 2 bytes, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - Try to read a u16 as a usize from the beginning of the given slice in native endian format. If the slice has fewer than 2 bytes or if the deserialized number cannot be represented by usize, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - try_read_u32 πTry to read a u32 from the beginning of the given slice in native endian format. If the slice has fewer than 4 bytes, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - Try to read a u32 as a usize from the beginning of the given slice in native endian format. If the slice has fewer than 4 bytes or if the deserialized number cannot be represented by usize, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - try_read_u128 πTry to read a u128 from the beginning of the given slice in native endian format. If the slice has fewer than 16 bytes, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - u32s_to_pattern_ids πSafely converts a
&[u32]
to&[PatternID]
with zero cost. - u32s_to_state_ids πSafely converts a
&[u32]
to&[StateID]
with zero cost. - Safely converts a
&mut [u32]
to&mut [StateID]
with zero cost. - Writes 0xFEFF as an integer using the given endianness.
- Returns the number of bytes written by the endianness check.
- write_label πWrites the given label to the buffer as a NUL terminated string. The label given must not contain NUL, otherwise this will panic. Similarly, the label must not be longer than 255 bytes, otherwise this will panic.
- write_label_len πReturns the total number of bytes (including padding) that would be written for the given label. This panics if the given label contains a NUL byte or is longer than 255 bytes. (The size restriction exists so that searching for a label during deserialization can be done in small bounded space.)
- write_pattern_id πWrite the given pattern ID to the beginning of the given slice of bytes using the specified endianness. The given slice must have length at least
PatternID::SIZE
, or else this panics. Upon success, the total number of bytes written is returned. - write_state_id πWrite the given state ID to the beginning of the given slice of bytes using the specified endianness. The given slice must have length at least
StateID::SIZE
, or else this panics. Upon success, the total number of bytes written is returned. - write_version πWrites the given version number to the beginning of the given slice.
- write_version_len πReturns the number of bytes written by writing the version number.
Type Aliases§
- NE π