forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode.go
37 lines (32 loc) · 816 Bytes
/
encode.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
31
32
33
34
35
36
37
package reader
import (
"io"
"time"
"github.com/elastic/beats/filebeat/harvester/encoding"
)
// Encode reader produces lines by reading lines from an io.Reader
// through a decoder converting the reader it's encoding to utf-8.
type Encode struct {
reader *Line
}
// NewEncode creates a new Encode reader from input reader by applying
// the given codec.
func NewEncode(
reader io.Reader,
codec encoding.Encoding,
bufferSize int,
) (Encode, error) {
r, err := NewLine(reader, codec, bufferSize)
return Encode{r}, err
}
// Next reads the next line from it's initial io.Reader
// This converts a io.Reader to a reader.reader
func (p Encode) Next() (Message, error) {
c, sz, err := p.reader.Next()
// Creating message object
return Message{
Ts: time.Now(),
Content: c,
Bytes: sz,
}, err
}