moonbit-mqtt

MQTT 3.1.1 packet codec helpers for MoonBit without transport or client runtime

mqtt
iot
codec
protocol
moonbit
moon add zbhzs1/moonbit-mqtt@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
last month
Downloads
8
README

#zbhzs1/moonbit-mqtt

MQTT 3.1.1 packet codec helpers for MoonBit.

This package focuses on byte-level encode/decode helpers. It does not implement network transport, a client runtime, broker sessions, TLS, or MQTT 5.0.

#
Connack

pub(all) struct Connack {
session_present : Bool
return_code : ConnackReturnCode
} derive(
Debug
)

#
ConnackReturnCode

pub(all) enum ConnackReturnCode {
ConnectionAccepted
UnacceptableProtocolVersion
IdentifierRejected
ServerUnavailable
BadUserNameOrPassword
NotAuthorized
} derive(Eq,
Debug
)

#
Connect

pub(all) struct Connect {
client_id : String
username : String?
password : Bytes?
will_topic : String?
will_message : Bytes?
keep_alive : Int
flags : ConnectFlags
} derive(
Debug
)

#
ConnectFlags

pub(all) struct ConnectFlags {
username : Bool
password : Bool
will_retain : Bool
will_qos : QoS
will_flag : Bool
clean_session : Bool
} derive(
Debug
)

#
FixedHeader

pub(all) struct FixedHeader {
message_type : MessageType
dup : Bool
qos : QoS
retain : Bool
remaining_length : Int
header_len : Int
} derive(
Debug
)

#
MessageType

pub(all) enum MessageType {
CONNECT
CONNACK
PUBLISH
PUBACK
PUBREC
PUBREL
PUBCOMP
SUBSCRIBE
SUBACK
UNSUBSCRIBE
UNSUBACK
PINGREQ
PINGRESP
DISCONNECT
} derive(Eq,
Debug
)

#
Packet

pub(all) enum Packet {
ConnectPacket(Connect)
ConnackPacket(Connack)
PublishPacket(Publish)
PubackPacket(PacketId)
PubrecPacket(PacketId)
PubrelPacket(PacketId)
PubcompPacket(PacketId)
SubscribePacket(Subscribe)
SubackPacket(Suback)
UnsubscribePacket(Unsubscribe)
UnsubackPacket(Unsuback)
PingreqPacket
PingrespPacket
DisconnectPacket
} derive(
Debug
)

#
PacketId

pub(all) struct PacketId {
message_id : Int
} derive(
Debug
)

#
Publish

pub(all) struct Publish {
topic : String
payload : Bytes
qos : QoS
message_id : Int?
retain : Bool
dup : Bool
} derive(
Debug
)

#
QoS

pub(all) enum QoS {
QoS0
QoS1
QoS2
} derive(Eq,
Debug
)

#
Suback

pub(all) struct Suback {
message_id : Int
return_codes : Array[SubackReturnCode]
} derive(
Debug
)

#
SubackReturnCode

pub(all) enum SubackReturnCode {
SuccessQoS0
SuccessQoS1
SuccessQoS2
Failure
} derive(Eq,
Debug
)

#
Subscribe

pub(all) struct Subscribe {
topics : Array[SubscribeTopic]
message_id : Int
} derive(
Debug
)

#
SubscribeTopic

pub(all) struct SubscribeTopic {
topic : String
qos : QoS
} derive(
Debug
)

#
Unsuback

pub(all) struct Unsuback {
message_id : Int
} derive(
Debug
)

#
Unsubscribe

pub(all) struct Unsubscribe {
topics : Array[String]
message_id : Int
} derive(
Debug
)

#
decode_binary

fn decode_binary(bytes : Array[Byte], offset : Int) -> Result[(Bytes, Int), String]

#
decode_connack

fn decode_connack(bytes : Array[Byte]) -> Result[Connack, String]

#
decode_connect

fn decode_connect(bytes : Array[Byte]) -> Result[Connect, String]

#
decode_disconnect

fn decode_disconnect(bytes : Array[Byte]) -> Result[Unit, String]

#
decode_fixed_header

fn decode_fixed_header(bytes : Array[Byte]) -> Result[FixedHeader, String]

#
decode_packet

fn decode_packet(bytes : Array[Byte]) -> Result[Packet, String]

#
decode_pingreq

fn decode_pingreq(bytes : Array[Byte]) -> Result[Unit, String]

#
decode_pingresp

fn decode_pingresp(bytes : Array[Byte]) -> Result[Unit, String]

#
decode_puback

fn decode_puback(bytes : Array[Byte]) -> Result[PacketId, String]

#
decode_pubcomp

fn decode_pubcomp(bytes : Array[Byte]) -> Result[PacketId, String]

#
decode_publish

fn decode_publish(bytes : Array[Byte]) -> Result[Publish, String]

#
decode_pubrec

fn decode_pubrec(bytes : Array[Byte]) -> Result[PacketId, String]

#
decode_pubrel

fn decode_pubrel(bytes : Array[Byte]) -> Result[PacketId, String]

#
decode_remaining_length

fn decode_remaining_length(bytes : Array[Byte], offset : Int) -> Result[(Int, Int), String]

#
decode_string

fn decode_string(bytes : Array[Byte], offset : Int) -> Result[(String, Int), String]

#
decode_suback

fn decode_suback(bytes : Array[Byte]) -> Result[Suback, String]

#
decode_subscribe

fn decode_subscribe(bytes : Array[Byte]) -> Result[Subscribe, String]

#
decode_unsuback

fn decode_unsuback(bytes : Array[Byte]) -> Result[Unsuback, String]

#
decode_unsubscribe

fn decode_unsubscribe(bytes : Array[Byte]) -> Result[Unsubscribe, String]

#
encode_binary

fn encode_binary(value : Bytes) -> Result[Array[Byte], String]

#
encode_connack

fn encode_connack(connack : Connack) -> Result[Array[Byte], String]

#
encode_connect

fn encode_connect(connect : Connect) -> Result[Array[Byte], String]

#
encode_disconnect

fn encode_disconnect() -> Result[Array[Byte], String]

#
encode_packet

fn encode_packet(packet : Packet) -> Result[Array[Byte], String]

#
encode_pingreq

fn encode_pingreq() -> Result[Array[Byte], String]

#
encode_pingresp

fn encode_pingresp() -> Result[Array[Byte], String]

#
encode_puback

fn encode_puback(message_id : Int) -> Result[Array[Byte], String]

#
encode_pubcomp

fn encode_pubcomp(message_id : Int) -> Result[Array[Byte], String]

#
encode_publish

fn encode_publish(publish : Publish) -> Result[Array[Byte], String]

#
encode_pubrec

fn encode_pubrec(message_id : Int) -> Result[Array[Byte], String]

#
encode_pubrel

fn encode_pubrel(message_id : Int) -> Result[Array[Byte], String]

#
encode_remaining_length

fn encode_remaining_length(length : Int) -> Result[Array[Byte], String]

#
encode_string

fn encode_string(value : String) -> Result[Array[Byte], String]

#
encode_suback

fn encode_suback(suback : Suback) -> Result[Array[Byte], String]

#
encode_subscribe

fn encode_subscribe(subscribe : Subscribe) -> Result[Array[Byte], String]

#
encode_unsuback

fn encode_unsuback(message_id : Int) -> Result[Array[Byte], String]

#
encode_unsubscribe

fn encode_unsubscribe(unsubscribe : Unsubscribe) -> Result[Array[Byte], String]

#
has_complete_packet

fn has_complete_packet(bytes : Array[Byte]) -> Bool

#
is_pingresp

fn is_pingresp(bytes : Array[Byte]) -> Bool

#
packet_total_length

fn packet_total_length(bytes : Array[Byte]) -> Result[Int, String]

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io