connect

package
v0.0.0-...-f13fc7a Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RolePlatform = "platform"
	RoleHost     = "host"
	RoleHostBoot = "host_boot"
)
View Source
const (
	SocketTypeRouter = "router"
	SocketTypeDealer = "dealer"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallBack

type CallBack func(input, result *protocol.PlatformMessage, err common_type.PluginError)

type Connection

type Connection struct {
	Zmq *ZmqEndpoint
	ConnectionHandler
	// contains filtered or unexported fields
}

Connection 改造了 MessageHandler 中的核心函数 OnMessage, 并且为 send 函数添加了同异步发送, 超时功能。 其余函数委托给 ConnectionHandler 实现。

func NewConnection

func NewConnection(zmq *ZmqEndpoint, handler ConnectionHandler) *Connection

func (*Connection) Connect

func (c *Connection) Connect() common_type.PluginError

func (*Connection) GetZmq

func (c *Connection) GetZmq() *ZmqEndpoint

func (*Connection) OnMessage

func (c *Connection) OnMessage(endpoint *EndpointInfo, content []byte)

func (*Connection) Send

Send 同步发送

func (*Connection) SendAsync

func (c *Connection) SendAsync(msg *protocol.PlatformMessage, timeout time.Duration, callback CallBack)

SendAsync 异步发送

func (*Connection) SendOnly

type ConnectionHandler

type ConnectionHandler interface {
	OnConnect() common_type.PluginError
	OnDisconnect() common_type.PluginError
	OnMsg(endpoint *EndpointInfo, content *protocol.PlatformMessage, unmarshalError common_type.PluginError)
	OnError(pluginError common_type.PluginError)
}

type EndpointInfo

type EndpointInfo struct {
	ID   string
	Role Role
	Name string
}

type MessageHandler

type MessageHandler interface {
	OnConnect() common_type.PluginError
	OnDisconnect() common_type.PluginError
	OnMessage(endpoint *EndpointInfo, content []byte)
	OnError(pluginError common_type.PluginError) // EndpointReceiveErr、EndpointIdentifyErr、EndpointSendErr only
}

type MessagePacker

type MessagePacker interface {
	// Unpack 从rawData中剥离出发送端和接收端,返回processedData
	Unpack(rawData []byte) (source, target *EndpointInfo, processedData []byte, err common_type.PluginError)
	// Pack 给出发送端和接收端,为rawData加上发送端和接收端信息,生成新的发送内容
	Pack(source, target *EndpointInfo, rawData []byte) (processedData []byte, err common_type.PluginError)
}

MessagePacker 规定在ZmqEndpoint传输的数据中必须包含元数据(即:发送端和接收端的相关信息),使用 MessagePacker 将其组装或分离

type ProtoPacker

type ProtoPacker struct{}

func (*ProtoPacker) Pack

func (i *ProtoPacker) Pack(source, target *EndpointInfo, data []byte) ([]byte, common_type.PluginError)

func (*ProtoPacker) Unpack

type Role

type Role string

type SocketType

type SocketType string

type ZmqEndpoint

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

func NewZmq

func NewZmq(id, name, addr string, socketType SocketType, role Role) *ZmqEndpoint

func (*ZmqEndpoint) AddEndpoint

func (p *ZmqEndpoint) AddEndpoint(ep *EndpointInfo)

func (*ZmqEndpoint) Close

func (p *ZmqEndpoint) Close() error

func (*ZmqEndpoint) Connect

func (p *ZmqEndpoint) Connect() common_type.PluginError

func (*ZmqEndpoint) DeleteEndpoint

func (p *ZmqEndpoint) DeleteEndpoint(id string)

func (*ZmqEndpoint) ExistEndpoint

func (p *ZmqEndpoint) ExistEndpoint(id string) bool

func (*ZmqEndpoint) GetEndpoint

func (p *ZmqEndpoint) GetEndpoint(id string) (*EndpointInfo, bool)

func (*ZmqEndpoint) ListEndpoints

func (p *ZmqEndpoint) ListEndpoints() []*EndpointInfo

func (*ZmqEndpoint) Publish

func (p *ZmqEndpoint) Publish(rawData []byte) common_type.PluginError

func (*ZmqEndpoint) Send

func (p *ZmqEndpoint) Send(rawData []byte) common_type.PluginError

func (*ZmqEndpoint) SendTo

func (p *ZmqEndpoint) SendTo(id string, content []byte) common_type.PluginError

func (*ZmqEndpoint) SetHandler

func (p *ZmqEndpoint) SetHandler(h MessageHandler) *ZmqEndpoint

func (*ZmqEndpoint) SetPacker

func (p *ZmqEndpoint) SetPacker(packer MessagePacker) *ZmqEndpoint

Jump to

Keyboard shortcuts

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