-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMQTTOperationBinding.cs
More file actions
63 lines (54 loc) · 2.26 KB
/
Copy pathMQTTOperationBinding.cs
File metadata and controls
63 lines (54 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
namespace ByteBard.AsyncAPI.Bindings.MQTT
{
using System;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using ByteBard.AsyncAPI.Writers;
/// <summary>
/// Binding class for MQTT operations.
/// </summary>
public class MQTTOperationBinding : OperationBinding<MQTTOperationBinding>
{
/// <summary>
/// Defines the Quality of Service (QoS) levels for the message flow between client and server.
/// Its value MUST be either 0 (At most once delivery), 1 (At least once delivery), or 2 (Exactly once delivery).
/// </summary>
public int QoS { get; set; }
/// <summary>
/// Whether the broker should retain the message or not.
/// </summary>
public bool Retain { get; set; }
/// <summary>
/// Interval in seconds or a Schema Object containing the definition of the lifetime of the message.
/// </summary>
public int? MessageExpiryInterval { get; set; }
public override string BindingKey => "mqtt";
protected override FixedFieldMap<MQTTOperationBinding> FixedFieldMap => new()
{
{ "qos", (a, n) => { a.QoS = n.GetIntegerValue(); } },
{ "retain", (a, n) => { a.Retain = n.GetBooleanValue(); } },
{ "messageExpiryInterval", (a, n) => { a.MessageExpiryInterval = n.GetIntegerValueOrDefault(); } },
};
public override void SerializeV2(IAsyncApiWriter writer)
{
this.SerializeV3(writer);
}
public override void SerializeV3(IAsyncApiWriter writer)
{
this.SerializeProperties(writer);
}
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
writer.WriteRequiredProperty("qos", this.QoS);
writer.WriteRequiredProperty("retain", this.Retain);
writer.WriteOptionalProperty("messageExpiryInterval", this.MessageExpiryInterval);
writer.WriteOptionalProperty("bindingVersion", this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}