Files
zmq/socket_types.go
zeekayandHanzo Dev cde37cf581 Go 1.27.1, and the code it can say more simply
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]>
2026-09-16 19:37:50 -07:00

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])
}