summaryrefslogtreecommitdiff
path: root/payload.go
blob: 9e1366df586035a758a6d955d9b7af758eab5543 (plain)
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
38
39
40
41
42
43
package roadrunner

import (
	"bufio"
)

// Payload carries binary header and body to workers and
// back to the server.
type Payload struct {
	// Context represent payload context, might be omitted.
	Context []byte

	// body contains binary payload to be processed by worker.
	Body []byte

	// attached when worker responds with the stream
	stream *bufio.Reader

	// close callback will be called when payload is closed
	cc func()
}

// String returns payload body as string
func (p *Payload) String() string {
	return string(p.Body)
}

// Stream returns true is payload is streaming.
func (p *Payload) Stream() bool {
	return p.stream != nil
}

// Stream returns associated stream.
func (p *Payload) Read(d []byte) (n int, err error) {
	return p.stream.Read(d)
}

// Close closes underlying stream and notifies stream end watchers.
func (p *Payload) Close() {
	if p.cc != nil {
		p.cc()
	}
}