Documentation
¶
Overview ¶
Package protocol implements decoding and encoding of client/server messages of the Locksmith protocol.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrServerMessageDecode = errors.New("server message decoding error") ErrClientMessageDecode = errors.New("client message decoding error") ErrServerMessageType = errors.New("server message type not found") ErrClientMessageType = errors.New("client message type not found") ErrLockTagSize = errors.New("lock tag size does not match actual lock tag size") ErrLockTagEncoding = errors.New("lock tag was not valid UTF8") )
Errors returned by encoding/decoding functions.
Functions ¶
func EncodeClientMessage ¶
func EncodeClientMessage(clientMessage *ClientMessage) []byte
EncodeServerMessage converts a ServerMessage into a slice of bytes to be sent over a wire.
func EncodeServerMessage ¶
func EncodeServerMessage(serverMessage *ServerMessage) []byte
EncodeServerMessage converts a ServerMessage into a slice of bytes to be sent over a wire.
Types ¶
type ClientMessage ¶
type ClientMessage struct {
Type ClientMessageType
LockTag string
}
ClientMessage models a client-bound message.
func DecodeClientMessage ¶
func DecodeClientMessage(bytes []byte) (*ClientMessage, error)
DecodeClientMessage decodes a slice of bytes into a ClientMessage pointer.
There are a few possible errors:
- The length exceeds or is shorter than the possible bounds.
- The lock tag size does not match the communicated size.
- The client message type is not recognized.
- The lock tag is not valid UTF8.
type ClientMessageType ¶
type ClientMessageType byte
ClientMessageType encompasses all messages: Locksmith -> Client.
const (
Acquired ClientMessageType = 0
)
type ServerMessage ¶
type ServerMessage struct {
Type ServerMessageType
LockTag string
}
ServerMessage models a server-bound message.
func DecodeServerMessage ¶
func DecodeServerMessage(bytes []byte) (*ServerMessage, error)
DecodeServerMessage decodes a slice of bytes into a ServerMessage pointer.
There are a few possible errors:
- The length exceeds or is shorter than the possible bounds.
- The lock tag size does not match the communicated size.
- The server message type is not recognized.
- The lock tag is not valid UTF8.
type ServerMessageType ¶
type ServerMessageType byte
ServerMessageType encompasses all messages: Client -> Locksmith.
const ( Acquire ServerMessageType = 0 Release ServerMessageType = 1 )