goentangle

package module
v0.0.0-...-d24cd1f Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

README

goentangle - Entangle runtime library for Go
============================================

.. image:: https://travis-ci.org/entangle/goentangle.png?branch=master
   :target: https://travis-ci.org/entangle/goentangle

Documentation

Overview

Package goentangle provides the Entangle runtime library for Go.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMessageData   = errors.New("invalid message data received")
	ErrInvalidMessageOpcode = errors.New("invalid message opcode received")
	ErrInvalidMessageId     = errors.New("invalid message ID received")
	ErrBadMessage           = errors.New("bad message received")
)
View Source
var (
	// Bad message error definition.
	BadMessageError = NewExceptionDefinition("entangle", "BadMessage")

	// Internal server error.
	InternalServerError = NewExceptionDefinition("entangle", "InternalServerError")

	// Unknown method.
	UnknownMethodError = NewExceptionDefinition("entangle", "UnknownMethod")

	// Unknown exception.
	UnknownExceptionError = NewExceptionDefinition("entangle", "UnknownException")
)
View Source
var (
	ErrDeserializationError = errors.New("deserialization error")
)
View Source
var ErrShutdown = errors.New("connection is shut down")

Client connection is shut down.

Functions

func DeserializeBinary

func DeserializeBinary(input interface{}) ([]byte, error)

Deserialize a binary.

Returns ErrDeserializationError if deserialization failed.

func DeserializeBool

func DeserializeBool(input interface{}) (bool, error)

Deserialize a boolean.

Returns ErrDeserializationError if deserialization failed.

func DeserializeFloat32

func DeserializeFloat32(input interface{}) (float32, error)

Deserialize a 32-bit floating point number.

Returns ErrDeserializationError if deserialization failed.

func DeserializeFloat64

func DeserializeFloat64(input interface{}) (float64, error)

Deserialize a 64-bit floating point number.

Returns ErrDeserializationError if deserialization failed.

func DeserializeInt16

func DeserializeInt16(input interface{}) (int16, error)

Deserialize a signed 16-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeInt32

func DeserializeInt32(input interface{}) (int32, error)

Deserialize a signed 32-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeInt64

func DeserializeInt64(input interface{}) (int64, error)

Deserialize a signed 64-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeInt8

func DeserializeInt8(input interface{}) (int8, error)

Deserialize a signed 8-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeString

func DeserializeString(input interface{}) (string, error)

Deserialize a string.

Returns ErrDeserializationError if deserialization failed.

func DeserializeUint16

func DeserializeUint16(input interface{}) (uint16, error)

Deserialize an unsigned 16-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeUint32

func DeserializeUint32(input interface{}) (uint32, error)

Deserialize an unsigned 32-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeUint64

func DeserializeUint64(input interface{}) (uint64, error)

Deserialize an unsigned 64-bit integer.

Returns ErrDeserializationError if deserialization failed.

func DeserializeUint8

func DeserializeUint8(input interface{}) (uint8, error)

Deserialize an unsigned 8-bit integer.

Returns ErrDeserializationError if deserialization failed.

Types

type ClientConnHandler

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

Client connection handler.

Convenience type for handling requests and responses for clients.

func NewClientConnHandler

func NewClientConnHandler(conn *Conn) (h *ClientConnHandler)

New client connection handler.

func (*ClientConnHandler) Call

func (h *ClientConnHandler) Call(method string, args []interface{}, notify bool, trace bool) (resp Message, err error)

Call a remote function.

func (*ClientConnHandler) Close

func (h *ClientConnHandler) Close() error

Close the connection.

type CompressionMethod

type CompressionMethod uint8

Compression method.

const (
	// Snappy.
	SnappyCompression CompressionMethod = iota
)

Compression methods.

func DeserializeCompressionMethod

func DeserializeCompressionMethod(input interface{}) (m CompressionMethod, ok bool)

Deserialize a compression method.

func (CompressionMethod) Compress

func (m CompressionMethod) Compress(input []byte) (output []byte, err error)

Compress.

func (CompressionMethod) Decompress

func (m CompressionMethod) Decompress(input []byte) (output []byte, err error)

Decompress.

func (CompressionMethod) String

func (m CompressionMethod) String() string

func (CompressionMethod) Valid

func (m CompressionMethod) Valid() bool

Test if a compression method is valid.

type Conn

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

Connection.

Reading is only safe from one goroutine while writing is safe in a blocking manner form any number of goroutines.

func NewConn

func NewConn(conn io.ReadWriteCloser, description string) *Conn

New connection.

func (*Conn) AcknowledgeNotification

func (c *Conn) AcknowledgeNotification(responseTo Message) error

Acknowledge a notification.

func (*Conn) Close

func (c *Conn) Close()

Close connection.

func (*Conn) Description

func (c *Conn) Description() string

Description.

func (*Conn) RaiseException

func (c *Conn) RaiseException(exception error, responseTo Message, trace Trace) error

Raise an exception.

func (*Conn) Receive

func (c *Conn) Receive() (msg Message, err error)

Receive a message.

The returned error can be either io.EOF, ErrInvalidMessageData, ErrInvalidMessageOpcode or ErrInvalidMessageId, all of which are unrecoverable, or ErrBadMessage which doesn't prohibit the connection from continuing.

func (*Conn) Respond

func (c *Conn) Respond(result interface{}, responseTo Message, trace Trace) error

Send a response.

func (*Conn) SendNotification

func (c *Conn) SendNotification(method string, arguments []interface{}) (MessageId, error)

Send a notification.

func (*Conn) SendRequest

func (c *Conn) SendRequest(method string, arguments []interface{}, trace bool) (MessageId, error)

Send a request.

type Exception

type Exception interface {
	error

	// Definition.
	Definition() string

	// Name.
	Name() string
}

Entangle exception.

type ExceptionDefinition

type ExceptionDefinition interface {
	// New error.
	New(description string) Exception

	// New formatted error.
	//
	// Behaves like fmt.Printf.
	Newf(format string, a ...interface{}) Exception
}

Entangle exception definition.

Exception definition that can produce an exception of a specific type.

func NewExceptionDefinition

func NewExceptionDefinition(definition, name string) ExceptionDefinition

New error definition.

type ExceptionMessage

type ExceptionMessage struct {

	// Definition.
	Definition string

	// Name.
	Name string

	// Description.
	Description string

	// Trace.
	Trace Trace
	// contains filtered or unexported fields
}

Exception message.

func (*ExceptionMessage) MessageId

func (m *ExceptionMessage) MessageId() MessageId

func (*ExceptionMessage) Serialize

func (m *ExceptionMessage) Serialize() []interface{}

type Message

type Message interface {
	// Message ID.
	MessageId() MessageId

	// Serialize the message.
	Serialize() []interface{}
}

Message.

type MessageId

type MessageId uint32

Message ID.

func ParseMessageId

func ParseMessageId(input interface{}) (id MessageId, ok bool)

Parse a message ID.

type NotificationAcknowledgementMessage

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

Notification acknowledgement message.

func (*NotificationAcknowledgementMessage) MessageId

func (*NotificationAcknowledgementMessage) Serialize

func (m *NotificationAcknowledgementMessage) Serialize() []interface{}

type NotificationMessage

type NotificationMessage struct {

	// Method.
	Method string

	// Arguments.
	Arguments []interface{}
	// contains filtered or unexported fields
}

Notification message.

func (*NotificationMessage) MessageId

func (m *NotificationMessage) MessageId() MessageId

func (*NotificationMessage) Serialize

func (m *NotificationMessage) Serialize() []interface{}

type Opcode

type Opcode uint8

Opcode.

const (
	// Request opcode.
	RequestOpcode Opcode = iota

	// Notification opcode.
	NotificationOpcode

	// Response opcode.
	ResponseOpcode

	// Exception opcode.
	ExceptionOpcode

	// Notification acknowledgement opcode.
	NotificationAcknowledgementOpcode

	// Compressed message opcode.
	CompressedMessageOpcode = 0x7f
)

Opcodes.

func ParseOpcode

func ParseOpcode(input interface{}) (o Opcode, ok bool)

Parse an opcode.

func (Opcode) String

func (o Opcode) String() string

func (Opcode) Valid

func (o Opcode) Valid() bool

Test if an opcode is valid.

type RequestMessage

type RequestMessage struct {

	// Method.
	Method string

	// Arguments.
	Arguments []interface{}

	// Trace.
	Trace bool
	// contains filtered or unexported fields
}

Request message.

func (*RequestMessage) MessageId

func (m *RequestMessage) MessageId() MessageId

func (*RequestMessage) Serialize

func (m *RequestMessage) Serialize() []interface{}

type ResponseMessage

type ResponseMessage struct {

	// Result.
	Result interface{}

	// Trace.
	Trace Trace
	// contains filtered or unexported fields
}

Response message.

func (*ResponseMessage) MessageId

func (m *ResponseMessage) MessageId() MessageId

func (*ResponseMessage) Serialize

func (m *ResponseMessage) Serialize() []interface{}

type Server

type Server interface {
	// Accept accepts connections on the listener and serves requests for each
	// incoming connection.
	//
	// Accept blocks; the caller typically invokes it in a go statement.
	Accept(l net.Listener) error

	// Serve connections until the listener is closed.
	Serve(l net.Listener) error

	// ServeConn runs the server on a single connection.
	//
	// ServeConn blocks, serving the connection until the client hangs up. The
	// caller typically invokes ServeConn in a go statement.
	ServeConn(conn *Conn)

	// Wait for all connections to finish.
	//
	// Only valid when using Serve.
	Wait()
}

Server.

type Trace

type Trace interface {
	// Description.
	Description() string

	// Begin tracing.
	//
	// Returns a sub-trace.
	Begin(description string) Trace

	// End the trace.
	End()

	// Sub-traces.
	SubTraces() []Trace

	// Serialize.
	Serialize() interface{}
}

Trace.

func DeserializeTrace

func DeserializeTrace(ser interface{}) (t Trace, err error)

Deserialize trace.

func NewTrace

func NewTrace(description string) Trace

New trace.

Jump to

Keyboard shortcuts

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