Documentation ¶
Index ¶
- Constants
- func ByteToUint16(buf []byte) uint16
- func ClientIdToDeviceId(identify string) (uint64, error)
- func DeviceIdToClientId(deviceid uint64) string
- func Uint16ToByte(value uint16) []byte
- type Broker
- type BytesPayload
- type ConnAck
- type Connect
- type Connection
- type Disconnect
- type Header
- type Manager
- func (m *Manager) AddConn(id uint64, c *Connection)
- func (m *Manager) CleanWorker()
- func (m *Manager) DelConn(id uint64)
- func (m *Manager) GetToken(deviceid uint64) ([]byte, error)
- func (m *Manager) NewConn(conn net.Conn)
- func (m *Manager) PublishMessage2Device(deviceid uint64, msg *Publish, timeout time.Duration) error
- func (m *Manager) PublishMessage2Server(deviceid uint64, msg *Publish) error
- type Message
- type Payload
- type PingReq
- type PingResp
- type Provider
- type PubAck
- type PubComp
- type PubRec
- type PubRel
- type Publish
- type ResponseType
- type SubAck
- type Subscribe
- type TagMessageType
- type TagQosLevel
- type TagRetCode
- type TopicQos
- type UnsubAck
- type Unsubscribe
Constants ¶
const ( QosAtMostOnce = TagQosLevel(iota) QosAtLeastOnce QosExactlyOnce QosInvalid )
OoS only support QoS 0
const ( MsgConnect = TagMessageType(iota + 1) MsgConnAck MsgPublish MsgPubAck MsgPubRec MsgPubRel MsgPubComp MsgSubscribe MsgSubAck MsgUnsubscribe MsgUnsubAck MsgPingReq MsgPingResp MsgDisconnect MsgInvalid )
Message Type
const ( RetCodeAccepted = TagRetCode(iota) RetCodeUnacceptableProtocolVersion RetCodeIdentifierRejected RetCodeBadUsernameOrPassword RetCodeNotAuthorized RetCodeInvalid )
retcode
const (
MaxPayloadSize = (1 << (4 * 7)) - 1
)
Max Payload size
const (
SendChanLen = 16
)
Variables ¶
This section is empty.
Functions ¶
func ByteToUint16 ¶
func ClientIdToDeviceId ¶
func DeviceIdToClientId ¶
func Uint16ToByte ¶
Types ¶
type BytesPayload ¶
type BytesPayload []byte
func (BytesPayload) ReadPayload ¶
func (p BytesPayload) ReadPayload(r io.Reader, n int) error
func (BytesPayload) Size ¶
func (p BytesPayload) Size() int
func (BytesPayload) WritePayload ¶
func (p BytesPayload) WritePayload(b *bytes.Buffer) error
type ConnAck ¶
type ConnAck struct { Header ReturnCode TagRetCode }
ConnAck represents an MQTT CONNACK message.
type Connect ¶
type Connect struct { Header ProtocolName string ProtocolVersion uint8 WillRetain bool WillFlag bool CleanSession bool WillQos TagQosLevel KeepAliveTimer uint16 ClientId string WillTopic, WillMessage string UsernameFlag, PasswordFlag bool Username, Password string }
Connect represents an MQTT CONNECT message.
type Connection ¶
type Connection struct { Mgr *Manager DeviceId uint64 Conn net.Conn SendChan chan Message MessageId uint16 MessageWaitChan map[uint16]chan error KeepAlive uint16 LastHbTime int64 Token []byte }
func NewConnection ¶
func NewConnection(conn net.Conn, mgr *Manager) *Connection
func (*Connection) Close ¶
func (c *Connection) Close()
func (*Connection) Publish ¶
func (c *Connection) Publish(msg Message, timeout time.Duration) error
Publish will publish a message , and return a chan to wait for completion.
func (*Connection) RcvMsgFromClient ¶
func (c *Connection) RcvMsgFromClient()
func (*Connection) SendMsgToClient ¶
func (c *Connection) SendMsgToClient()
func (*Connection) Submit ¶
func (c *Connection) Submit(msg Message)
func (*Connection) ValidateToken ¶
func (c *Connection) ValidateToken(token []byte) error
type Disconnect ¶
type Disconnect struct {
Header
}
Disconnect represents an MQTT DISCONNECT message.
type Header ¶
type Header struct { DupFlag bool QosLevel TagQosLevel Retain bool }
message fix header
func (*Header) EncodeInto ¶
type Manager ¶
type Manager struct { Provider Provider CxtMutex sync.RWMutex IdToConn map[uint64]*Connection }
func NewManager ¶
func (*Manager) AddConn ¶
func (m *Manager) AddConn(id uint64, c *Connection)
func (*Manager) CleanWorker ¶
func (m *Manager) CleanWorker()
func (*Manager) PublishMessage2Device ¶
type Message ¶
type Message interface { Encode(w io.Writer) error Decode(r io.Reader, hdr Header, packetRemaining int32) error }
message interface
func DecodeOneMessage ¶
DecodeOneMessage decodes one message from r. config provides specifics on how to decode messages, nil indicates that the DefaultDecoderConfig should be used.
func NewMessage ¶
func NewMessage(msgType TagMessageType) (msg Message, err error)
type Payload ¶
type Payload interface { // Size returns the number of bytes that WritePayload will write. Size() int // WritePayload writes the payload data to w. Implementations must write // Size() bytes of data, but it is *not* required to do so prior to // returning. Size() bytes must have been written to w prior to another // message being encoded to the underlying connection. WritePayload(b *bytes.Buffer) error // ReadPayload reads the payload data from r (r will EOF at the end of the // payload). It is *not* required for r to have been consumed prior to this // returning. r must have been consumed completely prior to another message // being decoded from the underlying connection. ReadPayload(r io.Reader, n int) error }
Payload is the interface for Publish payloads. Typically the BytesPayload implementation will be sufficient for small payloads whose full contents will exist in memory. However, other implementations can read or write payloads requiring them holding their complete contents in memory.
type PingReq ¶
type PingReq struct {
Header
}
PingReq represents an MQTT PINGREQ message.
type PingResp ¶
type PingResp struct {
Header
}
PingResp represents an MQTT PINGRESP message.
type ResponseType ¶
type SubAck ¶
type SubAck struct { Header MessageId uint16 TopicsQos []TagQosLevel }
SubAck represents an MQTT SUBACK message.
type TagMessageType ¶
type TagMessageType uint8
func (TagMessageType) IsValid ¶
func (msg TagMessageType) IsValid() bool
type TagQosLevel ¶
type TagQosLevel uint8
func (TagQosLevel) HasId ¶
func (qos TagQosLevel) HasId() bool
func (TagQosLevel) IsAtLeastOnce ¶
func (qos TagQosLevel) IsAtLeastOnce() bool
func (TagQosLevel) IsExactlyOnce ¶
func (qos TagQosLevel) IsExactlyOnce() bool
func (TagQosLevel) IsValid ¶
func (qos TagQosLevel) IsValid() bool
type TagRetCode ¶
type TagRetCode uint8
func (TagRetCode) IsValid ¶
func (rc TagRetCode) IsValid() bool
type TopicQos ¶
type TopicQos struct { Topic string Qos TagQosLevel }