-
Notifications
You must be signed in to change notification settings - Fork 1
/
processor.go
30 lines (26 loc) · 1.08 KB
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package conveyor
// LineProcessor is the interface that wraps the Process method.
//
// Process gets the line that needs to be processed with the line metadata
// and returns the converted line or an error if the conversion failed.
// It is also valid to return an empty result if the line should be excluded from
// the output e.g when the file should not be mapped but processed in
// another way.
type LineProcessor interface {
Process(line []byte, metadata LineMetadata) (out []byte, err error)
}
// LineMetadata is the metadata passed to LineProcessor.Process.
// Line is the line number relative to the chunk.
// Chunk is a pointer to the chunk which contains that line.
type LineMetadata struct {
WorkerId int
Line int
Chunk *Chunk
}
// The LineProcessorFunc type is an adapter that allows the use of
// ordinary functions as LineProcessor.
type LineProcessorFunc func([]byte, LineMetadata) ([]byte, error)
// Process calls the underlying LineProcessorFunc.
func (f LineProcessorFunc) Process(line []byte, metadata LineMetadata) (out []byte, err error) {
return f(line, metadata)
}