Documentation
¶
Overview ¶
Package frames describes the Frame interface. A set of standard frames are also defined in this package. These are: Fixed, Window, Wild and WildMin.
Index ¶
- Variables
- func NonZero(f Frame) bool
- func Register(id byte, l Loader)
- func TotalLength(f Frame) int
- type Fixed
- func (f Fixed) Equals(frame Frame) bool
- func (f Fixed) Linked(prev Frame, maxDistance, maxRange int) bool
- func (f Fixed) Match(b []byte) (bool, []int)
- func (f Fixed) MatchR(b []byte) (bool, []int)
- func (f Fixed) Max() int
- func (f Fixed) Min() int
- func (f Fixed) Pat() patterns.Pattern
- func (f Fixed) Save(ls *persist.LoadSaver)
- func (f Fixed) String() string
- type Frame
- type Loader
- type OffType
- type Sequencer
- type Signature
- type Wild
- func (w Wild) Equals(frame Frame) bool
- func (w Wild) Linked(prev Frame, maxDistance, maxRange int) bool
- func (w Wild) Match(b []byte) (bool, []int)
- func (w Wild) MatchR(b []byte) (bool, []int)
- func (w Wild) Max() int
- func (w Wild) Min() int
- func (w Wild) Pat() patterns.Pattern
- func (w Wild) Save(ls *persist.LoadSaver)
- func (w Wild) String() string
- type WildMin
- func (w WildMin) Equals(frame Frame) bool
- func (w WildMin) Linked(prev Frame, maxDistance, maxRange int) bool
- func (w WildMin) Match(b []byte) (bool, []int)
- func (w WildMin) MatchR(b []byte) (bool, []int)
- func (w WildMin) Max() int
- func (w WildMin) Min() int
- func (w WildMin) Pat() patterns.Pattern
- func (w WildMin) Save(ls *persist.LoadSaver)
- func (w WildMin) String() string
- type Window
- func (w Window) Equals(frame Frame) bool
- func (w Window) Linked(prev Frame, maxDistance, maxRange int) bool
- func (w Window) Match(b []byte) (bool, []int)
- func (w Window) MatchR(b []byte) (bool, []int)
- func (w Window) Max() int
- func (w Window) Min() int
- func (w Window) Pat() patterns.Pattern
- func (w Window) Save(ls *persist.LoadSaver)
- func (w Window) String() string
Constants ¶
This section is empty.
Variables ¶
var OffString = [...]string{"B", "P", "S", "E"}
OffString is an exported array of strings representing each of the four offset types
Functions ¶
func NonZero ¶
NonZero checks whether, when converted to simple byte sequences, this frame's pattern is all 0 bytes.
func Register ¶
Register an additional Loader. Must provide an integer between 4 and 7 (the first four loaders are taken by the standard four frames).
func TotalLength ¶
TotalLength is sum of the maximum length of the enclosed pattern and the maximum offset.
Types ¶
type Fixed ¶
Fixed frames are at a fixed offset e.g. 0 or 10 from the BOF, EOF or a preceding or succeeding frame.
func (Fixed) Linked ¶
Linked tests whether a frame is linked to a preceding frame (by a preceding or succeding relationship) with an offset and range that is less than the supplied ints.
func (Fixed) Match ¶
Match the enclosed pattern against the byte slice in a L-R direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
func (Fixed) MatchR ¶
MatchR matches the enclosed pattern against the byte slice in a reverse (R-L) direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
type Frame ¶
type Frame interface { Match([]byte) (bool, []int) // Match the enclosed pattern against the byte slice in a L-R direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin. MatchR([]byte) (bool, []int) // Match the enclosed pattern against the byte slice in a reverse (R-L) direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin. Equals(Frame) bool // Equals tests equality of two frames. String() string Min() int // Min returns the minimum offset a frame can appear at Max() int // Max returns the maximum offset a frame can appear at. Returns -1 for no limit (wildcard, *) Linked(Frame, int, int) bool // Linked tests whether a frame is linked to a preceding frame (by a preceding or succeding relationship) with an offset and range that is less than the supplied ints Pat() patterns.Pattern // Pat exposes the enclosed pattern Save(*persist.LoadSaver) // Save a frame to a LoadSaver. The first byte written should be the identifying byte provided to Register(). // The following methods are inherited from the enclosed OffType Orientation() OffType SwitchOff() OffType // The following methods are inherited from the enclosed pattern Length() (int, int) // min and max lengths of the enclosed pattern NumSequences() int // // the number of simple sequences that the enclosed pattern can be represented by. 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() []patterns.Sequence }
Frame encapsulates a pattern with offset information, mediating between the pattern and the bytestream.
func BMHConvert ¶
BMHConvert converts the patterns within a slice of frames to BMH sequences if possible.
func NewFrame ¶
NewFrame generates Fixed, Window, Wild and WildMin frames. The offsets argument controls what type of frame is created:
- for a Wild frame, give no offsets or give a max offset of < 0 and a min of < 1
- for a WildMin frame, give one offset, or give a max offset of < 0 and a min of > 0
- for a Fixed frame, give two offsets that are both >= 0 and that are equal to each other
- for a Window frame, give two offsets that are both >= 0 and that are not equal to each other.
type OffType ¶
type OffType uint8
OffType is the type of offset
const ( BOF OffType = iota // beginning of file offset PREV // offset from previous frame SUCC // offset from successive frame EOF // end of file offset )
Four offset types are supported
func (OffType) Orientation ¶
Orientation returns the offset type of the frame which must be either BOF, PREV, SUCC or EOF
type Sequencer ¶
Sequencer turns sequential frames into a set of plain byte sequences. The set represents possible choices.
func NewSequencer ¶
NewSequencer creates a Sequencer (reversed if true).
type Signature ¶
type Signature []Frame
Signature is just a slice of frames.
func (Signature) Mirror ¶
Mirror returns a signature in which wildcard previous segments are turned into wildcard succ/eof segments. If no wildcard previous segments are present, nil is returned.
func (Signature) Segment ¶
Segment divides signatures into signature segments. This separation happens on wildcards or when the distance between frames is deemed too great. E.g. a signature of [BOF 0: "ABCD"][PREV 0-20: "EFG"][PREV Wild: "HI"][EOF 0: "XYZ"] has three segments: 1. [BOF 0: "ABCD"][PREV 0-20: "EFG"] 2. [PREV Wild: "HI"] 3. [EOF 0: "XYZ"] The Distance and Range options control the allowable distance and range between frames (i.e. a fixed offset of 5000 distant might be acceptable, where a range of 1-2000 might not be).
type Wild ¶
Wild frames can be at any offset (i.e. 0 to the end of the file) relative to the BOF, EOF or a preceding or succeeding frame.
func (Wild) Linked ¶
Linked tests whether a frame is linked to a preceding frame (by a preceding or succeding relationship) with an offset and range that is less than the supplied ints.
func (Wild) Match ¶
Match the enclosed pattern against the byte slice in a L-R direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
func (Wild) MatchR ¶
MatchR matches the enclosed pattern against the byte slice in a reverse (R-L) direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
type WildMin ¶
WildMin frames have a minimum but no maximum offset (e.g. 200-*) relative to the BOF, EOF or a preceding or succeeding frame.
func (WildMin) Linked ¶
Linked tests whether a frame is linked to a preceding frame (by a preceding or succeding relationship) with an offset and range that is less than the supplied ints.
func (WildMin) Match ¶
Match the enclosed pattern against the byte slice in a L-R direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
func (WildMin) MatchR ¶
MatchR matches the enclosed pattern against the byte slice in a reverse (R-L) direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
func (WildMin) Max ¶
Max returns the maximum offset a frame can appear at. Returns -1 for no limit (wildcard, *).
type Window ¶
Window frames are at a range of offsets e.g. e.g. 1-1500 from the BOF, EOF or a preceding or succeeding frame.
func (Window) Linked ¶
Linked tests whether a frame is linked to a preceding frame (by a preceding or succeding relationship) with an offset and range that is less than the supplied ints.
func (Window) Match ¶
Match the enclosed pattern against the byte slice in a L-R direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.
func (Window) MatchR ¶
MatchR matches the enclosed pattern against the byte slice in a reverse (R-L) direction. Return a boolean to indicate success. If true, return an offset for where a successive match by a related frame should begin.