API
#github.com/xulang-org/packages/mqtt
Xu 0.8.8 API
import: mqtt #github.com/xulang-org/packages/mqtt
counts: 10 fns, 11 methods, 3 types, 0 consts, 0 ifaces
MQTT 3.1.1 lightweight messaging and IoT driver for Xu. Features Pure binary Wire Protocol implementation in 100% pure Xu. Full CONNECT / CONNACK session handshake. PUBLISH support for QoS 0 and QoS 1 with PUBACK confirmation. SUBSCRIBE with SUBACK confirmation. PINGREQ / PINGRESP heartbeat maintenance. Graceful DISCONNECT.
github.com/xulang-org/packages · 0.1.1 · Install and use
open
pub fn open(addr string, client_id string) Client
Purpose
MQTT 3.1.1 lightweight messaging and IoT driver for Xu. Features Pure binary Wire Protocol implementation in 100% pure Xu. Full CONNECT / CONNACK session handshake. PUBLISH support for QoS 0 and QoS 1 with PUBACK confirmation. SUBSCRIBE with SUBACK confirmation. PINGREQ / PINGRESP heartbeat maintenance. Graceful DISCONNECT. Throws on failure.
Parameters
addr string- address (string)
client_id string- client_id (string)
Returns
Client — a value of this type
open_pool
pub fn open_pool(addr string, id_prefix string, max_idle int) Pool
Purpose
Open pool.
Parameters
addr string- address (string)
id_prefix string- id_prefix (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
struct Client
pub struct Client {
pub fd int
pub addr string
pub client_id string
pub next_pid int
}
Purpose
Public struct `Client`.
Parameters
fd int- file descriptor
addr string- address
client_id string- field (string)
next_pid int- field (int)
struct Message
pub struct Message {
pub topic string
pub payload string
pub qos int
}
Purpose
Public struct `Message`.
Parameters
topic string- field (string)
payload string- field (string)
qos int- field (int)
connect_opts
pub fn connect_opts(addr string, client_id string, username string, password string, clean_session bool, keepalive int) Client
Purpose
Connect opts. Throws on failure.
Parameters
addr string- address (string)
client_id string- client_id (string)
username string- username (string)
password string- password (string)
clean_session bool- clean_session (bool)
keepalive int- keepalive (int)
Returns
Client — a value of this type
connect
pub fn connect(addr string, client_id string) Client
Purpose
connect; returns Client. Throws on failure.
Parameters
addr string- address (string)
client_id string- client_id (string)
Returns
Client — a value of this type
connect_auth
pub fn connect_auth(addr string, client_id string, username string, password string) Client
Purpose
Connect auth. Throws on failure.
Parameters
addr string- address (string)
client_id string- client_id (string)
username string- username (string)
password string- password (string)
Returns
Client — a value of this type
(&mut Client) ping
pub fn (c &mut Client) ping() bool
Purpose
Call `ping` on `&mut Client`.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
bool — true or false
(&mut Client) publish
pub fn (c &mut Client) publish(topic string, payload string, qos int) int
Purpose
Call `publish` on `&mut Client`. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
topic string- topic (string)
payload string- payload (string)
qos int- qos (int)
Returns
int — a value of this type
(&mut Client) subscribe
pub fn (c &mut Client) subscribe(topic string, qos int) int
Purpose
Call `subscribe` on `&mut Client`. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
topic string- topic (string)
qos int- qos (int)
Returns
int — a value of this type
(&mut Client) read_message
pub fn (c &mut Client) read_message() Message
Purpose
Method on `&mut Client`: read message. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
Message — a value of this type
(&mut Client) disconnect
pub fn (c &mut Client) disconnect() int
Purpose
Call `disconnect` on `&mut Client`.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
int — a value of this type
(&mut Client) close
pub fn (c &mut Client) close() int
Purpose
Method on `&mut Client`: close the resource.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
int — a value of this type
struct Pool
pub struct Pool {
pub addr string
pub id_prefix string
pub idle chan int
pub max_idle int
pub seq chan int
}
Purpose
Connection Pool for MQTT 3.1.1 clients. Uses channel of socket file descriptors for lightweight and high-throughput pooling.
Parameters
addr string- address
id_prefix string- field (string)
idle chan int- field (channel; type chan int)
max_idle int- field (int)
seq chan int- field (channel; type chan int)
new_pool
pub fn new_pool(addr string, id_prefix string, max_idle int) Pool
Purpose
Construct pool.
Parameters
addr string- address (string)
id_prefix string- id_prefix (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
(&Pool) get
pub fn (p &Pool) get() Client
Purpose
Call `get` on `&Pool`. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
Client — a value of this type
(&Pool) put_conn
pub fn (p &Pool) put_conn(fd int)
Purpose
Method on `&Pool`: put connection.
Parameters
p &Pool- receiver &Pool (borrow)
fd int- file descriptor (int)
(&Pool) put
pub fn (p &Pool) put(c Client)
Purpose
Call `put` on `&Pool`.
Parameters
p &Pool- receiver &Pool (borrow)
c Client- byte or character code (Client)
(&Pool) publish
pub fn (p &Pool) publish(topic string, payload string, qos int) int
Purpose
Call `publish` on `&Pool`. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
topic string- topic (string)
payload string- payload (string)
qos int- qos (int)
Returns
int — a value of this type
(&Pool) close
Purpose
Method on `&Pool`: close the resource.
Parameters
p &Pool- receiver &Pool (borrow)
encode_u16
pub fn encode_u16(n int) string
Purpose
Encode.
Parameters
n int- count, length, or limit (int)
Returns
string — result string
decode_u16
pub fn decode_u16(s &string, off int) int
Purpose
Decode.
Parameters
s &string- source string (borrowed; caller keeps it; type &string)
off int- offset (int)
Returns
int — a value of this type
encode_str
pub fn encode_str(text string) string
Purpose
Encode.
Parameters
text string- text (string)
Returns
string — result string
encode_var_len
pub fn encode_var_len(val int) string
Purpose
Encode.
Parameters
val int- value (int)
Returns
string — result string