Documentation ¶
Index ¶
- Constants
- type CallBack
- type Connection
- func (c *Connection) Connect() common_type.PluginError
- func (c *Connection) GetZmq() *ZmqEndpoint
- func (c *Connection) OnMessage(endpoint *EndpointInfo, content []byte)
- func (c *Connection) Send(msg *protocol.PlatformMessage, timeout time.Duration) (result *protocol.PlatformMessage, err common_type.PluginError)
- func (c *Connection) SendAsync(msg *protocol.PlatformMessage, timeout time.Duration, callback CallBack)
- func (c *Connection) SendOnly(msg *protocol.PlatformMessage) common_type.PluginError
- type ConnectionHandler
- type EndpointInfo
- type MessageHandler
- type MessagePacker
- type ProtoPacker
- type Role
- type SocketType
- type ZmqEndpoint
- func (p *ZmqEndpoint) AddEndpoint(ep *EndpointInfo)
- func (p *ZmqEndpoint) Close() error
- func (p *ZmqEndpoint) Connect() common_type.PluginError
- func (p *ZmqEndpoint) DeleteEndpoint(id string)
- func (p *ZmqEndpoint) ExistEndpoint(id string) bool
- func (p *ZmqEndpoint) GetEndpoint(id string) (*EndpointInfo, bool)
- func (p *ZmqEndpoint) ListEndpoints() []*EndpointInfo
- func (p *ZmqEndpoint) Publish(rawData []byte) common_type.PluginError
- func (p *ZmqEndpoint) Send(rawData []byte) common_type.PluginError
- func (p *ZmqEndpoint) SendTo(id string, content []byte) common_type.PluginError
- func (p *ZmqEndpoint) SetHandler(h MessageHandler) *ZmqEndpoint
- func (p *ZmqEndpoint) SetPacker(packer MessagePacker) *ZmqEndpoint
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 ¶
func (c *Connection) Send(msg *protocol.PlatformMessage, timeout time.Duration) ( result *protocol.PlatformMessage, err common_type.PluginError)
Send 同步发送
func (*Connection) SendAsync ¶
func (c *Connection) SendAsync(msg *protocol.PlatformMessage, timeout time.Duration, callback CallBack)
SendAsync 异步发送
func (*Connection) SendOnly ¶
func (c *Connection) SendOnly(msg *protocol.PlatformMessage) common_type.PluginError
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 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 ¶
func (i *ProtoPacker) Unpack(data []byte) (*EndpointInfo, *EndpointInfo, []byte, common_type.PluginError)
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
Click to show internal directories.
Click to hide internal directories.