Debian Codegraph @

transport.go

raw
1 package centrifuge
2
3 import "github.com/centrifugal/protocol"
4
5 // ProtocolType represents client connection transport encoding format.
6 type ProtocolType string
7
8 func (t ProtocolType) toProto() protocol.Type {
9 return protocol.Type(t)
10 }
11
12 const (
13 // ProtocolTypeJSON means JSON protocol - i.e. data encoded in
14 // JSON-streaming format.
15 ProtocolTypeJSON ProtocolType = "json"
16 // ProtocolTypeProtobuf means protobuf protocol - i.e. data encoded
17 // as length-delimited protobuf messages.
18 ProtocolTypeProtobuf ProtocolType = "protobuf"
19 )
20
21 // EncodingType represents client payload encoding format.
22 type EncodingType string
23
24 const (
25 // EncodingTypeJSON means JSON payload.
26 EncodingTypeJSON EncodingType = "json"
27 // EncodingTypeBinary means binary payload.
28 EncodingTypeBinary EncodingType = "binary"
29 )
30
31 // TransportInfo has read-only transport description methods.
32 type TransportInfo interface {
33 // Name returns a name of transport used for client connection.
34 Name() string
35 // Protocol returns underlying transport protocol type used.
36 // At moment this can be for example a JSON streaming based protocol
37 // or Protobuf length-delimited protocol.
38 Protocol() ProtocolType
39 // Encoding returns payload encoding type used by client. By default
40 // server assumes that payload passed as JSON.
41 Encoding() EncodingType
42 }
43
44 // Transport abstracts a connection transport between server and client.
45 // It does not contain Read method as reading can be handled by connection
46 // handler code (for example by WebsocketHandler.ServeHTTP).
47 type Transport interface {
48 TransportInfo
49 // Write data encoded using Centrifuge protocol to connection.
50 Write([]byte) error
51 // Close closes transport.
52 Close(*Disconnect) error
53 }