prpc

package module
v0.0.0-...-2cb1332 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

README

prpc

prpc 是一个基于protobuf的双向调用rpc,server也可以向已连接的客户端发起主动调用。 支持 Call() 同步调用, Go() 异步调用, Notify() 通知,不关心返回值。此项目来源于一个IM项目。客户端可以通过同一条连接发起请求,服务端也可以反向向客户端发起调用(推送消息并获取回执,通知客户端断开连接等)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShutdown = errors.New("connection is shut down")

Functions

This section is empty.

Types

type Call

type Call struct {
	ServiceMethod string      // The name of the service and method to call.
	Args          interface{} // The argument to the function (*struct).
	Reply         interface{} // The reply from the function (*struct).
	Error         error       // After completion, the error status.
	Done          chan *Call  // Strobes when call is complete.
	IsNotify      bool
}

type CallManager

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

func NewCallManager

func NewCallManager(codec Codec) *CallManager

func (*CallManager) Call

func (client *CallManager) Call(serviceMethod string, args interface{}, reply interface{}) error

func (*CallManager) Go

func (client *CallManager) Go(serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call

func (*CallManager) Notify

func (client *CallManager) Notify(serviceMethod string, args interface{}, reply interface{}) error

type Client

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

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

func NewClientWithCodec

func NewClientWithCodec(codec Codec) *Client

func (*Client) Loop

func (client *Client) Loop() (err error)

func (*Client) SetServer

func (client *Client) SetServer(server *ServiceManager)

type Codec

type Codec interface {
	Write(*Header, interface{}) error
	ReadHeader(*Header) error
	ReadBody(interface{}) error

	Close() error
}

func NewProtobufCodec

func NewProtobufCodec(rwc io.ReadWriteCloser) Codec

type DecodeReader

type DecodeReader interface {
	io.ByteReader
	io.Reader
}

type Decoder

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

A Decoder manages the receipt of type and data information read from the remote side of a connection.

func NewDecoder

func NewDecoder(r DecodeReader) *Decoder

NewDecoder returns a new decoder that reads from the io.Reader.

func (*Decoder) Decode

func (d *Decoder) Decode(m proto.Message) (err error)

type Encoder

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

An Encoder manages the transmission of type and data information to the other side of a connection.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that will transmit on the io.Writer.

func (*Encoder) Encode

func (e *Encoder) Encode(m proto.Message) (err error)

Encode transmits the data item represented by the empty interface value, guaranteeing that all necessary type information has been transmitted first.

type Header struct {
	IsResp        bool
	ServiceMethod string
	Seq           uint64
	Error         string
	// contains filtered or unexported fields
}

type ServerError

type ServerError string

func (ServerError) Error

func (e ServerError) Error() string

type ServiceManager

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

func NewServiceManager

func NewServiceManager() *ServiceManager

func (*ServiceManager) Register

func (server *ServiceManager) Register(rcvr interface{}) error

func (*ServiceManager) RegisterName

func (server *ServiceManager) RegisterName(name string, rcvr interface{}) error

Directories

Path Synopsis
proto
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.
Package pb is a generated protocol buffer package.
Package pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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