Exemplo n.º 1
0
func (fs *frameSet) save(ls *persist.LoadSaver) {
	ls.SaveSmallInt(len(fs.set))
	for _, f := range fs.set {
		f.Save(ls)
	}
	ls.SaveInts(fs.testTreeIndex)
}
Exemplo n.º 2
0
// Save persists the pattern.
func (c Choice) Save(ls *persist.LoadSaver) {
	ls.SaveByte(choiceLoader)
	ls.SaveSmallInt(len(c))
	for _, pat := range c {
		pat.Save(ls)
	}
}
Exemplo n.º 3
0
// Save persists the pattern.
func (l List) Save(ls *persist.LoadSaver) {
	ls.SaveByte(listLoader)
	ls.SaveSmallInt(len(l))
	for _, pat := range l {
		pat.Save(ls)
	}
}
Exemplo n.º 4
0
func loadWildMin(ls *persist.LoadSaver) Frame {
	return WildMin{
		OffType(ls.LoadByte()),
		ls.LoadInt(),
		patterns.Load(ls),
	}
}
Exemplo n.º 5
0
func loadFixed(ls *persist.LoadSaver) Frame {
	return Fixed{
		OffType(ls.LoadByte()),
		ls.LoadInt(),
		patterns.Load(ls),
	}
}
Exemplo n.º 6
0
func saveTestNodes(ls *persist.LoadSaver, tns []*testNode) {
	ls.SaveSmallInt(len(tns))
	for _, n := range tns {
		n.Frame.Save(ls)
		ls.SaveInts(n.success)
		saveTestNodes(ls, n.tests)
	}
}
Exemplo n.º 7
0
func loadRBMH(ls *persist.LoadSaver) Pattern {
	rbmh := &RBMHSequence{}
	rbmh.Seq = Sequence(ls.LoadBytes())
	for i := range rbmh.Shift {
		rbmh.Shift[i] = ls.LoadSmallInt()
	}
	return rbmh
}
Exemplo n.º 8
0
func loadBMH(ls *persist.LoadSaver) Pattern {
	bmh := &BMHSequence{}
	bmh.Seq = Sequence(ls.LoadBytes())
	for i := range bmh.Shift {
		bmh.Shift[i] = ls.LoadSmallInt()
	}
	return bmh
}
Exemplo n.º 9
0
func loadList(ls *persist.LoadSaver) Pattern {
	le := ls.LoadSmallInt()
	list := make(List, le)
	for i := range list {
		list[i] = Load(ls)
	}
	return list
}
Exemplo n.º 10
0
func loadChoice(ls *persist.LoadSaver) Pattern {
	l := ls.LoadSmallInt()
	choices := make(Choice, l)
	for i := range choices {
		choices[i] = Load(ls)
	}
	return choices
}
Exemplo n.º 11
0
func Load(ls *persist.LoadSaver) Matcher {
	ret := make(Matcher, ls.LoadTinyUInt())
	for i := range ret {
		ret[i] = loadCM(ls)
		ret[i].ctype = ctypes[ret[i].conType]
		ret[i].entryBufs = siegreader.New()
	}
	return ret
}
Exemplo n.º 12
0
// Load a frame from a persist.LoadSaver
func Load(ls *persist.LoadSaver) Frame {
	id := ls.LoadByte()
	l := loaders[int(id)]
	if l == nil {
		if ls.Err == nil {
			ls.Err = errors.New("bad frame loader")
		}
		return nil
	}
	return l(ls)
}
Exemplo n.º 13
0
// LoadIdentifier applies the appropriate IdentifierLoader to load an identifier.
func LoadIdentifier(ls *persist.LoadSaver) Identifier {
	id := ls.LoadByte()
	l := loaders[int(id)]
	if l == nil {
		if ls.Err == nil {
			ls.Err = errors.New("bad identifier loader")
		}
		return nil
	}
	return l(ls)
}
Exemplo n.º 14
0
func (c *ContainerMatcher) save(ls *persist.LoadSaver) {
	ls.SaveInts(c.startIndexes)
	ls.SaveTinyUInt(int(c.conType))
	saveCTests(ls, c.nameCTest)
	ls.SaveInts(c.parts)
	c.priorities.Save(ls)
	ls.SaveString(c.extension)
}
Exemplo n.º 15
0
func loadTestNodes(ls *persist.LoadSaver) []*testNode {
	l := ls.LoadSmallInt()
	if l == 0 {
		return nil
	}
	ret := make([]*testNode, l)
	for i := range ret {
		ret[i] = &testNode{
			frames.Load(ls),
			ls.LoadInts(),
			loadTestNodes(ls),
		}
	}
	return ret
}
Exemplo n.º 16
0
func saveCTests(ls *persist.LoadSaver, ct map[string]*cTest) {
	ls.SaveSmallInt(len(ct))
	for k, v := range ct {
		ls.SaveString(k)
		ls.SaveInts(v.satisfied)
		ls.SaveInts(v.unsatisfied)
		v.bm.Save(ls)
	}
}
Exemplo n.º 17
0
func Load(ls *persist.LoadSaver) *Matcher {
	if !ls.LoadBool() {
		return nil
	}
	return &Matcher{
		keyFrames:  loadKeyFrames(ls),
		tests:      loadTests(ls),
		bofFrames:  loadFrameSet(ls),
		eofFrames:  loadFrameSet(ls),
		bofSeq:     loadSeqSet(ls),
		eofSeq:     loadSeqSet(ls),
		maxBOF:     ls.LoadInt(),
		maxEOF:     ls.LoadInt(),
		priorities: priority.Load(ls),
		mu:         &sync.Mutex{},
	}
}
Exemplo n.º 18
0
func (m Matcher) Save(ls *persist.LoadSaver) {
	ls.SaveSmallInt(len(m))
	for k, v := range m {
		ls.SaveString(k)
		ls.SaveSmallInt(len(v))
		for _, w := range v {
			ls.SaveSmallInt(int(w))
		}
	}
}
Exemplo n.º 19
0
func (s *Set) Save(ls *persist.LoadSaver) {
	ls.SaveInts(s.Idx)
	ls.SaveSmallInt(len(s.Lists))
	for _, v := range s.Lists {
		ls.SaveSmallInt(len(v))
		for _, w := range v {
			ls.SaveInts(w)
		}
	}
}
Exemplo n.º 20
0
func loadCM(ls *persist.LoadSaver) *ContainerMatcher {
	return &ContainerMatcher{
		startIndexes: ls.LoadInts(),
		conType:      containerType(ls.LoadTinyUInt()),
		nameCTest:    loadCTests(ls),
		parts:        ls.LoadInts(),
		priorities:   priority.Load(ls),
		extension:    ls.LoadString(),
	}
}
Exemplo n.º 21
0
func Load(ls *persist.LoadSaver) *Set {
	set := &Set{}
	set.Idx = ls.LoadInts()
	if set.Idx == nil {
		_ = ls.LoadSmallInt() // discard the empty list too
		return set
	}
	set.Lists = make([]List, ls.LoadSmallInt())
	for i := range set.Lists {
		le := ls.LoadSmallInt()
		if le == 0 {
			continue
		}
		set.Lists[i] = make(List, le)
		for j := range set.Lists[i] {
			set.Lists[i][j] = ls.LoadInts()
		}
	}
	return set
}
Exemplo n.º 22
0
// Save persists the pattern.
func (s *RBMHSequence) Save(ls *persist.LoadSaver) {
	ls.SaveByte(rbmhLoader)
	ls.SaveBytes(s.Seq)
	for _, v := range s.Shift {
		ls.SaveSmallInt(v)
	}
}
Exemplo n.º 23
0
// Save frame to a LoadSaver.
func (w Window) Save(ls *persist.LoadSaver) {
	ls.SaveByte(windowLoader)
	ls.SaveByte(byte(w.OffType))
	ls.SaveInt(w.MinOff)
	ls.SaveInt(w.MaxOff)
	w.Pattern.Save(ls)
}
Exemplo n.º 24
0
func Load(ls *persist.LoadSaver) Matcher {
	le := ls.LoadSmallInt()
	if le == 0 {
		return nil
	}
	ret := make(Matcher)
	for i := 0; i < le; i++ {
		k := ls.LoadString()
		r := make([]result, ls.LoadSmallInt())
		for j := range r {
			r[j] = result(ls.LoadSmallInt())
		}
		ret[k] = r
	}
	return ret
}
Exemplo n.º 25
0
func (b *Matcher) Save(ls *persist.LoadSaver) {
	if b == nil {
		ls.SaveBool(false)
		return
	}
	ls.SaveBool(true)
	saveKeyFrames(ls, b.keyFrames)
	saveTests(ls, b.tests)
	b.bofFrames.save(ls)
	b.eofFrames.save(ls)
	b.bofSeq.save(ls)
	b.eofSeq.save(ls)
	ls.SaveInt(b.knownBOF)
	ls.SaveInt(b.knownEOF)
	ls.SaveInt(b.maxBOF)
	ls.SaveInt(b.maxEOF)
	b.priorities.Save(ls)
}
Exemplo n.º 26
0
func loadCTests(ls *persist.LoadSaver) map[string]*cTest {
	ret := make(map[string]*cTest)
	l := ls.LoadSmallInt()
	for i := 0; i < l; i++ {
		ret[ls.LoadString()] = &cTest{
			satisfied:   ls.LoadInts(),
			unsatisfied: ls.LoadInts(),
			bm:          bytematcher.Load(ls),
		}
	}
	return ret
}
Exemplo n.º 27
0
func loadFrameSet(ls *persist.LoadSaver) *frameSet {
	ret := &frameSet{}
	le := ls.LoadSmallInt()
	if le == 0 {
		_ = ls.LoadInts()
		return ret
	}
	ret.set = make([]frames.Frame, le)
	for i := range ret.set {
		ret.set[i] = frames.Load(ls)
	}
	ret.testTreeIndex = ls.LoadInts()
	return ret
}
Exemplo n.º 28
0
// Save frame to a LoadSaver.
func (f Fixed) Save(ls *persist.LoadSaver) {
	ls.SaveByte(fixedLoader)
	ls.SaveByte(byte(f.OffType))
	ls.SaveInt(f.Off)
	f.Pattern.Save(ls)
}
Exemplo n.º 29
0
// Save frame to a LoadSaver.
func (w WildMin) Save(ls *persist.LoadSaver) {
	ls.SaveByte(wildMinLoader)
	ls.SaveByte(byte(w.OffType))
	ls.SaveInt(w.MinOff)
	w.Pattern.Save(ls)
}
Exemplo n.º 30
0
// Save frame to a LoadSaver.
func (w Wild) Save(ls *persist.LoadSaver) {
	ls.SaveByte(wildLoader)
	ls.SaveByte(byte(w.OffType))
	w.Pattern.Save(ls)
}