forked from davidfowl/signalr-ports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hubprotocol.go
66 lines (56 loc) · 1.77 KB
/
hubprotocol.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
package signalr
import (
"bytes"
"io"
)
// HubProtocol interface
// ReadMessage() reads a message from buf and returns the message if the buf contained one completely.
// If buf does not contain the whole message, it returns a nil message and complete false
// WriteMessage writes a message to the specified writer
// UnmarshalArgument() unmarshals a raw message depending of the specified value type into value
type HubProtocol interface {
ReadMessage(buf *bytes.Buffer) (interface{}, bool, error)
WriteMessage(message interface{}, writer io.Writer) error
UnmarshalArgument(argument interface{}, value interface{}) error
setDebugLogger(dbg StructuredLogger)
}
// Protocol
type hubMessage struct {
Type int `json:"type"`
}
type invocationMessage struct {
Type int
Target string
InvocationID string
Arguments []interface{}
StreamIds []string
}
type sendOnlyHubInvocationMessage struct {
Type int `json:"type"`
Target string `json:"target"`
Arguments []interface{} `json:"arguments"`
}
type completionMessage struct {
Type int `json:"type"`
InvocationID string `json:"invocationId"`
Result interface{} `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
type streamItemMessage struct {
Type int `json:"type"`
InvocationID string `json:"invocationId"`
Item interface{} `json:"item"`
}
type cancelInvocationMessage struct {
Type int `json:"type"`
InvocationID string `json:"invocationId"`
}
type closeMessage struct {
Type int `json:"type"`
Error string `json:"error"`
AllowReconnect bool `json:"allowReconnect"`
}
type handshakeRequest struct {
Protocol string `json:"Protocol"`
Version int `json:"version"`
}