Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt5 enums #235

Merged
merged 86 commits into from
Mar 25, 2024
Merged

Mqtt5 enums #235

merged 86 commits into from
Mar 25, 2024

Conversation

sbSteveK
Copy link
Contributor

@sbSteveK sbSteveK commented Feb 20, 2024

First pass of Mqtt5 enums, classes, and callbacks.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@xiazhvera xiazhvera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data classes looks good to me. I left some comments worthy discussions.

While it is a huge file, would we like to put them in separate files? For example, we could put data types in Mqtt5Types.swift, and packets in Mqtt5Packets.swift. I'm not sure what is the best practice in swift yet, but it is worthy thinking about.

I realized we probably would need other data structs for the complete callbacks. As an example, we have PublishCompletionData in python for Publish() results. I also wanna clarify that we might add new data classes in the future for those cases.


// TODO WebSocket implementation
/// This callback allows a custom transformation of the HTTP request that acts as the websocket handshake. Websockets will be used if this is set to a valid transformation callback. To use websockets but not perform a transformation, just set this as a trivial completion callback. If None, the connection will be made with direct MQTT.
// var websocketHandshakeTransform: Callable[[WebsocketHandshakeTransformArgs], None] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any concern about websocketHandshakeTransform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't dug into it yet. I was thinking about digging into it once we have normal connections succeeding. What concerns do you mean?

Comment on lines 582 to 583
/// The payload of the publish message in a byte buffer format
var payload: Data?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debatable: "Data?" leads to two different ways of having empty data: nil vs Data(). Perhaps just default this to Data() to indicate that it is not required, instead of making it nullable if it makes sense from API perspective.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with String? and others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked on implementation on what is okay to have as empty/default vs. nil and the optionals are that way because they are truly either there or not there on a received packet. Customers should be using a nil check before attempting to access them because depending on whether it exists or not can make a difference in how they handle those packets.

In the direction of customer created packets/options/etc, they can set them but would not need to access them afterwards and we will check and apply defaults after they are bound to native and processed by the client there. We should not be applying native level defaults to swift level properties.

Comment on lines 994 to 995
/// The time interval to wait after sending a CONNECT request for a CONNACK to arrive. If one does not arrive, the connection will be shut down.
var connackTimeoutMs: UInt32?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, probably easier to just default this to 0 instead of nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Once the customer sets (or doesn't set) these values at creation of the object, they will not need to access them again so keeping them nil works for binding them as optional into the native client. The native client will process and apply any defaults as necessary at that point.

var keepAliveIntervalSec: UInt16?

/// A unique string identifying the client to the server. Used to restore session state between connections. If left empty, the broker will auto-assign a unique client id. When reconnecting, the mqtt5 client will always use the auto-assigned client id.
var clientId: String?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember IoT had a bug with auto-assigned client id. Should we force assign a id for now to work around it?

Copy link
Contributor Author

@sbSteveK sbSteveK Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember something like that but I also think if you don't provide a clientId in MQTT5, the broker assigns one to you and you get it back in the negotiated settings. Maybe it was an MQTT3 specific issue.

@sbSteveK sbSteveK merged commit 133f813 into iot Mar 25, 2024
25 checks passed
@sbSteveK sbSteveK deleted the mqtt5-enums branch March 25, 2024 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants