rocutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package rocutil roc对象构造及调用的简单使用工具,基于反射实现,性能敏感处不宜使用。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsNotFunc      = errors.New("target funcname isn't func")
	ErrUnknownFunc    = errors.New("unknown function name")
	ErrArgNumMismatch = errors.New("call arg num mismatch")
)

错误定义

Functions

func CallNR

func CallNR(rocServer roc.IROCServer, typ roc.ObjType, objID string,
	funcName string, args ...interface{}) error

CallNR call remote object function 调用一个由 rocutil 创建的ROC对象,由于该调用会将参数编码,所以对端的参数解码也 必须由 rocutil 实现。

func NewROCObj

func NewROCObj(obj interface{}, rocObjType roc.ObjType,
	rocObjID string, ops ...*options.Options) (roc.IObj, error)

NewROCObj 基于源对象构造一个 ROC Util 对象,该对象的远程调用必须使用 rocutil.CallNR 调用, 本质上,是实例化出一个源对象的代理,由该代理实现 roc.IObj 接口,然后返回该代理, 这简化了源对象的构造,并且通过反射来将源对象中具有的方法映射到ROC调用的路径中, 使得源对象的 OnROCCall 方法也省略了。

func ServerROCObj

func ServerROCObj(rocserver roc.IROCServer, obj interface{},
	rocObjType roc.ObjType, rocObjID string,
	opts ...*options.Options) (roc.IObj, error)

ServerROCObj 服务一个对象,并且将该对象注册到 源对象的 roc.IObj 接口由 NewROCObj 实现, 实际注册到ROC系统中的是代理对象,如果目标类型的ROC没被创建则自动创建。

Types

type CallArg

type CallArg [][]byte

CallArg ROC调用的参数列表

func (*CallArg) Add

func (arg *CallArg) Add(data []byte)

Add 增加一个调用参数

func (*CallArg) Len

func (arg *CallArg) Len() int

Len 调用参数的数量

type Method

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

Method 代理对象的方法

func (*Method) Call

func (method *Method) Call(data *CallArg) ([]reflect.Value, error)

Call 提供编码好的参数二进制流,调用该方法

func (*Method) GetArgValues

func (method *Method) GetArgValues(data *CallArg) ([]reflect.Value, error)

GetArgValues 根据远程调用发来的参数,将信息解码为当前方法的参数列表,提供给外层反射调用。

func (*Method) GetName

func (method *Method) GetName() string

GetName 获取当前方法的名字。

func (*Method) Init

func (method *Method) Init(name string, f reflect.Value) error

Init 初始化一个方法

type ROCObjAgent

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

ROCObjAgent ROC对象代理,由 rocutil 创建的ROC对象均由代理来实现roc对象需要的接口, 同时实现通过代理对象具有的函数,自动编解码参数列表,实现更为简单的ROC调用。

func (*ROCObjAgent) GetROCObjID

func (agent *ROCObjAgent) GetROCObjID() string

GetROCObjID 提供给 roc.Server 的接口,获取ROC对象的ID

func (*ROCObjAgent) GetROCObjType

func (agent *ROCObjAgent) GetROCObjType() roc.ObjType

GetROCObjType 提供给 roc.Server 的接口,获取ROC对象的类型

func (*ROCObjAgent) Init

func (agent *ROCObjAgent) Init(obj interface{}, rocObjType roc.ObjType,
	rocObjID string, ops []*options.Options) error

Init 初始化该代理,目标对象不需要实现任何接口,但是需要告知目标对象的类型和ID,以便 代理提供ROC对象的接口给ROC系统。

func (*ROCObjAgent) OnROCCall

func (agent *ROCObjAgent) OnROCCall(path *roc.Path, arg []byte) ([]byte, error)

OnROCCall 提供给 roc.Server 的接口,受到ROC调用时调用

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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