iface

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package iface 生成 interface 的实例对象, 通过 fake iface 结果获得

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackUpTo

func BackUpTo(ctx *IContext, iface unsafe.Pointer)

BackUpTo 备份缓存 iface 指针到 IContext 中

func GenCallableMethod

func GenCallableMethod(ctx *IContext, apply interface{}, proxy PFunc) uintptr

GenCallableMethod 生成可以直接 CALL 的接口方法实现, 带上下文 (rdx)

func MakeInterface

func MakeInterface(ctx *IContext, funcTabIndex int, itabFunc uintptr, typ reflect.Type) *hack.Iface

MakeInterface 构造 interface 对象, 包含 receive、funcTab 等数据

func MakeMethodCaller

func MakeMethodCaller(to unsafe.Pointer) (uintptr, error)

MakeMethodCaller 构造 interface 的方法调用并放到 stub 区 to 桩函数跳转到的地址

func MakeMethodCallerWithCtx

func MakeMethodCallerWithCtx(ctx unsafe.Pointer, to uintptr) (uintptr, error)

MakeMethodCallerWithCtx 构造 interface 的方法调用并放到 stub 区 ctx make Func 对象的上下文地址,即 @see reflect.makeFuncImpl to 桩函数最终跳转到另一个地址

Types

type IContext

type IContext struct {
	// Data 可以传递任意数据
	Data interface{}
	// contains filtered or unexported fields
}

IContext 接口 Mock 代码函数的接收体 避免被 mock 的接口变量为 nil, 无法通过单测逻辑中 mock==nil 的判断

func NewContext

func NewContext() *IContext

NewContext 构造上下文

func (*IContext) Cache

func (c *IContext) Cache(key string, value *hack.Iface)

Cache 缓存数据

func (*IContext) Cached

func (c *IContext) Cached(key string) (v *hack.Iface, ok bool)

Cached 获取缓存数据

func (*IContext) Cancel

func (c *IContext) Cancel()

Cancel 取消接口代理

func (*IContext) Canceled

func (c *IContext) Canceled() bool

Canceled 是否已经被取消

type PContext

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

PContext 代理上下文 适配 proxy 包的 Context

type PFunc

type PFunc func(args []reflect.Value) (results []reflect.Value)

PFunc 代理函数类型的签名

Jump to

Keyboard shortcuts

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