Exemplo n.º 1
0
func (fs *frameSet) index(buf *siegreader.Buffer, rev bool, quit chan struct{}) chan fsmatch {
	ret := make(chan fsmatch)
	go func() {
		for i, f := range fs.set {
			select {
			case <-quit:
				close(ret)
				return
			default:
			}
			var match bool
			var matches []int
			if rev {
				slc, err := buf.EofSlice(0, frames.TotalLength(f))
				if err != nil {
					close(ret)
					return
				}
				match, matches = f.MatchR(slc)
			} else {
				slc, err := buf.Slice(0, frames.TotalLength(f))
				if err != nil {
					close(ret)
					return
				}
				match, matches = f.Match(slc)
			}
			if match {
				var min int
				if !rev {
					min, _ = f.Length()
				}
				for _, off := range matches {
					ret <- fsmatch{i, int64(off - min), min}
				}
			}
		}
		close(ret)
	}()
	return ret
}
Exemplo n.º 2
0
func (t *testNode) length() int {
	return frames.TotalLength(t.Frame)
}