Documentation ¶
Overview ¶
Package mqttprot implements the MQTT protocol.
Index ¶
- type Client
- type MockClient
- type PacketType
- type Protocol
- func (p *Protocol) BuildRequest(reqInfo interface{}) (protocols.Request, error)
- func (p *Protocol) BuildResponse(respInfo interface{}) (protocols.Response, error)
- func (p *Protocol) CreateRequest(req interface{}) (protocols.Request, error)
- func (p *Protocol) CreateResponse(resp interface{}) (protocols.Response, error)
- func (p *Protocol) NewRequestInfo() interface{}
- func (p *Protocol) NewResponseInfo() interface{}
- type Request
- func (r *Request) Client() Client
- func (r *Request) Close()
- func (r *Request) ConnectPacket() *packets.ConnectPacket
- func (r *Request) DisconnectPacket() *packets.DisconnectPacket
- func (r *Request) GetPayload() io.Reader
- func (r *Request) Header() protocols.Header
- func (r *Request) IsStream() bool
- func (r *Request) PacketType() PacketType
- func (r *Request) PayloadSize() int64
- func (r *Request) PublishPacket() *packets.PublishPacket
- func (r *Request) RawPayload() []byte
- func (r *Request) RealIP() string
- func (r *Request) SetPayload(payload interface{})
- func (r *Request) SubscribePacket() *packets.SubscribePacket
- func (r *Request) ToBuilderRequest(name string) interface{}
- func (r *Request) UnsubscribePacket() *packets.UnsubscribePacket
- type Response
- func (r *Response) Close()
- func (r *Response) Disconnect() bool
- func (r *Response) Drop() bool
- func (r *Response) GetPayload() io.Reader
- func (r *Response) Header() protocols.Header
- func (r *Response) IsStream() bool
- func (r *Response) PayloadSize() int64
- func (r *Response) RawPayload() []byte
- func (r *Response) SetDisconnect()
- func (r *Response) SetDrop()
- func (r *Response) SetPayload(payload interface{})
- func (r *Response) ToBuilderResponse(name string) interface{}
- func (r *Response) Trailer() protocols.Trailer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { ClientID() string UserName() string Load(key interface{}) (value interface{}, ok bool) Store(key interface{}, value interface{}) Delete(key interface{}) }
Client contains MQTT client info that send this packet
type MockClient ¶
MockClient is mock client for MQTT protocol
func (*MockClient) ClientID ¶
func (m *MockClient) ClientID() string
ClientID return client id of MockClient
func (*MockClient) Delete ¶
func (m *MockClient) Delete(key interface{})
Delete delete key-value pair in MockClient kv map
func (*MockClient) Load ¶
func (m *MockClient) Load(key interface{}) (value interface{}, ok bool)
Load load value keep in MockClient kv map
func (*MockClient) Store ¶
func (m *MockClient) Store(key interface{}, value interface{})
Store store kv pair into MockClient kv map
func (*MockClient) UserName ¶
func (m *MockClient) UserName() string
UserName return username if MockClient
type PacketType ¶
type PacketType int
PacketType contains supported MQTT packet type
const ( // ConnectType is MQTT packet type of connect ConnectType PacketType = 1 // PublishType is MQTT packet type of publish PublishType PacketType = 2 // DisconnectType is MQTT packet type of disconnect DisconnectType PacketType = 3 // SubscribeType is MQTT packet type of subscribe SubscribeType PacketType = 4 // UnsubscribeType is MQTT packet type of unsubscribe UnsubscribeType PacketType = 5 // OtherType is all other MQTT packet type OtherType PacketType = 99 )
type Protocol ¶
type Protocol struct { }
Protocol implements protocols.Protocol for MQTT.
func (*Protocol) BuildRequest ¶
BuildRequest builds and returns a request according to the given reqInfo.
func (*Protocol) BuildResponse ¶
BuildResponse builds and returns a response according to the given respInfo.
func (*Protocol) CreateRequest ¶
CreateRequest creates a new MQTT request.
func (*Protocol) CreateResponse ¶
CreateResponse creates a new MQTT response.
func (*Protocol) NewRequestInfo ¶
func (p *Protocol) NewRequestInfo() interface{}
NewRequestInfo returns a new requestInfo.
func (*Protocol) NewResponseInfo ¶
func (p *Protocol) NewResponseInfo() interface{}
NewResponseInfo returns a new responseInfo.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request contains MQTT packet.
func NewRequest ¶
func NewRequest(packet packets.ControlPacket, client Client) *Request
NewRequest create new MQTT Request
func (*Request) ConnectPacket ¶
func (r *Request) ConnectPacket() *packets.ConnectPacket
ConnectPacket return MQTT connect packet if PacketType is ConnectType
func (*Request) DisconnectPacket ¶
func (r *Request) DisconnectPacket() *packets.DisconnectPacket
DisconnectPacket return MQTT disconnect packet if PacketType is DisconnectType
func (*Request) GetPayload ¶
GetPayload returns a new payload reader.
func (*Request) PacketType ¶
func (r *Request) PacketType() PacketType
PacketType return MQTT request packet type
func (*Request) PayloadSize ¶
PayloadSize returns the length of the payload.
func (*Request) PublishPacket ¶
func (r *Request) PublishPacket() *packets.PublishPacket
PublishPacket return MQTT publish packet if PacketType is PublishType
func (*Request) RawPayload ¶
RawPayload returns the payload in []byte, the caller should not modify its content.
func (*Request) SetPayload ¶
func (r *Request) SetPayload(payload interface{})
SetPayload set the payload of the request to payload.
func (*Request) SubscribePacket ¶
func (r *Request) SubscribePacket() *packets.SubscribePacket
SubscribePacket return MQTT subscribe packet if PacketType is SubscribeType
func (*Request) ToBuilderRequest ¶
ToBuilderRequest wraps the request and returns the wrapper, the return value can be used in the template of the Builder filters.
func (*Request) UnsubscribePacket ¶
func (r *Request) UnsubscribePacket() *packets.UnsubscribePacket
UnsubscribePacket return MQTT unsubscribe packet if PacketType is UnsubscribeType
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response contains MQTT response.
func (*Response) Disconnect ¶
Disconnect return true if the MQTT client will be disconnect.
func (*Response) Drop ¶
Drop return true if the packet in context will be drop. For example, if SetDrop and the packet in Request is subscribe packet, MQTTProxy will not subscribe the topics in the packet.
func (*Response) GetPayload ¶
GetPayload returns a new payload reader.
func (*Response) PayloadSize ¶
PayloadSize returns the length of the payload.
func (*Response) RawPayload ¶
RawPayload returns the payload in []byte, the caller should not modify its content.
func (*Response) SetDisconnect ¶
func (r *Response) SetDisconnect()
SetDisconnect means the MQTT client will be disconnect.
func (*Response) SetDrop ¶
func (r *Response) SetDrop()
SetDrop means the packet in context will be drop.
func (*Response) SetPayload ¶
func (r *Response) SetPayload(payload interface{})
SetPayload set the payload of the response to payload.
func (*Response) ToBuilderResponse ¶
ToBuilderResponse wraps the response and returns the wrapper, the return value can be used in the template of the Builder filters.