Versions in this module Expand all Collapse all v0 v0.2.0 Feb 17, 2023 Changes in this version + const CodeAdministrativeAction + const CodeBadAuthenticationMethod + const CodeBadUserPass + const CodeBadUsernameOrPassword + const CodeBanned + const CodeClientIdNotValid + const CodeConnectionRateExceeded + const CodeContinueAuth + const CodeDisconnWithWill + const CodeGrantedQos0 + const CodeGrantedQos1 + const CodeGrantedQos2 + const CodeIdentifierRejected + const CodeImplementationSpecificError + const CodeKeepaliveTimeout + const CodeMalformedPacket + const CodeMaxConnectTime + const CodeMessageRateTooHigh + const CodeNoMatchingSubscribers + const CodeNoSubscriptionExisted + const CodeNormalDisconn + const CodeNotAuthorized + const CodePacketIdentifierInUse + const CodePacketIdentifierNotFound + const CodePacketTooLarge + const CodePayloadFormatInvalid + const CodeProtoError + const CodeQosNoSupported + const CodeQuotaExceeded + const CodeReAuth + const CodeReceiveMaxExceeded + const CodeRetainNotSupported + const CodeServerBusy + const CodeServerMoved + const CodeServerShuttingDown + const CodeServerUnavail + const CodeServerUnavailable + const CodeSessionTakenOver + const CodeSharedSubscriptionNotSupported + const CodeSubscriptionIdentifiersNotSupported + const CodeSuccess + const CodeTopicAliasInvalid + const CodeTopicFilterInvalid + const CodeTopicNameInvalid + const CodeUnacceptableVersion + const CodeUnauthorized + const CodeUnspecifiedError + const CodeUnsupportedProtoVersion + const CodeUseAnotherServer + const CodeWildcardSubscriptionNotSupported + const SubFail + const SubOkMaxQos0 + const SubOkMaxQos1 + const SubOkMaxQos2 + var ErrDecodeBadPacket = errors.New("none MQTT packet") + var ErrDecodeNoneV311Packet = errors.New("none MQTT v3.1.1 packet") + var ErrDecodeNoneV5Packet = errors.New("none MQTT v5 packet") + var ErrEncodeBadPacket = errors.New("trying encode none MQTT packet ") + var ErrEncodeLargePacket = errors.New("MQTT packet too large") + var ErrNotSupportedVersion = errors.New("mqtt version not supported ") + var ErrPacketDroppedByStrategy = errors.New("packet persist dropped by strategy ") + var ErrUnsupportedVersion = errors.New("trying encode/decode packet with unsupported MQTT version ") + var NonePersist = &nonePersist + var PingReqPacket = &pingReqPacket + var PingRespPacket = &pingRespPacket + var WithBuf = WithBufSize + func Encode(packet Packet, w BufferedWriter) error + type AsyncClient struct + func (c *AsyncClient) Connect(h ConnHandler) + func (c *AsyncClient) ConnectServer(server string, connOptions ...Option) error + func (c *AsyncClient) Destroy(force bool) + func (c *AsyncClient) Disconnect(server string, packet *DisconnPacket) bool + func (c *AsyncClient) Handle(topic string, h TopicHandler) + func (c *AsyncClient) HandleNet(h NetHandler) + func (c *AsyncClient) HandlePersist(h PersistHandler) + func (c *AsyncClient) HandlePub(h PubHandler) + func (c *AsyncClient) HandleSub(h SubHandler) + func (c *AsyncClient) HandleTopic(topic string, h TopicHandleFunc) + func (c *AsyncClient) HandleUnSub(h UnSubHandler) + func (c *AsyncClient) Publish(msg ...*PublishPacket) + func (c *AsyncClient) Subscribe(topics ...*Topic) + func (c *AsyncClient) UnSubscribe(topics ...string) + func (c *AsyncClient) Unsubscribe(topics ...string) + func (c *AsyncClient) Wait() + type AuthPacket struct + Code byte + Props *AuthProps + func (a *AuthPacket) Bytes() []byte + func (a *AuthPacket) Type() CtrlType + func (a *AuthPacket) WriteTo(w BufferedWriter) error + type AuthProps struct + AuthData []byte + AuthMethod string + Reason string + UserProps UserProps + type BasePacket struct + ProtoVersion ProtoVersion + func (b *BasePacket) SetVersion(version ProtoVersion) + func (b *BasePacket) Version() ProtoVersion + type BufferedReader interface + type BufferedWriter interface + type Client = *AsyncClient + func NewClient(options ...Option) (Client, error) + type ConnAckPacket struct + Code byte + Present bool + Props *ConnAckProps + func (c *ConnAckPacket) Bytes() []byte + func (c *ConnAckPacket) Type() CtrlType + func (c *ConnAckPacket) WriteTo(w BufferedWriter) error + type ConnAckProps struct + AssignedClientID string + AuthData []byte + AuthMethod string + MaxPacketSize uint32 + MaxQos QosLevel + MaxRecv uint16 + MaxTopicAlias uint16 + Reason string + RespInfo string + RetainAvail *bool + ServerKeepalive uint16 + ServerRef string + SessionExpiryInterval uint32 + SharedSubAvail *bool + SubIDAvail *bool + UserProps UserProps + WildcardSubAvail *bool + type ConnHandleFunc func(client Client, server string, code byte, err error) + type ConnHandler func(server string, code byte, err error) + type ConnPacket struct + CleanSession bool + ClientID string + IsWill bool + Keepalive uint16 + Password string + Props *ConnProps + ProtoName string + Username string + WillMessage []byte + WillProps *WillProps + WillQos QosLevel + WillRetain bool + WillTopic string + func (c *ConnPacket) Bytes() []byte + func (c *ConnPacket) Type() CtrlType + func (c *ConnPacket) WriteTo(w BufferedWriter) error + type ConnProps struct + AuthData []byte + AuthMethod string + MaxPacketSize uint32 + MaxRecv uint16 + MaxTopicAlias uint16 + ReqProblemInfo *bool + ReqRespInfo *bool + SessionExpiryInterval uint32 + UserProps UserProps + type Connector func(ctx context.Context, address string, timeout time.Duration, ...) (net.Conn, error) + type CtrlType = byte + const CtrlAuth + const CtrlConn + const CtrlConnAck + const CtrlDisConn + const CtrlPingReq + const CtrlPingResp + const CtrlPubAck + const CtrlPubComp + const CtrlPubRecv + const CtrlPubRel + const CtrlPublish + const CtrlSubAck + const CtrlSubscribe + const CtrlUnSub + const CtrlUnSubAck + type DisConnPacket = DisconnPacket + type DisConnProps = DisconnPacket + type DisconnPacket struct + Code byte + Props *DisconnProps + func (d *DisconnPacket) Bytes() []byte + func (d *DisconnPacket) Type() CtrlType + func (d *DisconnPacket) WriteTo(w BufferedWriter) error + type DisconnProps struct + Reason string + ServerRef string + SessionExpiryInterval uint32 + UserProps UserProps + type LogLevel byte + const Debug + const Error + const Info + const Silent + const Verbose + const Warning + type NetHandleFunc func(client Client, server string, err error) + type NetHandler func(server string, err error) + type Option func(*AsyncClient, *connectOptions) error + func WithAutoReconnect(autoReconnect bool) Option + func WithBackoffStrategy(firstDelay, maxDelay time.Duration, factor float64) Option + func WithBufSize(sendBufSize, recvBufSize int) Option + func WithCleanSession(f bool) Option + func WithClientID(clientID string) Option + func WithConnHandleFunc(handler ConnHandleFunc) Option + func WithConnPacket(pkt ConnPacket) Option + func WithCustomConnector(connector Connector) Option + func WithCustomTLS(config *tls.Config) Option + func WithDialTimeout(timeout uint16) Option + func WithIdentity(username, password string) Option + func WithKeepalive(keepalive uint16, factor float64) Option + func WithLog(l LogLevel) Option + func WithNetHandleFunc(handler NetHandleFunc) Option + func WithPersist(method PersistMethod) Option + func WithPersistHandleFunc(handler PersistHandleFunc) Option + func WithPubHandleFunc(handler PubHandleFunc) Option + func WithRouter(r TopicRouter) Option + func WithSecureServer(servers ...string) Option + func WithServer(servers ...string) Option + func WithSubHandleFunc(handler SubHandleFunc) Option + func WithTCPConnector(handshakeTimeout time.Duration) Option + func WithTLS(certFile, keyFile, caCert, serverNameOverride string, skipVerify bool) Option + func WithTLSReader(certReader, keyReader, caReader io.Reader, serverNameOverride string, ...) Option + func WithUnsubHandleFunc(handler UnsubHandleFunc) Option + func WithVersion(version ProtoVersion, compromise bool) Option + func WithWebSocketConnector(handshakeTimeout time.Duration, headers http.Header) Option + func WithWill(topic string, qos QosLevel, retain bool, payload []byte) Option + type Packet interface + Bytes func() []byte + SetVersion func(version ProtoVersion) + Type func() CtrlType + Version func() ProtoVersion + WriteTo func(w BufferedWriter) error + func Decode(version ProtoVersion, r BufferedReader) (Packet, error) + type PersistHandleFunc func(client Client, packet Packet, err error) + type PersistHandler func(err error) + type PersistMethod interface + Delete func(key string) error + Destroy func() error + Load func(key string) (Packet, bool) + Name func() string + Range func(func(key string, p Packet) bool) + Store func(key string, p Packet) error + func NewFilePersist(dirPath string, strategy *PersistStrategy) PersistMethod + func NewMemPersist(strategy *PersistStrategy) PersistMethod + type PersistStrategy struct + DropOnExceed bool + DuplicateReplace bool + Interval time.Duration + MaxCount uint32 + type ProtoVersion byte + const V311 + const V5 + type PubAckPacket struct + Code byte + PacketID uint16 + Props *PubAckProps + func (p *PubAckPacket) Bytes() []byte + func (p *PubAckPacket) Type() CtrlType + func (p *PubAckPacket) WriteTo(w BufferedWriter) error + type PubAckProps struct + Reason string + UserProps UserProps + type PubCompPacket struct + Code byte + PacketID uint16 + Props *PubCompProps + func (p *PubCompPacket) Bytes() []byte + func (p *PubCompPacket) Type() CtrlType + func (p *PubCompPacket) WriteTo(w BufferedWriter) error + type PubCompProps struct + Reason string + UserProps UserProps + type PubHandleFunc func(client Client, topic string, err error) + type PubHandler func(topic string, err error) + type PubRecvPacket struct + Code byte + PacketID uint16 + Props *PubRecvProps + func (p *PubRecvPacket) Bytes() []byte + func (p *PubRecvPacket) Type() CtrlType + func (p *PubRecvPacket) WriteTo(w BufferedWriter) error + type PubRecvProps struct + Reason string + UserProps UserProps + type PubRelPacket struct + Code byte + PacketID uint16 + Props *PubRelProps + func (p *PubRelPacket) Bytes() []byte + func (p *PubRelPacket) Type() CtrlType + func (p *PubRelPacket) WriteTo(w BufferedWriter) error + type PubRelProps struct + Reason string + UserProps UserProps + type PublishPacket struct + IsDup bool + IsRetain bool + PacketID uint16 + Payload []byte + Props *PublishProps + Qos QosLevel + TopicName string + func (p *PublishPacket) Bytes() []byte + func (p *PublishPacket) Type() CtrlType + func (p *PublishPacket) WriteTo(w BufferedWriter) error + type PublishProps struct + ContentType string + CorrelationData []byte + MessageExpiryInterval uint32 + PayloadFormat byte + RespTopic string + SubIDs []int + TopicAlias uint16 + UserProps UserProps + type QosLevel = byte + const Qos0 + const Qos1 + const Qos2 + type RegexRouter struct + func NewRegexRouter() *RegexRouter + func (r *RegexRouter) Dispatch(client Client, p *PublishPacket) + func (r *RegexRouter) Handle(topicRegex string, h TopicHandleFunc) + func (r *RegexRouter) Name() string + type StandardRouter struct + func NewStandardRouter() *StandardRouter + func (s *StandardRouter) Dispatch(client Client, p *PublishPacket) + func (s *StandardRouter) Handle(topic string, h TopicHandleFunc) + func (s *StandardRouter) Name() string + type SubAckPacket struct + Codes []byte + PacketID uint16 + Props *SubAckProps + func (s *SubAckPacket) Bytes() []byte + func (s *SubAckPacket) Type() CtrlType + func (s *SubAckPacket) WriteTo(w BufferedWriter) error + type SubAckProps struct + Reason string + UserProps UserProps + type SubHandleFunc func(client Client, topics []*Topic, err error) + type SubHandler func(topics []*Topic, err error) + type SubscribePacket struct + PacketID uint16 + Props *SubscribeProps + Topics []*Topic + func (s *SubscribePacket) Bytes() []byte + func (s *SubscribePacket) Type() CtrlType + func (s *SubscribePacket) WriteTo(w BufferedWriter) error + type SubscribeProps struct + SubID int + UserProps UserProps + type TextRouter struct + func NewTextRouter() *TextRouter + func (r *TextRouter) Dispatch(client Client, p *PublishPacket) + func (r *TextRouter) Handle(topic string, h TopicHandleFunc) + func (r *TextRouter) Name() string + type Topic struct + Name string + Qos QosLevel + func (t *Topic) String() string + type TopicHandleFunc func(client Client, topic string, qos QosLevel, msg []byte) + type TopicHandler func(topic string, qos QosLevel, msg []byte) + type TopicRouter interface + Dispatch func(client Client, p *PublishPacket) + Handle func(topic string, h TopicHandleFunc) + Name func() string + type UnSubAckPacket = UnsubAckPacket + type UnSubAckProps = UnsubAckProps + type UnSubHandler func(topics []string, err error) + type UnSubProps = UnsubProps + type UnsubAckPacket struct + PacketID uint16 + Props *UnsubAckProps + func (s *UnsubAckPacket) Bytes() []byte + func (s *UnsubAckPacket) Type() CtrlType + func (s *UnsubAckPacket) WriteTo(w BufferedWriter) error + type UnsubAckProps struct + Reason string + UserProps UserProps + type UnsubHandleFunc func(client Client, topics []string, err error) + type UnsubPacket struct + PacketID uint16 + Props *UnsubProps + TopicNames []string + func (s *UnsubPacket) Bytes() []byte + func (s *UnsubPacket) Type() CtrlType + func (s *UnsubPacket) WriteTo(w BufferedWriter) error + type UnsubProps struct + UserProps UserProps + type UserProps map[string][]string + func (u UserProps) Add(key, value string) + func (u UserProps) Del(key string) + func (u UserProps) Get(key string) (string, bool) + func (u UserProps) Set(key string, value string) + type WillProps struct + ContentType string + CorrelationData []byte + MessageExpiryInterval uint32 + PayloadFormat uint8 + ResponseTopic string + UserProps UserProps + WillDelayInterval uint32