frames

package
v1.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var OffString = [...]string{"B", "P", "S", "E"}

OffString is an exported array of strings representing each of the four offset types

Functions

func NonZero

func NonZero(f Frame) bool

NonZero checks whether, when converted to simple byte sequences, this frame's pattern is all 0 bytes.

func Register

func Register(id byte, l Loader)

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

func TotalLength(f Frame) int

TotalLength is sum of the maximum length of the enclosed pattern and the maximum offset.

Types

type Fixed

type Fixed struct {
	OffType
	Off int
	patterns.Pattern
}

Fixed frames are at a fixed offset e.g. 0 or 10 from the BOF, EOF or a preceding or succeeding frame.

func (Fixed) Equals

func (f Fixed) Equals(frame Frame) bool

Equals tests equality of two frames

func (Fixed) Linked

func (f Fixed) Linked(prev Frame, maxDistance, maxRange 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.

func (Fixed) Match

func (f Fixed) Match(b []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.

func (Fixed) MatchR

func (f Fixed) MatchR(b []byte) (bool, []int)

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 (Fixed) Max

func (f Fixed) Max() int

Max returns the maximum offset a frame can appear at. Returns -1 for no limit (wildcard, *).

func (Fixed) Min

func (f Fixed) Min() int

Min returns the minimum offset a frame can appear at.

func (Fixed) Pat

func (f Fixed) Pat() patterns.Pattern

Pat exposes the enclosed pattern.

func (Fixed) Save

func (f Fixed) Save(ls *persist.LoadSaver)

Save frame to a LoadSaver.

func (Fixed) String

func (f Fixed) String() string

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

func BMHConvert(fs []Frame, rev bool) []Frame

BMHConvert converts the patterns within a slice of frames to BMH sequences if possible.

func Load

func Load(ls *persist.LoadSaver) Frame

Load a frame from a persist.LoadSaver

func NewFrame

func NewFrame(typ OffType, pat patterns.Pattern, offsets ...int) Frame

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.

func SwitchFrame

func SwitchFrame(f Frame, p patterns.Pattern) Frame

SwitchFrame returns a new frame with a different orientation (for example to allow right-left searching).

type Loader

type Loader func(*persist.LoadSaver) Frame

Loader is any function that accepts a persist.LoadSaver and returns a Frame.

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

func (o OffType) Orientation() OffType

Orientation returns the offset type of the frame which must be either BOF, PREV, SUCC or EOF

func (OffType) SwitchOff

func (o OffType) SwitchOff() OffType

SwitchOff returns a new offset type according to a given set of rules. These are:

  • PREV -> SUCC
  • SUCC and EOF -> PREV

This is helpful when changing the orientation of a frame (for example to allow right-left searching).

type Sequencer

type Sequencer func(Frame) [][]byte

Sequencer turns sequential frames into a set of plain byte sequences. The set represents possible choices.

func NewSequencer

func NewSequencer(rev bool) Sequencer

NewSequencer creates a Sequencer (reversed if true).

type Signature

type Signature []Frame

Signature is just a slice of frames.

func (Signature) Equals

func (s Signature) Equals(s1 Signature) bool

Equals tests equality of two signatures.

func (Signature) Mirror

func (s Signature) Mirror() Signature

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

func (s Signature) Segment(dist, rng int) []Signature

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).

func (Signature) String

func (s Signature) String() string

type Wild

type Wild struct {
	OffType
	patterns.Pattern
}

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) Equals

func (w Wild) Equals(frame Frame) bool

Equals tests equality of two frames.

func (Wild) Linked

func (w Wild) Linked(prev Frame, maxDistance, maxRange 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.

func (Wild) Match

func (w Wild) Match(b []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.

func (Wild) MatchR

func (w Wild) MatchR(b []byte) (bool, []int)

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 (Wild) Max

func (w Wild) Max() int

Max returns the maximum offset a frame can appear at. Returns -1 for no limit (wildcard, *).

func (Wild) Min

func (w Wild) Min() int

Min returns the minimum offset a frame can appear at.

func (Wild) Pat

func (w Wild) Pat() patterns.Pattern

Pat exposes the enclosed pattern.

func (Wild) Save

func (w Wild) Save(ls *persist.LoadSaver)

Save frame to a LoadSaver.

func (Wild) String

func (w Wild) String() string

type WildMin

type WildMin struct {
	OffType
	MinOff int
	patterns.Pattern
}

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) Equals

func (w WildMin) Equals(frame Frame) bool

Equals tests equality of two frames.

func (WildMin) Linked

func (w WildMin) Linked(prev Frame, maxDistance, maxRange 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.

func (WildMin) Match

func (w WildMin) Match(b []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.

func (WildMin) MatchR

func (w WildMin) MatchR(b []byte) (bool, []int)

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

func (w WildMin) Max() int

Max returns the maximum offset a frame can appear at. Returns -1 for no limit (wildcard, *).

func (WildMin) Min

func (w WildMin) Min() int

Min returns the minimum offset a frame can appear at.

func (WildMin) Pat

func (w WildMin) Pat() patterns.Pattern

Pat exposes the enclosed pattern.

func (WildMin) Save

func (w WildMin) Save(ls *persist.LoadSaver)

Save frame to a LoadSaver.

func (WildMin) String

func (w WildMin) String() string

type Window

type Window struct {
	OffType
	MinOff int
	MaxOff int
	patterns.Pattern
}

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) Equals

func (w Window) Equals(frame Frame) bool

Equals tests equality of two frames

func (Window) Linked

func (w Window) Linked(prev Frame, maxDistance, maxRange 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.

func (Window) Match

func (w Window) Match(b []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.

func (Window) MatchR

func (w Window) MatchR(b []byte) (bool, []int)

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 (Window) Max

func (w Window) Max() int

Max returns the maximum offset a frame can appear at. Returns -1 for no limit (wildcard, *).

func (Window) Min

func (w Window) Min() int

Min returns the minimum offset a frame can appear at.

func (Window) Pat

func (w Window) Pat() patterns.Pattern

Pat exposes the enclosed pattern.

func (Window) Save

func (w Window) Save(ls *persist.LoadSaver)

Save frame to a LoadSaver.

func (Window) String

func (w Window) String() string

Directories

Path Synopsis
Package tests exports shared frames and signatures for use by the other bytematcher packages
Package tests exports shared frames and signatures for use by the other bytematcher packages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL