coolmsg

package module
v0.0.0-...-0bde82d Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// From spec
	TYPE_ERR = 0x81aba3f7522edc6b
	// From spec
	TYPE_OK = 0xd4924862b91c639d
	// From spec
	TYPE_CLUNK = 0xcf3a50d623ee637d
	// From spec
	TYPE_OBJECT_REF = 0xd782cf4b395eca05

	// From spec
	ERRCODE_OBJECT_NOT_EXIST = 0xab0547366de885bc
	// From spec
	ERRCODE_UNEXPECTED_MESSAGE = 0xd47d4e94917934b2
	ERRCODE_GENERIC            = 0

	RESERVED_OBJECT_ID  = 0
	BOOTSTRAP_OBJECT_ID = 1
)

Variables

View Source
var (
	ErrBadResponse        = errors.New("bad response.")
	ErrPayloadTooBig      = errors.New("payload too big.")
	ErrRequestCancelled   = errors.New("request cancelled.")
	ErrClientShutdown     = errors.New("client has been shutdown.")
	ErrObjectDoesNotExist = &Error{Code: ERRCODE_OBJECT_NOT_EXIST, Display: "object does not exist."}
	ErrUnexpectedMessage  = &Error{Code: ERRCODE_UNEXPECTED_MESSAGE, Display: "unexpected message."}
)

Functions

func JsonMarshal

func JsonMarshal(v interface{}) []byte

func JsonUnmarshal

func JsonUnmarshal(buf []byte, v interface{}) bool

func MsgpackMarshal

func MsgpackMarshal(v interface{}) []byte

func MsgpackMarshalAsArray

func MsgpackMarshalAsArray(v interface{}) []byte

func MsgpackUnmarshal

func MsgpackUnmarshal(buf []byte, v interface{}) bool

func RegisterError

func RegisterError(code uint64, mk func(e *Error) error)

func RegisterMessage

func RegisterMessage(id uint64, mk func() Message)

func RegisterStandardMessagesAndErrors

func RegisterStandardMessagesAndErrors(reg *Registry)

func WriteRequest

func WriteRequest(w io.Writer, req Request) error

func WriteResponse

func WriteResponse(w io.Writer, resp Response) error

Types

type Client

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

func NewClient

func NewClient(conn io.ReadWriteCloser, options ClientOptions) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) RawSend

func (c *Client) RawSend(oid uint64, paramType uint64, paramData []byte) (Response, error)

func (*Client) RawSendCtx

func (c *Client) RawSendCtx(ctx context.Context, oid uint64, paramType uint64, paramData []byte) (Response, error)

func (*Client) RawSendParsedReply

func (c *Client) RawSendParsedReply(reg *Registry, oid uint64, paramType uint64, paramData []byte) (interface{}, error)

func (*Client) RawSendParsedReplyCtx

func (c *Client) RawSendParsedReplyCtx(ctx context.Context, reg *Registry, oid uint64, paramType uint64, paramData []byte) (interface{}, error)

func (*Client) Send

func (c *Client) Send(oid uint64, arg Message) (interface{}, error)

func (*Client) SendCtx

func (c *Client) SendCtx(ctx context.Context, oid uint64, arg Message) (interface{}, error)

func (*Client) SendWithReg

func (c *Client) SendWithReg(reg *Registry, oid uint64, arg Message) (interface{}, error)

func (*Client) SendWithRegCtx

func (c *Client) SendWithRegCtx(ctx context.Context, reg *Registry, oid uint64, arg Message) (interface{}, error)

type ClientOptions

type ClientOptions struct {
	MaxResponseSize uint64
	// If nil, defaults to DefaultRegistry
	Registry *Registry
}

type Clunk

type Clunk struct{}

func (*Clunk) CoolMsg_Marshal

func (m *Clunk) CoolMsg_Marshal() []byte

func (*Clunk) CoolMsg_TypeId

func (m *Clunk) CoolMsg_TypeId() uint64

func (*Clunk) CoolMsg_Unmarshal

func (m *Clunk) CoolMsg_Unmarshal(buf []byte) bool

type ConnServer

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

func NewConnServer

func NewConnServer(c io.ReadWriteCloser, options ConnServerOptions) *ConnServer

func (*ConnServer) Clunk

func (s *ConnServer) Clunk(oid uint64)

func (*ConnServer) Go

func (s *ConnServer) Go(f func())

func (*ConnServer) HandleRequest

func (s *ConnServer) HandleRequest(ctx context.Context, r Request, respond RespondFunc)

func (*ConnServer) Register

func (s *ConnServer) Register(o Object) uint64

func (*ConnServer) RegisterBootstrap

func (s *ConnServer) RegisterBootstrap(o Object)

func (*ConnServer) Serve

func (s *ConnServer) Serve(ctx context.Context, c io.ReadWriteCloser)

func (*ConnServer) Wait

func (s *ConnServer) Wait()

type ConnServerOptions

type ConnServerOptions struct {
	MaxRequestSize uint64
	// Each connection will stop reading new
	// requests if this is exceeded, zero
	// means unlimited.
	MaxOutstandingRequests uint64
	// This function is used to create the root object
	// a client can send messages to.
	//
	// It takes a connection object as a way for out of band connection
	// information to be used while creating the root object.
	// One example is using a unix socket to get the remote user id,
	// and then using that for authentication.
	BootstrapFunc func(io.ReadWriteCloser) Object
	// If nil, defaults to DefaultRegistry
	Registry *Registry
}

type Error

type Error struct {
	Code    uint64
	Display string
	Debug   string
}

Fields must remain compatible. with spec, Order is significant as Error is marshaled as an array.

func (*Error) CoolMsg_Marshal

func (m *Error) CoolMsg_Marshal() []byte

func (*Error) CoolMsg_TypeId

func (m *Error) CoolMsg_TypeId() uint64

func (*Error) CoolMsg_Unmarshal

func (m *Error) CoolMsg_Unmarshal(buf []byte) bool

func (*Error) Error

func (m *Error) Error() string

type Message

type Message interface {
	CoolMsg_TypeId() uint64
	CoolMsg_Marshal() []byte
	// The buffer is guaranteed to be read only.
	// This means zero copy references into the
	// buffer are okay (and encouraged).
	CoolMsg_Unmarshal([]byte) bool
}

type Object

type Object interface {
	Message(context.Context, *ConnServer, Message, RespondFunc)
	UnknownMessage(context.Context, *ConnServer, uint64, []byte, RespondFunc)
	Clunk(*ConnServer)
}

type ObjectRef

type ObjectRef struct {
	Id uint64
}

func (*ObjectRef) CoolMsg_Marshal

func (m *ObjectRef) CoolMsg_Marshal() []byte

func (*ObjectRef) CoolMsg_TypeId

func (m *ObjectRef) CoolMsg_TypeId() uint64

func (*ObjectRef) CoolMsg_Unmarshal

func (m *ObjectRef) CoolMsg_Unmarshal(buf []byte) bool

type Ok

type Ok struct{}

func (*Ok) CoolMsg_Marshal

func (m *Ok) CoolMsg_Marshal() []byte

func (*Ok) CoolMsg_TypeId

func (m *Ok) CoolMsg_TypeId() uint64

func (*Ok) CoolMsg_Unmarshal

func (m *Ok) CoolMsg_Unmarshal(buf []byte) bool

type Registry

type Registry struct {
	// contains filtered or unexported fields
}
var DefaultRegistry *Registry

func NewRegistry

func NewRegistry() *Registry

func (*Registry) MakeError

func (reg *Registry) MakeError(e *Error) error

func (*Registry) RegisterError

func (reg *Registry) RegisterError(code uint64, mk func(e *Error) error)

func (*Registry) RegisterMessage

func (reg *Registry) RegisterMessage(id uint64, mk func() Message)

func (*Registry) Unmarshal

func (reg *Registry) Unmarshal(id uint64, data []byte) (Message, bool)

type Request

type Request struct {
	RequestId   uint64
	ObjectId    uint64
	MessageType uint64
	// Modifying this buffer is an error.
	MessageData []byte
}

func ReadRequest

func ReadRequest(r io.Reader, maxRequestSize uint64) (Request, error)

type RespondFunc

type RespondFunc func(Message)

type Response

type Response struct {
	RequestId    uint64
	ResponseType uint64
	// Modifying this buffer is an error.
	ResponseData []byte
}

func ReadResponse

func ReadResponse(r io.Reader, maxResponseSize uint64) (Response, error)

type Server

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

func NewServer

func NewServer(options ServerOptions) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) GoHandle

func (s *Server) GoHandle(c io.ReadWriteCloser)

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

func (*Server) Wait

func (s *Server) Wait()

type ServerOptions

type ServerOptions struct {
	ConnOptions ConnServerOptions
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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