-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMQTTMessageBinding.cs
More file actions
63 lines (55 loc) · 2.55 KB
/
MQTTMessageBinding.cs
File metadata and controls
63 lines (55 loc) · 2.55 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.Models;
using ByteBard.AsyncAPI.Readers;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using ByteBard.AsyncAPI.Writers;
/// <summary>
/// Binding class for MQTT messages.
/// </summary>
public class MQTTMessageBinding : MessageBinding<MQTTMessageBinding>
{
/// <summary>
/// Indicates the format of the payload.
/// Either: 0 (zero) for unspecified bytes, or 1 for UTF-8 encoded character data.
/// </summary>
public int? PayloadFormatIndicator { get; set; }
/// <summary>
/// Correlation Data is used to identify the request the response message is for.
/// </summary>
public AsyncApiJsonSchema CorrelationData { get; set; }
/// <summary>
/// String describing the content type of the message payload.
/// This should not conflict with the contentType field of the associated AsyncAPI Message object.
/// </summary>
public string ContentType { get; set; }
/// <summary>
/// The topic (channel URI) for a response message.
/// </summary>
public string ResponseTopic { get; set; }
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
writer.WriteOptionalProperty("payloadFormatIndicator", this.PayloadFormatIndicator);
writer.WriteOptionalObject("correlationData", this.CorrelationData, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty("contentType", this.ContentType);
writer.WriteOptionalProperty("responseTopic", this.ResponseTopic);
writer.WriteOptionalProperty("bindingVersion", this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
public override string BindingKey => "mqtt";
protected override FixedFieldMap<MQTTMessageBinding> FixedFieldMap => new()
{
{ "payloadFormatIndicator", (a, n) => { a.PayloadFormatIndicator = n.GetIntegerValueOrDefault(); } },
{ "correlationData", (a, n) => { a.CorrelationData = AsyncApiJsonSchemaDeserializer.LoadSchema(n); } },
{ "contentType", (a, n) => { a.ContentType = n.GetScalarValue(); } },
{ "responseTopic", (a, n) => { a.ResponseTopic = n.GetScalarValue(); } },
};
}
}