duplex

package
v0.0.0-...-d076a97 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version         = "0.1.0"
	ProtocolName    = "SIMPLEX"
	ProtocolVersion = "1.0"
	TypeRequest     = "req"
	TypeReply       = "rep"
	HandshakeAccept = "+OK"
	BacklogSize     = 1024
	MaxFrameSize    = 1 << 20 // 1mb
)

Functions

This section is empty.

Types

type Channel

type Channel struct {
	*Peer
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel(peer *Peer, typ string, method string) *Channel

func (*Channel) Context

func (ch *Channel) Context() context.Context

func (*Channel) Recv

func (ch *Channel) Recv(obj interface{}) (bool, error)

func (*Channel) Send

func (ch *Channel) Send(obj interface{}, more bool) error

func (*Channel) SendErr

func (ch *Channel) SendErr(code int, message string, data interface{}) error

func (*Channel) SendLast

func (ch *Channel) SendLast(obj interface{}) error

not convenient enough? we'll see

func (*Channel) SetExt

func (ch *Channel) SetExt(ext interface{})

type Codec

type Codec struct {
	Name   string
	Encode func(obj interface{}) ([]byte, error)
	Decode func(frame []byte, obj interface{}) error
}

func NewJSONCodec

func NewJSONCodec() *Codec

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

func (Error) Error

func (err Error) Error() string

type Message

type Message struct {
	Type    string      `json:"type"`
	Method  string      `json:"method,omitempty"`
	Payload interface{} `json:"payload,omitempty"`
	Error   *Error      `json:"error,omitempty"`
	Id      int         `json:"id,omitempty"`
	More    bool        `json:"more,omitempty"`
	Ext     interface{} `json:"ext,omitempty"`
}

type Peer

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

func NewPeer

func NewPeer(rpc *RPC, conn io.ReadWriteCloser, ctx context.Context) *Peer

func (*Peer) Call

func (peer *Peer) Call(method string, args interface{}, reply interface{}) error

func (*Peer) Close

func (peer *Peer) Close() error

func (*Peer) CloseNotify

func (peer *Peer) CloseNotify() <-chan bool

func (*Peer) Open

func (peer *Peer) Open(service string) *Channel

type RPC

type RPC struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRPC

func NewRPC(codec *Codec) *RPC

func (*RPC) Accept

func (rpc *RPC) Accept(conn io.ReadWriteCloser) (*Peer, error)

func (*RPC) AcceptWith

func (rpc *RPC) AcceptWith(conn io.ReadWriteCloser, ctx context.Context) (*Peer, error)

func (*RPC) CallbackFunc

func (rpc *RPC) CallbackFunc(fn func(interface{}, *Channel) (interface{}, error)) string

func (*RPC) Handshake

func (rpc *RPC) Handshake(conn io.ReadWriteCloser) (*Peer, error)

func (*RPC) Register

func (rpc *RPC) Register(name string, handler func(*Channel) error)

func (*RPC) RegisterFunc

func (rpc *RPC) RegisterFunc(name string, fn func(interface{}, *Channel) (interface{}, error))

func (*RPC) Unregister

func (rpc *RPC) Unregister(name string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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