bolt

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResetMsg    Type = "RESET"
	RunMsg           = "RUN"
	DiscardMsg       = "DISCARD"
	PullMsg          = "PULL"
	RecordMsg        = "RECORD"
	SuccessMsg       = "SUCCESS"
	IgnoreMsg        = "IGNORE"
	FailureMsg       = "FAILURE"
	HelloMsg         = "HELLO"
	GoodbyeMsg       = "GOODBYE"
	BeginMsg         = "BEGIN"
	CommitMsg        = "COMMIT"
	RollbackMsg      = "ROLLBACK"
	UnknownMsg       = "?UNKNOWN?"
	NopMsg           = "NOP"
	ChunkedMsg       = "CHUNKED" // not a true bolt message
)

Variables

This section is empty.

Functions

func IntToBytes added in v0.4.0

func IntToBytes(i int) ([]byte, error)

Serialize an int to a byte slice

func ParseArray added in v0.4.0

func ParseArray(buf []byte) ([]interface{}, int, error)

Parse a byte slice into a TinyArray as an array of interface{} values, returning the array, the last position in the byte slice read, and optionally an error.

func ParseInt

func ParseInt(buf []byte) (int, int, error)

Parse a packed Int

func ParseMap added in v0.4.0

func ParseMap(buf []byte) (map[string]interface{}, int, error)

Try parsing some bytes into a Packstream Map, returning it as a map of strings to their values as byte arrays.

If not found or something horribly wrong, return nil and an error. Also, will panic on a nil input.

func ParseString

func ParseString(buf []byte) (string, int, error)

Parse a byte slice into a string, returning the string value, the last position used in the byte slice, and optionally an error

func ParseTinyInt

func ParseTinyInt(b byte) (int, error)

Parse a TinyInt...which is a simply 7-bit number.

func ParseTinyString

func ParseTinyString(buf []byte) (string, int, error)

Parse a TinyString from a byte slice, returning the string (if valid) and the number of bytes processed from the slice (including the 0x80 prefix).

Otherwise, return an empty string, 0, and an error.

func StringToBytes added in v0.4.0

func StringToBytes(s string) ([]byte, error)

Serialize a string to a byte slice

func TinyMapToBytes added in v0.4.0

func TinyMapToBytes(tinymap map[string]interface{}) ([]byte, error)

Serialize a TinyMap to a byte slice

func ValidateHandshake

func ValidateHandshake(client, server []byte) ([]byte, error)

Inspect client and server communication for valid Bolt handshake, returning the handshake value's bytes.

In order to pick the version, we use a simple formula of:

min( max(client versions), max(server versions) )

So if client_versions=[4.0, 3.5, 3.4] and server_versions=[4.2, 4.1, 4.0, 3.5] then min(max(4.0, 3.5, 3.4), max([4.2, 4.1, 4.0, 3.5])) ==>

min(4.0, 4.2) ==> 4.0!

Though, in reality, right now we already have the max(serverVersion) as the server []byte argument.

If the handshake is input bytes or handshake is invalid, returns an error and an empty byte array.

func ValidateMagic

func ValidateMagic(magic []byte) (bool, error)

Inspect bytes for valid Bolt Magic pattern, returning true if found. Otherwise, returns false with an error.

Types

type BoltConn

type BoltConn interface {
	R() <-chan *Message
	WriteMessage(*Message) error
	io.Closer
}

An abstraction of a Bolt-aware io.ReadWriterCloser. Allows for sending and receiving Messages, abstracting away the nuances of the transport.

R() should simply be a means of accessing the channel containining any available Messages. (Might rename this later.) They should be handled async by the conncetion instance.

WriteMessage() should synchronously try to write a Bolt Message to the connection.

type DirectConn

type DirectConn struct {
	// contains filtered or unexported fields
}

Designed for operating direct (e.g. TCP/IP-only) Bolt connections

func NewDirectConn

func NewDirectConn(c io.ReadWriteCloser) DirectConn

Create a new Direct Bolt Connection that uses simple Read/Write calls to transfer data.

Note: the buffer size of 1024*128 is based off some manual testing as it was found 1024*64 was not enough, for instance, as some messages larger than 64kb have been encountered.

func (DirectConn) Close

func (c DirectConn) Close() error

func (DirectConn) R

func (c DirectConn) R() <-chan *Message

func (DirectConn) String added in v0.2.0

func (c DirectConn) String() string

func (DirectConn) WriteMessage

func (c DirectConn) WriteMessage(m *Message) error

type Message

type Message struct {
	T    Type
	Data []byte
}

type Mode

type Mode string

Mode of a Bolt Transaction for determining cluster routing

const (
	ReadMode  Mode = "READ"
	WriteMode      = "WRITE"
)

func ValidateMode

func ValidateMode(buf []byte) (Mode, error)

Try to find and validate the Mode for some given bytes, returning the Mode if found or if valid looking Bolt chatter. Otherwise, returns nil and an error.

type Type

type Type string

func IdentifyType

func IdentifyType(buf []byte) Type

Try to extract the BoltMsg from some given bytes.

func TypeFromByte

func TypeFromByte(b byte) Type

Parse a byte into the corresponding Bolt message Type

type WsConn

type WsConn struct {
	// contains filtered or unexported fields
}

Used for WebSocket-based Bolt connections

func NewWsConn

func NewWsConn(c io.ReadWriteCloser) WsConn

func (WsConn) Close

func (c WsConn) Close() error

func (WsConn) R

func (c WsConn) R() <-chan *Message

func (WsConn) String added in v0.2.0

func (c WsConn) String() string

func (WsConn) WriteMessage

func (c WsConn) WriteMessage(m *Message) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL