Crate bparse

Source
Expand description

§Overview

When parsing byte streams from a network socket, the same pattern tends to appear:

  1. Read bytes from the socket into a buffer.
  2. Check the buffer for complete message. a. If the buffer has a complete message, split it off and process it. b. If the buffer does not have a complete message yet, go to 1.

This crate implements a byte buffer, Buf specifically for this use case.

The crate is organized into three parts:

  1. The Pattern trait: represents a byte pattern to be recognized.
  2. A list of common functions and combinators for composing Patterns together.
  3. The Buf struct; a buffer that uses patterns to match its contents. Matched bytes are removed from the buffer.

Structs§

Buf
A byte buffer whose contents can be matched with Patterns.
ByteLookupTable
See oneof
Choice
See Pattern::or
ElementRange
See range()
Eof
See end
Not
See not
One
See one
Prefix
See prefix
Repetition
Exppresses pattern repetition.
Sequence
See Pattern::then

Traits§

Pattern
Expresses that the implementing type may be used to match a byte slice.

Functions§

alpha
Returns a pattern that will match any ascii letter at the start of the input
any
Returns a new pattern that matches as many repetitions as possible of the given pattern, including 0.
at_least
Returns a new pattern that matches at least n repetitions of pattern.
at_most
Returns a new pattern that matches at most n repetitions of pattern.
between
Returns a new pattern that matches between lo and hi repetitions of pattern.
count
Returns a new pattern that matches exactly n repetitions of pattern.
digit
Returns a pattern that will match any ascii digit at the start of the input
end
Returns a pattern that matches the end of the slice.
hex
Returns a pattern that will match any hexadecimal character at the start of the input
noneof
Inverse of oneof.
not
Returns a new pattern that matches only if pattern does not match.
one
Returns a new pattern that always matches the next element in the input if it exists.
oneof
Returns a pattern that will match any byte in bytes at the start of the input
optional
Returns a new pattern that matches 0 or 1 repetitions of pattern
prefix
Returns a new pattern that will match if slice is a prefix of the input.
range
Returns a new pattern that will match an element in the closed interval [lo, hi]
utf8
Returns a new pattern that will match the utf8 string slice s at the start of the input.