Documentation ¶
Index ¶
- Constants
- Variables
- func AlignedAlloc(size uint) unsafe.Pointer
- func AlignedFree(ptr unsafe.Pointer)
- func ClearAllocator() error
- func ClearDatabaseAllocator() error
- func ClearMiscAllocator() error
- func ClearScratchAllocator() error
- func ClearStreamAllocator() error
- func CloseStream(stream Stream, s Scratch, cb MatchEventHandler, ctx interface{}) error
- func CompressStream(stream Stream, buf []byte) ([]byte, error)
- func DatabaseInfo(db Database) (string, error)
- func DatabaseSize(db Database) (int, error)
- func DefaultAlloc(size uint) unsafe.Pointer
- func DefaultFree(ptr unsafe.Pointer)
- func DeserializeDatabaseAt(data []byte, db Database) error
- func ExpandStream(db Database, stream *Stream, buf []byte) error
- func ExpressionExt(expression string, flags CompileFlag) (ext *ExprExt, info *ExprInfo, err error)
- func FreeDatabase(db Database) (err error)
- func FreeScratch(scratch Scratch) error
- func FreeStream(stream Stream)
- func ReallocScratch(db Database, scratch *Scratch) error
- func ResetAndCopyStream(to, from Stream, s Scratch, cb MatchEventHandler, ctx interface{}) error
- func ResetAndExpandStream(stream Stream, buf []byte, s Scratch, cb MatchEventHandler, ctx interface{}) error
- func ResetStream(stream Stream, flags ScanFlag, s Scratch, cb MatchEventHandler, ...) error
- func Scan(db Database, data []byte, flags ScanFlag, s Scratch, cb MatchEventHandler, ...) error
- func ScanStream(stream Stream, data []byte, flags ScanFlag, s Scratch, cb MatchEventHandler, ...) error
- func ScanVector(db Database, data [][]byte, flags ScanFlag, s Scratch, cb MatchEventHandler, ...) error
- func ScratchSize(scratch Scratch) (int, error)
- func SerializeDatabase(db Database) (b []byte, err error)
- func SerializedDatabaseInfo(data []byte) (string, error)
- func SerializedDatabaseSize(data []byte) (int, error)
- func SetAllocator(allocFunc AllocFunc, freeFunc FreeFunc) error
- func SetDatabaseAllocator(allocFunc AllocFunc, freeFunc FreeFunc) error
- func SetMiscAllocator(allocFunc AllocFunc, freeFunc FreeFunc) error
- func SetScratchAllocator(allocFunc AllocFunc, freeFunc FreeFunc) error
- func SetStreamAllocator(allocFunc AllocFunc, freeFunc FreeFunc) error
- func StreamSize(db Database) (int, error)
- func ValidPlatform() error
- func Version() string
- type AllocFunc
- type Allocator
- type CompileError
- type CompileFlag
- type CpuFeature
- type Database
- type Error
- type ExprExt
- type ExprInfo
- type ExtFlag
- type FreeFunc
- type MatchEvent
- type MatchEventContext
- type MatchEventHandler
- type MatchRecorder
- type ModeFlag
- type Pattern
- type Patterns
- type PlatformInfo
- type ScanFlag
- type Scratch
- type Stream
- type TuneFlag
Constants ¶
const UnboundedMaxWidth = C.UINT_MAX
UnboundedMaxWidth represents the pattern expression has an unbounded maximum width
Variables ¶
var ( // ErrNoFound means patterns not found. ErrNoFound = errors.New("no found") // ErrUnexpected means item is unexpected. ErrUnexpected = errors.New("unexpected") )
var CompileFlags = map[rune]CompileFlag{ 'i': Caseless, 's': DotAll, 'm': MultiLine, 'H': SingleMatch, 'V': AllowEmpty, '8': Utf8Mode, 'W': UnicodeProperty, 'P': PrefilterMode, 'L': SomLeftMost, }
var DeprecatedCompileFlags = map[rune]CompileFlag{ 'o': SingleMatch, 'e': AllowEmpty, 'u': Utf8Mode, 'p': UnicodeProperty, 'f': PrefilterMode, 'l': SomLeftMost, }
var ModeFlags = map[string]ModeFlag{ "STREAM": StreamMode, "NOSTREAM": BlockMode, "VECTORED": VectoredMode, "BLOCK": BlockMode, }
Functions ¶
func AlignedAlloc ¶
func AlignedFree ¶
func ClearAllocator ¶
func ClearAllocator() error
func ClearDatabaseAllocator ¶
func ClearDatabaseAllocator() error
func ClearMiscAllocator ¶
func ClearMiscAllocator() error
func ClearScratchAllocator ¶
func ClearScratchAllocator() error
func ClearStreamAllocator ¶
func ClearStreamAllocator() error
func CloseStream ¶
func CloseStream(stream Stream, s Scratch, cb MatchEventHandler, ctx interface{}) error
func DatabaseInfo ¶
func DatabaseSize ¶
func DefaultAlloc ¶
func DefaultFree ¶
func DeserializeDatabaseAt ¶
func ExpressionExt ¶
func ExpressionExt(expression string, flags CompileFlag) (ext *ExprExt, info *ExprInfo, err error)
func FreeDatabase ¶
func FreeScratch ¶
func FreeStream ¶
func FreeStream(stream Stream)
func ReallocScratch ¶
func ResetAndCopyStream ¶
func ResetAndCopyStream(to, from Stream, s Scratch, cb MatchEventHandler, ctx interface{}) error
func ResetAndExpandStream ¶
func ResetAndExpandStream(stream Stream, buf []byte, s Scratch, cb MatchEventHandler, ctx interface{}) error
func ResetStream ¶
func ResetStream(stream Stream, flags ScanFlag, s Scratch, cb MatchEventHandler, ctx interface{}) error
func ScanStream ¶
func ScanVector ¶
func ScratchSize ¶
func SerializeDatabase ¶
func SerializedDatabaseInfo ¶
func SerializedDatabaseSize ¶
func SetAllocator ¶
func SetDatabaseAllocator ¶
func SetMiscAllocator ¶
func SetScratchAllocator ¶
func SetStreamAllocator ¶
func StreamSize ¶
func ValidPlatform ¶
func ValidPlatform() error
Types ¶
type Allocator ¶
func DatabaseAllocator ¶
func DatabaseAllocator() *Allocator
func DefaultAllocator ¶
func DefaultAllocator() *Allocator
func MiscAllocator ¶
func MiscAllocator() *Allocator
func ScratchAllocator ¶
func ScratchAllocator() *Allocator
func StreamAllocator ¶
func StreamAllocator() *Allocator
type CompileError ¶
type CompileError struct { // A human-readable error message describing the error. Message string // The zero-based number of the expression that caused the error. Expression int }
A type containing error details that is returned by the compile calls on failure.
The caller may inspect the values returned in this type to determine the cause of failure.
func (*CompileError) Error ¶
func (e *CompileError) Error() string
type CompileFlag ¶
type CompileFlag uint
CompileFlag represents a pattern flag
const ( // Caseless represents set case-insensitive matching. Caseless CompileFlag = C.HS_FLAG_CASELESS // DotAll represents matching a `.` will not exclude newlines. DotAll CompileFlag = C.HS_FLAG_DOTALL // MultiLine set multi-line anchoring. MultiLine CompileFlag = C.HS_FLAG_MULTILINE // SingleMatch set single-match only mode. SingleMatch CompileFlag = C.HS_FLAG_SINGLEMATCH // AllowEmpty allow expressions that can match against empty buffers. AllowEmpty CompileFlag = C.HS_FLAG_ALLOWEMPTY // Utf8Mode enable UTF-8 mode for this expression. Utf8Mode CompileFlag = C.HS_FLAG_UTF8 // UnicodeProperty enable Unicode property support for this expression. UnicodeProperty CompileFlag = C.HS_FLAG_UCP // PrefilterMode enable prefiltering mode for this expression. PrefilterMode CompileFlag = C.HS_FLAG_PREFILTER // SomLeftMost enable leftmost start of match reporting. SomLeftMost CompileFlag = C.HS_FLAG_SOM_LEFTMOST )
const ( // Combination represents logical combination. Combination CompileFlag = C.HS_FLAG_COMBINATION // Quiet represents don't do any match reporting. Quiet CompileFlag = C.HS_FLAG_QUIET )
func (CompileFlag) String ¶
func (flags CompileFlag) String() string
type CpuFeature ¶
type CpuFeature int //nolint: golint,stylecheck,revive
CpuFeature is the CPU feature support flags
const ( // AVX2 is a CPU features flag indicates that the target platform supports AVX2 instructions. AVX2 CpuFeature = C.HS_CPU_FEATURES_AVX2 // AVX512 is a CPU features flag indicates that the target platform supports AVX512 instructions, // specifically AVX-512BW. Using AVX512 implies the use of AVX2. AVX512 CpuFeature = C.HS_CPU_FEATURES_AVX512 )
type Database ¶
type Database *C.hs_database_t
func Compile ¶
func Compile(expression string, flags CompileFlag, mode ModeFlag, info *PlatformInfo) (Database, error)
func CompileMulti ¶
func CompileMulti(input Patterns, mode ModeFlag, info *PlatformInfo) (Database, error)
func DeserializeDatabase ¶
type Error ¶
type Error int
Error represents an error
const ( // ErrSuccess is the error returned if the engine completed normally. ErrSuccess Error = C.HS_SUCCESS // ErrInvalid is the error returned if a parameter passed to this function was invalid. ErrInvalid Error = C.HS_INVALID // ErrNoMemory is the error returned if a memory allocation failed. ErrNoMemory Error = C.HS_NOMEM // ErrScanTerminated is the error returned if the engine was terminated by callback. ErrScanTerminated Error = C.HS_SCAN_TERMINATED // ErrCompileError is the error returned if the pattern compiler failed. ErrCompileError Error = C.HS_COMPILER_ERROR // ErrDatabaseVersionError is the error returned if the given database was built for a different version of Hyperscan. ErrDatabaseVersionError Error = C.HS_DB_VERSION_ERROR // ErrDatabasePlatformError is the error returned if the given database was built for a different platform. ErrDatabasePlatformError Error = C.HS_DB_PLATFORM_ERROR // ErrDatabaseModeError is the error returned if the given database was built for a different mode of operation. ErrDatabaseModeError Error = C.HS_DB_MODE_ERROR // ErrBadAlign is the error returned if a parameter passed to this function was not correctly aligned. ErrBadAlign Error = C.HS_BAD_ALIGN // ErrBadAlloc is the error returned if the memory allocator did not correctly return memory suitably aligned. ErrBadAlloc Error = C.HS_BAD_ALLOC // ErrScratchInUse is the error returned if the scratch region was already in use. ErrScratchInUse Error = C.HS_SCRATCH_IN_USE // ErrArchError is the error returned if unsupported CPU architecture. ErrArchError Error = C.HS_ARCH_ERROR // ErrInsufficientSpace is the error returned if provided buffer was too small. ErrInsufficientSpace Error = C.HS_INSUFFICIENT_SPACE )
const ( // ErrUnknown is an unexpected internal error. ErrUnknown Error = C.HS_UNKNOWN_ERROR )
type ExprExt ¶
type ExprExt struct { // Flags governing which parts of this structure are to be used by the compiler. Flags ExtFlag // The minimum end offset in the data stream at which this expression should match successfully. MinOffset uint64 // The maximum end offset in the data stream at which this expression should match successfully. MaxOffset uint64 // The minimum match length (from start to end) required to successfully match this expression. MinLength uint64 // Allow patterns to approximately match within this edit distance. EditDistance uint32 // Allow patterns to approximately match within this Hamming distance. HammingDistance uint32 }
ExprExt is a structure containing additional parameters related to an expression.
type ExprInfo ¶
type ExprInfo struct { // The minimum length in bytes of a match for the pattern. MinWidth uint // The maximum length in bytes of a match for the pattern. MaxWidth uint // Whether this expression can produce matches that are not returned in order, // such as those produced by assertions. ReturnUnordered bool // Whether this expression can produce matches at end of data (EOD). AtEndOfData bool // Whether this expression can *only* produce matches at end of data (EOD). OnlyAtEndOfData bool }
ExprInfo containing information related to an expression
func ExpressionInfo ¶
func ExpressionInfo(expression string, flags CompileFlag) (*ExprInfo, error)
func NewExprInfo ¶
func NewExprInfo(info *C.hs_expr_info_t) *ExprInfo
type ExtFlag ¶
type ExtFlag uint64
ExtFlag are used in ExprExt.Flags to indicate which fields are used.
const ( // ExtMinOffset is a flag indicating that the ExprExt.MinOffset field is used. ExtMinOffset ExtFlag = C.HS_EXT_FLAG_MIN_OFFSET // ExtMaxOffset is a flag indicating that the ExprExt.MaxOffset field is used. ExtMaxOffset ExtFlag = C.HS_EXT_FLAG_MAX_OFFSET // ExtMinLength is a flag indicating that the ExprExt.MinLength field is used. ExtMinLength ExtFlag = C.HS_EXT_FLAG_MIN_LENGTH // ExtEditDistance is a flag indicating that the ExprExt.EditDistance field is used. ExtEditDistance ExtFlag = C.HS_EXT_FLAG_EDIT_DISTANCE // ExtHammingDistance is a flag indicating that the ExprExt.HammingDistance field is used. ExtHammingDistance ExtFlag = C.HS_EXT_FLAG_HAMMING_DISTANCE )
type MatchEvent ¶
type MatchEventContext ¶
type MatchEventContext struct {
// contains filtered or unexported fields
}
type MatchEventHandler ¶
type MatchRecorder ¶
type MatchRecorder struct { Events []MatchEvent Err error }
func (*MatchRecorder) Handle ¶
func (h *MatchRecorder) Handle(id uint, from, to uint64, flags uint, _ interface{}) error
func (*MatchRecorder) Matched ¶
func (h *MatchRecorder) Matched() bool
type ModeFlag ¶
type ModeFlag uint
ModeFlag represents the compile mode flags
const ( // BlockMode for the block scan (non-streaming) database. BlockMode ModeFlag = C.HS_MODE_BLOCK // NoStreamMode is alias for Block. NoStreamMode ModeFlag = C.HS_MODE_NOSTREAM // StreamMode for the streaming database. StreamMode ModeFlag = C.HS_MODE_STREAM // VectoredMode for the vectored scanning database. VectoredMode ModeFlag = C.HS_MODE_VECTORED // SomHorizonLargeMode use full precision to track start of match offsets in stream state. SomHorizonLargeMode ModeFlag = C.HS_MODE_SOM_HORIZON_LARGE // SomHorizonMediumMode use medium precision to track start of match offsets in stream state. (within 2^32 bytes) SomHorizonMediumMode ModeFlag = C.HS_MODE_SOM_HORIZON_MEDIUM // SomHorizonSmallMode use limited precision to track start of match offsets in stream state. (within 2^16 bytes) SomHorizonSmallMode ModeFlag = C.HS_MODE_SOM_HORIZON_SMALL // ModeMask represents the mask of database mode ModeMask ModeFlag = 0xFF )
type PlatformInfo ¶
type PlatformInfo struct {
Platform C.struct_hs_platform_info
}
func NewPlatformInfo ¶
func NewPlatformInfo(tune TuneFlag, cpu CpuFeature) *PlatformInfo
func PopulatePlatform ¶
func PopulatePlatform() (*PlatformInfo, error)
func (*PlatformInfo) CpuFeatures ¶
func (i *PlatformInfo) CpuFeatures() CpuFeature
CpuFeatures returns the CPU features of the platform.
func (*PlatformInfo) Tune ¶
func (i *PlatformInfo) Tune() TuneFlag
Tune returns the tuning flags of the platform.
type TuneFlag ¶
type TuneFlag int
TuneFlag is the tuning flags
const ( // Generic indicates that the compiled database should not be tuned for any particular target platform. Generic TuneFlag = C.HS_TUNE_FAMILY_GENERIC // SandyBridge indicates that the compiled database should be tuned for the Sandy Bridge microarchitecture. SandyBridge TuneFlag = C.HS_TUNE_FAMILY_SNB // IvyBridge indicates that the compiled database should be tuned for the Ivy Bridge microarchitecture. IvyBridge TuneFlag = C.HS_TUNE_FAMILY_IVB // Haswell indicates that the compiled database should be tuned for the Haswell microarchitecture. Haswell TuneFlag = C.HS_TUNE_FAMILY_HSW // Silvermont indicates that the compiled database should be tuned for the Silvermont microarchitecture. Silvermont TuneFlag = C.HS_TUNE_FAMILY_SLM // Broadwell indicates that the compiled database should be tuned for the Broadwell microarchitecture. Broadwell TuneFlag = C.HS_TUNE_FAMILY_BDW // Skylake indicates that the compiled database should be tuned for the Skylake microarchitecture. Skylake TuneFlag = C.HS_TUNE_FAMILY_SKL // SkylakeServer indicates that the compiled database should be tuned for the Skylake Server microarchitecture. SkylakeServer TuneFlag = C.HS_TUNE_FAMILY_SKX // Goldmont indicates that the compiled database should be tuned for the Goldmont microarchitecture. Goldmont TuneFlag = C.HS_TUNE_FAMILY_GLM )