Documentation ¶
Index ¶
Constants ¶
View Source
const ( Connect = 1 Connack = 2 Publish = 3 Puback = 4 Pubrec = 5 Pubrel = 6 Pubcomp = 7 Subscribe = 8 Suback = 9 Unsubscribe = 10 Unsuback = 11 Pingreq = 12 Pingresp = 13 Disconnect = 14 )
Mqtt消息的包类型
View Source
const ( Accepted = 0x00 ErrRefusedBadProtocolVersion = 0x01 ErrRefusedIDRejected = 0x02 ErrRefusedBadUsernameOrPassword = 0x04 ErrRefusedNotAuthorised = 0x05 ErrNetworkError = 0xFE ErrProtocolViolation = 0xFF )
Variables ¶
View Source
var PacketNames = map[uint8]string{
1: "CONNECT",
2: "CONNACK",
3: "PUBLISH",
4: "PUBACK",
5: "PUBREC",
6: "PUBREL",
7: "PUBCOMP",
8: "SUBSCRIBE",
9: "SUBACK",
10: "UNSUBSCRIBE",
11: "UNSUBACK",
12: "PINGREQ",
13: "PINGRESP",
14: "DISCONNECT",
}
Functions ¶
This section is empty.
Types ¶
type ConnackPacket ¶
type ConnackPacket struct { FixedHeader SessionPresent bool ReturnCode byte }
connack包,服务端对connect的回应
func (*ConnackPacket) String ¶
func (ca *ConnackPacket) String() string
type ConnectPacket ¶
type ConnectPacket struct { FixedHeader ProtocolName string ProtocolVersion byte CleanSession bool WillFlag bool WillQos byte WillRetain bool UsernameFlag bool PasswordFlag bool ReservedBit byte Keepalive uint16 ClientId string WillTopic string WillMessage []byte Username string Password []byte }
connect包,客户端发起连接时发送
func (*ConnectPacket) String ¶
func (cp *ConnectPacket) String() string
func (*ConnectPacket) Validate ¶ added in v0.3.0
func (c *ConnectPacket) Validate() byte
Validate performs validation of the fields of a Connect packet
type DisconnectPacket ¶
type DisconnectPacket struct {
FixedHeader
}
func (*DisconnectPacket) String ¶
func (d *DisconnectPacket) String() string
type FixedHeader ¶
MQTT协议的固定头部协议,每条消息都需要携带
func (FixedHeader) String ¶
func (fh FixedHeader) String() string
type MqttPacket ¶
所有packet的公共接口
func NewMqttPacket ¶
func NewMqttPacket(messageType byte) MqttPacket
func NewMqttPacketWithHeader ¶
func NewMqttPacketWithHeader(fh FixedHeader) (MqttPacket, error)
func ReadPacket ¶
func ReadPacket(conn net.Conn) (MqttPacket, error)
type PingreqPacket ¶
type PingreqPacket struct {
FixedHeader
}
func (*PingreqPacket) String ¶
func (pr *PingreqPacket) String() string
type PingrespPacket ¶
type PingrespPacket struct {
FixedHeader
}
func (*PingrespPacket) String ¶
func (pr *PingrespPacket) String() string
type PublishPacket ¶
type PublishPacket struct { FixedHeader TopicName string MessageID uint16 Payload []byte }
PublishPacket is an internal representation of the fields of the Publish MQTT packet
func (*PublishPacket) Copy ¶
func (p *PublishPacket) Copy() *PublishPacket
Copy creates a new PublishPacket with the same topic and payload but an empty fixed header, useful for when you want to deliver a message with different properties such as Qos but the same content
func (*PublishPacket) Read ¶
func (p *PublishPacket) Read(b io.Reader) error
Unpack decodes the details of a ControlPacket after the fixed header has been read
func (*PublishPacket) String ¶
func (p *PublishPacket) String() string
type SubackPacket ¶
type SubackPacket struct { FixedHeader MessageID uint16 ReturnCodes []byte }
func (*SubackPacket) String ¶
func (sa *SubackPacket) String() string
type SubscribePacket ¶
type SubscribePacket struct { FixedHeader MessageID uint16 Topics []string Qoss []byte }
func (*SubscribePacket) String ¶
func (s *SubscribePacket) String() string
type UnsubackPacket ¶
type UnsubackPacket struct { FixedHeader MessageID uint16 }
func (*UnsubackPacket) String ¶
func (ua *UnsubackPacket) String() string
type UnsubscribePacket ¶
type UnsubscribePacket struct { FixedHeader MessageID uint16 Topics []string }
func (*UnsubscribePacket) String ¶
func (u *UnsubscribePacket) String() string
Click to show internal directories.
Click to hide internal directories.