Versions in this module Expand all Collapse all v0 v0.9.0 Dec 15, 2015 Changes in this version + const MaxPayloadSize + const MsgConnAck + const MsgConnect + const MsgDisconnect + const MsgInvalid + const MsgPingReq + const MsgPingResp + const MsgPubAck + const MsgPubComp + const MsgPubRec + const MsgPubRel + const MsgPublish + const MsgSubAck + const MsgSubscribe + const MsgUnsubAck + const MsgUnsubscribe + const QosAtLeastOnce + const QosAtMostOnce + const QosExactlyOnce + const QosInvalid + const RetCodeAccepted + const RetCodeBadUsernameOrPassword + const RetCodeIdentifierRejected + const RetCodeInvalid + const RetCodeNotAuthorized + const RetCodeServerUnavailable + const RetCodeUnacceptableProtocolVersion + const SendChanLen + func ByteToUint16(buf []byte) uint16 + func ClientIdToDeviceId(identify string) (uint64, error) + func DeviceIdToClientId(deviceid uint64) string + func Uint16ToByte(value uint16) []byte + type Broker struct + func NewBroker(p Provider) *Broker + func (b *Broker) GetToken(deviceid uint64) ([]byte, error) + func (b *Broker) Handle(conn net.Conn) + func (b *Broker) SendMessageToDevice(deviceid uint64, msgtype string, message []byte, timeout time.Duration) error + type BytesPayload []byte + func (p BytesPayload) ReadPayload(r io.Reader, n int) error + func (p BytesPayload) Size() int + func (p BytesPayload) WritePayload(b *bytes.Buffer) error + type ConnAck struct + ReturnCode TagRetCode + func (msg *ConnAck) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *ConnAck) Encode(w io.Writer) (err error) + type Connect struct + CleanSession bool + ClientId string + KeepAliveTimer uint16 + Password string + PasswordFlag bool + ProtocolName string + ProtocolVersion uint8 + Username string + UsernameFlag bool + WillFlag bool + WillMessage string + WillQos TagQosLevel + WillRetain bool + WillTopic string + func (msg *Connect) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *Connect) Encode(w io.Writer) (err error) + type Connection struct + Conn net.Conn + DeviceId uint64 + KeepAlive uint16 + LastHbTime int64 + MessageId uint16 + MessageWaitChan map[uint16]chan error + Mgr *Manager + SendChan chan Message + Token []byte + func NewConnection(conn net.Conn, mgr *Manager) *Connection + func (c *Connection) Close() + func (c *Connection) Publish(msg Message, timeout time.Duration) error + func (c *Connection) RcvMsgFromClient() + func (c *Connection) SendMsgToClient() + func (c *Connection) Submit(msg Message) + func (c *Connection) ValidateToken(token []byte) error + type Disconnect struct + func (msg *Disconnect) Decode(r io.Reader, hdr Header, packetRemaining int32) error + func (msg *Disconnect) Encode(w io.Writer) error + type Header struct + DupFlag bool + QosLevel TagQosLevel + Retain bool + func (hdr *Header) Decode(r io.Reader) (msgType TagMessageType, remainingLength int32, err error) + func (hdr *Header) Encode(w io.Writer, msgType TagMessageType, remainingLength int32) error + func (hdr *Header) EncodeInto(buf *bytes.Buffer, msgType TagMessageType, remainingLength int32) error + type Manager struct + CxtMutex sync.RWMutex + IdToConn map[uint64]*Connection + Provider Provider + func NewManager(p Provider) *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 interface + Decode func(r io.Reader, hdr Header, packetRemaining int32) error + Encode func(w io.Writer) error + func DecodeOneMessage(r io.Reader) (msg Message, err error) + func NewMessage(msgType TagMessageType) (msg Message, err error) + type Payload interface + ReadPayload func(r io.Reader, n int) error + Size func() int + WritePayload func(b *bytes.Buffer) error + type PingReq struct + func (msg *PingReq) Decode(r io.Reader, hdr Header, packetRemaining int32) error + func (msg *PingReq) Encode(w io.Writer) error + type PingResp struct + func (msg *PingResp) Decode(r io.Reader, hdr Header, packetRemaining int32) error + func (msg *PingResp) Encode(w io.Writer) error + type Provider interface + OnDeviceHeartBeat func(deviceid uint64) error + OnDeviceMessage func(deviceid uint64, msgtype string, message []byte) + OnDeviceOffline func(deviceid uint64) error + OnDeviceOnline func(args rpcs.ArgsGetOnline) error + ValidateDeviceToken func(deviceid uint64, token []byte) error + type PubAck struct + MessageId uint16 + func (msg *PubAck) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *PubAck) Encode(w io.Writer) error + type PubComp struct + MessageId uint16 + func (msg *PubComp) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *PubComp) Encode(w io.Writer) error + type PubRec struct + MessageId uint16 + func (msg *PubRec) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *PubRec) Encode(w io.Writer) error + type PubRel struct + MessageId uint16 + func (msg *PubRel) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *PubRel) Encode(w io.Writer) error + type Publish struct + MessageId uint16 + Payload Payload + TopicName string + func (msg *Publish) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *Publish) Encode(w io.Writer) (err error) + type ResponseType struct + DataType string + PublishType uint8 + SendTime uint8 + type SubAck struct + MessageId uint16 + TopicsQos []TagQosLevel + func (msg *SubAck) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *SubAck) Encode(w io.Writer) (err error) + type Subscribe struct + MessageId uint16 + Topics []TopicQos + func (msg *Subscribe) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *Subscribe) Encode(w io.Writer) (err error) + type TagMessageType uint8 + func (msg TagMessageType) IsValid() bool + type TagQosLevel uint8 + func (qos TagQosLevel) HasId() bool + func (qos TagQosLevel) IsAtLeastOnce() bool + func (qos TagQosLevel) IsExactlyOnce() bool + func (qos TagQosLevel) IsValid() bool + type TagRetCode uint8 + func (rc TagRetCode) IsValid() bool + type TopicQos struct + Qos TagQosLevel + Topic string + type UnsubAck struct + MessageId uint16 + func (msg *UnsubAck) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *UnsubAck) Encode(w io.Writer) error + type Unsubscribe struct + MessageId uint16 + Topics []string + func (msg *Unsubscribe) Decode(r io.Reader, hdr Header, packetRemaining int32) (err error) + func (msg *Unsubscribe) Encode(w io.Writer) (err error)