-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathendpoint_custom.go
67 lines (52 loc) · 1.24 KB
/
endpoint_custom.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gomavlib
import (
"io"
)
type removeCloser struct {
wrapped io.ReadWriteCloser
}
func (r *removeCloser) Read(p []byte) (int, error) {
return r.wrapped.Read(p)
}
func (r *removeCloser) Write(p []byte) (int, error) {
return r.wrapped.Write(p)
}
func (r *removeCloser) Close() error {
return nil
}
// EndpointCustom sets up a endpoint that works with a custom interface
// that provides the Read(), Write() and Close() functions.
type EndpointCustom struct {
// struct or interface implementing Read(), Write() and Close()
ReadWriteCloser io.ReadWriteCloser
}
func (conf EndpointCustom) init(node *Node) (Endpoint, error) {
e := &endpointCustom{
node: node,
conf: conf,
}
err := e.initialize()
return e, err
}
type endpointCustom struct {
node *Node
conf EndpointCustom
rwc io.ReadWriteCloser
}
func (e *endpointCustom) close() {
e.rwc.Close()
}
func (e *endpointCustom) initialize() error {
e.rwc = e.conf.ReadWriteCloser
return nil
}
func (e *endpointCustom) isEndpoint() {}
func (e *endpointCustom) Conf() EndpointConf {
return e.conf
}
func (e *endpointCustom) oneChannelAtAtime() bool {
return true
}
func (e *endpointCustom) provide() (string, io.ReadWriteCloser, error) {
return "custom", &removeCloser{e.rwc}, nil
}