Beispiel #1
0
// Write writes a compiled ruleset to an io.Writer.
func (r *Rules) Write(wr io.Writer) (err error) {
	var stream C.YR_STREAM
	stream.user_data = unsafe.Pointer(&wr)
	stream.write = C.YR_STREAM_WRITE_FUNC(C.stream_write)
	err = newError(C.yr_rules_save_stream(r.cptr, &stream))
	return
}
Beispiel #2
0
// ReadRules retrieves a compiled ruleset from an io.Reader
func ReadRules(rd io.Reader) (*Rules, error) {
	var yrRules *C.YR_RULES
	var stream C.YR_STREAM
	stream.user_data = unsafe.Pointer(&rd)
	stream.read = C.YR_STREAM_READ_FUNC(C.stream_read)
	if err := newError(C.yr_rules_load_stream(&stream, &yrRules)); err != nil {
		return nil, err
	}
	r := &Rules{rules: &rules{cptr: yrRules}}
	runtime.SetFinalizer(r.rules, (*rules).finalize)
	return r, nil
}
Beispiel #3
0
func writeStream(w io.Writer) *C.YR_STREAM {
	stream := new(C.YR_STREAM)
	stream.user_data = unsafe.Pointer(&w)
	stream.write = (C.YR_STREAM_WRITE_FUNC)(C.goStreamWrite)
	return stream
}
Beispiel #4
0
func readStream(r io.Reader) *C.YR_STREAM {
	stream := new(C.YR_STREAM)
	stream.user_data = unsafe.Pointer(&r)
	stream.read = (C.YR_STREAM_READ_FUNC)(C.goStreamRead)
	return stream
}