-
Notifications
You must be signed in to change notification settings - Fork 6
/
endpoint.go
41 lines (32 loc) · 1.14 KB
/
endpoint.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
// SPDX-FileCopyrightText: 2021 Henry Bubert
//
// SPDX-License-Identifier: MIT
package muxrpc
import (
"context"
"log"
"net"
)
//go:generate counterfeiter -o fakeendpoint_test.go . Endpoint
// Endpoint allows calling functions on the RPC peer.
type Endpoint interface {
// The different call types:
Async(ctx context.Context, ret interface{}, tipe RequestEncoding, method Method, args ...interface{}) error
Source(ctx context.Context, tipe RequestEncoding, method Method, args ...interface{}) (*ByteSource, error)
Sink(ctx context.Context, tipe RequestEncoding, method Method, args ...interface{}) (*ByteSink, error)
Duplex(ctx context.Context, tipe RequestEncoding, method Method, args ...interface{}) (*ByteSource, *ByteSink, error)
// Terminate wraps up the RPC session
Terminate() error
// Remote returns the network address of the remote
Remote() net.Addr
}
// HasMethod returns true if an endpoint supports a specific method
func HasMethod(edp Endpoint, m Method) bool {
rpc, ok := edp.(*rpc)
if !ok {
log.Printf("[warning] muxrpc: %T is not a *rpc", edp)
return false
}
_, doesHandle := rpc.manifest.Handled(m)
return doesHandle
}