mirror of
https://github.com/luxfi/zmq.git
synced 2026-10-30 15:11:11 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
// Copyright 2018 The go-zeromq Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package zmq4
|
|
|
|
// SocketType is a ZeroMQ socket type.
|
|
type SocketType string
|
|
|
|
const (
|
|
Pair SocketType = "PAIR" // a ZMQ_PAIR socket
|
|
Pub SocketType = "PUB" // a ZMQ_PUB socket
|
|
Sub SocketType = "SUB" // a ZMQ_SUB socket
|
|
Req SocketType = "REQ" // a ZMQ_REQ socket
|
|
Rep SocketType = "REP" // a ZMQ_REP socket
|
|
Dealer SocketType = "DEALER" // a ZMQ_DEALER socket
|
|
Router SocketType = "ROUTER" // a ZMQ_ROUTER socket
|
|
Pull SocketType = "PULL" // a ZMQ_PULL socket
|
|
Push SocketType = "PUSH" // a ZMQ_PUSH socket
|
|
XPub SocketType = "XPUB" // a ZMQ_XPUB socket
|
|
XSub SocketType = "XSUB" // a ZMQ_XSUB socket
|
|
Stream SocketType = "STREAM" // a ZMQ_STREAM socket
|
|
)
|
|
|
|
// IsCompatible checks whether two sockets are compatible and thus
|
|
// can be connected together.
|
|
// See https://rfc.zeromq.org/spec:23/ZMTP/ for more informations.
|
|
func (sck SocketType) IsCompatible(peer SocketType) bool {
|
|
switch sck {
|
|
case Pair:
|
|
if peer == Pair {
|
|
return true
|
|
}
|
|
case Pub:
|
|
switch peer {
|
|
case Sub, XSub:
|
|
return true
|
|
}
|
|
case Sub:
|
|
switch peer {
|
|
case Pub, XPub:
|
|
return true
|
|
}
|
|
case Req:
|
|
switch peer {
|
|
case Rep, Router:
|
|
return true
|
|
}
|
|
case Rep:
|
|
switch peer {
|
|
case Req, Dealer:
|
|
return true
|
|
}
|
|
case Dealer:
|
|
switch peer {
|
|
case Rep, Dealer, Router:
|
|
return true
|
|
}
|
|
case Router:
|
|
switch peer {
|
|
case Req, Dealer, Router:
|
|
return true
|
|
}
|
|
case Pull:
|
|
switch peer {
|
|
case Push:
|
|
return true
|
|
}
|
|
case Push:
|
|
switch peer {
|
|
case Pull:
|
|
return true
|
|
}
|
|
case XPub:
|
|
switch peer {
|
|
case Sub, XSub:
|
|
return true
|
|
}
|
|
case XSub:
|
|
switch peer {
|
|
case Pub, XPub:
|
|
return true
|
|
}
|
|
case Stream:
|
|
// STREAM sockets only connect to other STREAM sockets
|
|
if peer == Stream {
|
|
return true
|
|
}
|
|
default:
|
|
panic("unknown socket-type: \"" + string(sck) + "\"")
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// SocketIdentity is the ZMTP metadata socket identity.
|
|
// See:
|
|
//
|
|
// https://rfc.zeromq.org/spec:23/ZMTP/.
|
|
type SocketIdentity []byte
|
|
|
|
func (id SocketIdentity) String() string {
|
|
n := min(len(id), 255) // ZMTP identities are: 0*255OCTET
|
|
return string(id[:n])
|
|
}
|