Documentation
¶
Overview ¶
Package protocol provides functionalities to create payloads and compose packet that conform to the booster protocol.
Index ¶
- Constants
- Variables
- func Decode(p []byte, v interface{}, f DecoderFunc) error
- func Encode(v interface{}, f EncoderFunc) ([]byte, error)
- func IsVersionSupported(v string) bool
- type DecoderFunc
- type EncoderFunc
- type Encoding
- type Header
- type Message
- type Module
- type Operation
- type PayloadBandwidth
- type PayloadConnect
- type PayloadCtrl
- type PayloadDisconnect
- type PayloadHeartbeat
- type PayloadHello
- type PayloadMonitor
- type PayloadNode
- type PayloadProxyUpdate
- type Tunnel
Constants ¶
const ( PacketOpeningTag = ">" PacketClosingTag = "<" PayloadOpeningTag = "[" PayloadClosingTag = "]" Separator = ":" )
Tags used in the encoding and decoding of packets.
const Version = "v0.1.0"
Booster protocol version
Variables ¶
var HeaderDecoder = decodeHeader
var HeaderEncoder = encodeHeader
HeaderEncoder is the default function used to encode the headers.
var PayloadDecoders = map[Message]DecoderFunc{
MessageHello: decodeHello,
MessageConnect: decodeConnect,
MessageDisconnect: decodeDisconnect,
MessageHeartbeat: decodeHeartbeat,
MessageMonitor: decodeMonitor,
MessageCtrl: decodeCtrl,
MessageNetworkStatus: decodeBandwidth,
MessageNodeStatus: decodeNode,
MessageProxyUpdate: decodeProxyUpdate,
}
Implemented default decoders
var PayloadEncoders = map[Message]EncoderFunc{
MessageHello: encodeHello,
MessageConnect: encodeConnect,
MessageDisconnect: encodeDisconnect,
MessageHeartbeat: encodeHeartbeat,
MessageMonitor: encodeMonitor,
MessageCtrl: encodeCtrl,
MessageNetworkStatus: encodeBandwidth,
MessageNodeStatus: encodeNode,
MessageProxyUpdate: encodeProxyUpdate,
}
Implemented default encoders
Functions ¶
func Decode ¶ added in v0.4.0
func Decode(p []byte, v interface{}, f DecoderFunc) error
Decode takes as input a byte slice and tries to decode it into v. f is used for the internal mapping between public and private structs used for the data transmission.
v has to be a pointer to a struct.
func Encode ¶ added in v0.4.0
func Encode(v interface{}, f EncoderFunc) ([]byte, error)
Encoder tries to encode v using f.
v has to be a value, not a pointer (in fact we don't want v to be modified by this function in any way). When encoding an header using the default HeaderEncoders, v has to be a Message, which will be used to choose how to build the header using a default configuration, such as the encoding will be set to protobuf, the modules field will contain the payload module, etc. When encoding custom packets its betters to pass a custom EncoderFunc as parameter.
func IsVersionSupported ¶
IsVersionSupported returns true if the current protocol version is compatible with the requested version.
Types ¶
type DecoderFunc ¶ added in v0.4.0
DecoderFunc defines how a decoder should behave.
type EncoderFunc ¶ added in v0.4.0
EncoderFunc defines how an encoder should behave.
type Message ¶
type Message int32
type Operation ¶
type Operation int32
func OperationFromString ¶
OperationFromString converts raw, if possible, into a protocol known operation. Returns an error if no match is found.
type PayloadBandwidth ¶
type PayloadConnect ¶
type PayloadConnect struct {
Target string
}
type PayloadCtrl ¶
type PayloadCtrl struct {
Operation Operation
}
type PayloadDisconnect ¶
type PayloadDisconnect struct {
ID string
}
type PayloadHello ¶
type PayloadMonitor ¶ added in v0.4.0
type PayloadMonitor struct {
Features []Message
}