Documentation ¶
Overview ¶
Package patterns describes the Pattern interface. Standard patterns are also defined in this package: Sequence (as well as BMH and reverse BMH Sequence), Choice, List and Not.
Index ¶
- func Register(id byte, l Loader)
- func Stringify(b []byte) string
- type AnyMask
- func (am AnyMask) Equals(pat Pattern) bool
- func (am AnyMask) Length() (int, int)
- func (am AnyMask) NumSequences() int
- func (am AnyMask) Save(ls *persist.LoadSaver)
- func (am AnyMask) Sequences() []Sequence
- func (am AnyMask) String() string
- func (am AnyMask) Test(b []byte) (bool, int)
- func (am AnyMask) TestR(b []byte) (bool, int)
- type BMHSequence
- func (s *BMHSequence) Equals(pat Pattern) bool
- func (s *BMHSequence) Length() (int, int)
- func (s *BMHSequence) NumSequences() int
- func (s *BMHSequence) Save(ls *persist.LoadSaver)
- func (s *BMHSequence) Sequences() []Sequence
- func (s *BMHSequence) String() string
- func (s *BMHSequence) Test(b []byte) (bool, int)
- func (s *BMHSequence) TestR(b []byte) (bool, int)
- type Choice
- func (c Choice) Equals(pat Pattern) bool
- func (c Choice) Length() (int, int)
- func (c Choice) NumSequences() int
- func (c Choice) Save(ls *persist.LoadSaver)
- func (c Choice) Sequences() []Sequence
- func (c Choice) String() string
- func (c Choice) Test(b []byte) (bool, int)
- func (c Choice) TestR(b []byte) (bool, int)
- type List
- type Loader
- type Mask
- type Not
- type Pattern
- type RBMHSequence
- func (s *RBMHSequence) Equals(pat Pattern) bool
- func (s *RBMHSequence) Length() (int, int)
- func (s *RBMHSequence) NumSequences() int
- func (s *RBMHSequence) Save(ls *persist.LoadSaver)
- func (s *RBMHSequence) Sequences() []Sequence
- func (s *RBMHSequence) String() string
- func (s *RBMHSequence) Test(b []byte) (bool, int)
- func (s *RBMHSequence) TestR(b []byte) (bool, int)
- type Sequence
- func (s Sequence) Equals(pat Pattern) bool
- func (s Sequence) Length() (int, int)
- func (s Sequence) NumSequences() int
- func (s Sequence) Reverse() Sequence
- func (s Sequence) Save(ls *persist.LoadSaver)
- func (s Sequence) Sequences() []Sequence
- func (s Sequence) String() string
- func (s Sequence) Test(b []byte) (bool, int)
- func (s Sequence) TestR(b []byte) (bool, int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BMHSequence ¶
BMHSequence is an optimised version of the regular Sequence pattern. It is used behind the scenes in the Bytematcher package to speed up matching and should not be used directly in other packages (use the plain Sequence instead).
func NewBMHSequence ¶
func NewBMHSequence(s Sequence) *BMHSequence
NewBMHSequence turns a Sequence into a BMHSequence.
func (*BMHSequence) Equals ¶
func (s *BMHSequence) Equals(pat Pattern) bool
Equals reports whether a pattern is identical to another pattern.
func (*BMHSequence) Length ¶
func (s *BMHSequence) Length() (int, int)
Length returns a minimum and maximum length for the pattern.
func (*BMHSequence) NumSequences ¶
func (s *BMHSequence) NumSequences() int
NumSequences reports how many plain sequences are needed to represent this pattern.
func (*BMHSequence) Save ¶
func (s *BMHSequence) Save(ls *persist.LoadSaver)
Save persists the pattern.
func (*BMHSequence) Sequences ¶
func (s *BMHSequence) Sequences() []Sequence
Sequences converts the pattern into a slice of plain sequences.
func (*BMHSequence) String ¶
func (s *BMHSequence) String() string
type Choice ¶
type Choice []Pattern
Choice is a slice of patterns, any of which can test true for the pattern to succeed. Returns the longest matching pattern
func (Choice) NumSequences ¶
NumSequences reports how many plain sequences are needed to represent this pattern.
type List ¶
type List []Pattern
List is a slice of patterns, all of which must test true sequentially in order for the pattern to succeed.
func (List) NumSequences ¶
NumSequences reports how many plain sequences are needed to represent this pattern.
type Not ¶
type Not struct{ Pattern }
Not contains a pattern and reports the opposite of that pattern's result when testing.
func (Not) NumSequences ¶
NumSequences reports how many plain sequences are needed to represent this pattern.
type Pattern ¶
type Pattern interface { Test([]byte) (bool, int) // Returns boolean for match. For a positive match, the integer value represents the length of the match. For a negative match, the integer represents an offset jump before a subsequent test. That offset should be 0 if the remaining byte slice is smaller than the pattern. TestR([]byte) (bool, int) // Same as Test but for testing in reverse (from the right-most position of the byte slice). Equals(Pattern) bool // Test equality with another pattern Length() (int, int) // Minimum and maximum lengths of the pattern NumSequences() int // Number of simple sequences represented by a pattern. Return 0 if the pattern cannot be represented by a defined number of simple sequence (e.g. for an indirect offset pattern) or, if in your opinion, the number of sequences is unreasonably large. Sequences() []Sequence // Convert the pattern to a slice of sequences. Return an empty slice if the pattern cannot be represented by a defined number of simple sequences. String() string Save(*persist.LoadSaver) // encode the pattern into bytes for saving in a persist file }
Patterns are the smallest building blocks of a format signature. Exact byte sequence matches are a type of pattern, as are byte ranges, non-sequence matches etc. You can define custom patterns (e.g. for W3C date type) by implementing this interface.
type RBMHSequence ¶
RBMHSequence is a variant of the BMH sequence designed for reverse (R-L) matching. It is used behind the scenes in the Bytematcher package to speed up matching and should not be used directly in other packages (use the plain Sequence instead).
func NewRBMHSequence ¶
func NewRBMHSequence(s Sequence) *RBMHSequence
NewRBMHSequence create a reverse matching BMH sequence (apply the BMH optimisation to TestR rather than Test).
func (*RBMHSequence) Equals ¶
func (s *RBMHSequence) Equals(pat Pattern) bool
Equals reports whether a pattern is identical to another pattern.
func (*RBMHSequence) Length ¶
func (s *RBMHSequence) Length() (int, int)
Length returns a minimum and maximum length for the pattern.
func (*RBMHSequence) NumSequences ¶
func (s *RBMHSequence) NumSequences() int
NumSequences reports how many plain sequences are needed to represent this pattern.
func (*RBMHSequence) Save ¶
func (s *RBMHSequence) Save(ls *persist.LoadSaver)
Save persists the pattern.
func (*RBMHSequence) Sequences ¶
func (s *RBMHSequence) Sequences() []Sequence
Sequences converts the pattern into a slice of plain sequences.
func (*RBMHSequence) String ¶
func (s *RBMHSequence) String() string
type Sequence ¶
type Sequence []byte
Sequence is a matching sequence of bytes.
func (Sequence) NumSequences ¶
NumSequences reports how many plain sequences are needed to represent this pattern.
func (Sequence) Reverse ¶
The Reverse method is unique to this pattern. It is used for the EOF byte sequence set