mqttprot

package
v2.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package mqttprot implements the MQTT protocol.

Index

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

type MockClient struct {
	MockClientID string
	MockUserName string
	MockKVMap    sync.Map
}

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

func (p *Protocol) BuildRequest(reqInfo interface{}) (protocols.Request, error)

BuildRequest builds and returns a request according to the given reqInfo.

func (*Protocol) BuildResponse

func (p *Protocol) BuildResponse(respInfo interface{}) (protocols.Response, error)

BuildResponse builds and returns a response according to the given respInfo.

func (*Protocol) CreateRequest

func (p *Protocol) CreateRequest(req interface{}) (protocols.Request, error)

CreateRequest creates a new MQTT request.

func (*Protocol) CreateResponse

func (p *Protocol) CreateResponse(resp interface{}) (protocols.Response, error)

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) Client

func (r *Request) Client() Client

Client return MQTT request client

func (*Request) Close

func (r *Request) Close()

Close closes the 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

func (r *Request) GetPayload() io.Reader

GetPayload returns a new payload reader.

func (*Request) Header

func (r *Request) Header() protocols.Header

Header return MQTT request header

func (*Request) IsStream

func (r *Request) IsStream() bool

IsStream returns whether the payload of the request is a stream.

func (*Request) PacketType

func (r *Request) PacketType() PacketType

PacketType return MQTT request packet type

func (*Request) PayloadSize

func (r *Request) PayloadSize() int64

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

func (r *Request) RawPayload() []byte

RawPayload returns the payload in []byte, the caller should not modify its content.

func (*Request) RealIP

func (r *Request) RealIP() string

RealIP returns the real IP of the request.

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

func (r *Request) ToBuilderRequest(name string) interface{}

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 NewResponse

func NewResponse() *Response

NewResponse returns a new MQTT response.

func (*Response) Close

func (r *Response) Close()

Close closes the response.

func (*Response) Disconnect

func (r *Response) Disconnect() bool

Disconnect return true if the MQTT client will be disconnect.

func (*Response) Drop

func (r *Response) Drop() bool

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

func (r *Response) GetPayload() io.Reader

GetPayload returns a new payload reader.

func (*Response) Header

func (r *Response) Header() protocols.Header

Header return MQTT response header

func (*Response) IsStream

func (r *Response) IsStream() bool

IsStream returns whether the payload of the response is a stream.

func (*Response) PayloadSize

func (r *Response) PayloadSize() int64

PayloadSize returns the length of the payload.

func (*Response) RawPayload

func (r *Response) RawPayload() []byte

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

func (r *Response) ToBuilderResponse(name string) interface{}

ToBuilderResponse wraps the response and returns the wrapper, the return value can be used in the template of the Builder filters.

func (*Response) Trailer

func (r *Response) Trailer() protocols.Trailer

Trailer returns the trailer of the response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL