| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.ServiceBus.Amqp.Framing |
| | 5 | | { |
| | 6 | | using System.Text; |
| | 7 | | using Azure.Amqp; |
| | 8 | | using Azure.Amqp.Encoding; |
| | 9 | |
|
| | 10 | | sealed class AmqpCorrelationFilterCodec : AmqpFilterCodec |
| | 11 | | { |
| 0 | 12 | | public static readonly string Name = AmqpConstants.Vendor + ":correlation-filter:list"; |
| | 13 | | public const ulong Code = 0x000001370000009; |
| | 14 | | const int Fields = 9; |
| | 15 | |
|
| | 16 | | AmqpMap properties; |
| | 17 | |
|
| 0 | 18 | | public AmqpCorrelationFilterCodec() : base(Name, Code) |
| | 19 | | { |
| 0 | 20 | | this.properties = new AmqpMap(); |
| 0 | 21 | | } |
| | 22 | |
|
| 0 | 23 | | public string CorrelationId { get; set; } |
| | 24 | |
|
| 0 | 25 | | public string MessageId { get; set; } |
| | 26 | |
|
| 0 | 27 | | public string To { get; set; } |
| | 28 | |
|
| 0 | 29 | | public string ReplyTo { get; set; } |
| | 30 | |
|
| 0 | 31 | | public string Label { get; set; } |
| | 32 | |
|
| 0 | 33 | | public string SessionId { get; set; } |
| | 34 | |
|
| 0 | 35 | | public string ReplyToSessionId { get; set; } |
| | 36 | |
|
| 0 | 37 | | public string ContentType { get; set; } |
| | 38 | |
|
| 0 | 39 | | public AmqpMap Properties => this.properties; |
| | 40 | |
|
| 0 | 41 | | protected override int FieldCount => Fields; |
| | 42 | |
|
| | 43 | | public override string ToString() |
| | 44 | | { |
| 0 | 45 | | var stringBuilder = new StringBuilder("correlation("); |
| 0 | 46 | | var count = 0; |
| 0 | 47 | | this.AddFieldToString(this.CorrelationId != null, stringBuilder, "id", this.CorrelationId, ref count); |
| 0 | 48 | | stringBuilder.Append(')'); |
| 0 | 49 | | return stringBuilder.ToString(); |
| | 50 | | } |
| | 51 | |
|
| | 52 | | protected override void OnEncode(ByteBuffer buffer) |
| | 53 | | { |
| 0 | 54 | | AmqpCodec.EncodeString(this.CorrelationId, buffer); |
| 0 | 55 | | AmqpCodec.EncodeString(this.MessageId, buffer); |
| 0 | 56 | | AmqpCodec.EncodeString(this.To, buffer); |
| 0 | 57 | | AmqpCodec.EncodeString(this.ReplyTo, buffer); |
| 0 | 58 | | AmqpCodec.EncodeString(this.Label, buffer); |
| 0 | 59 | | AmqpCodec.EncodeString(this.SessionId, buffer); |
| 0 | 60 | | AmqpCodec.EncodeString(this.ReplyToSessionId, buffer); |
| 0 | 61 | | AmqpCodec.EncodeString(this.ContentType, buffer); |
| 0 | 62 | | AmqpCodec.EncodeMap(this.properties, buffer); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | protected override void OnDecode(ByteBuffer buffer, int count) |
| | 66 | | { |
| 0 | 67 | | if (count-- > 0) |
| | 68 | | { |
| 0 | 69 | | this.CorrelationId = AmqpCodec.DecodeString(buffer); |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | if (count-- > 0) |
| | 73 | | { |
| 0 | 74 | | this.MessageId = AmqpCodec.DecodeString(buffer); |
| | 75 | | } |
| | 76 | |
|
| 0 | 77 | | if (count-- > 0) |
| | 78 | | { |
| 0 | 79 | | this.To = AmqpCodec.DecodeString(buffer); |
| | 80 | | } |
| | 81 | |
|
| 0 | 82 | | if (count-- > 0) |
| | 83 | | { |
| 0 | 84 | | this.ReplyTo = AmqpCodec.DecodeString(buffer); |
| | 85 | | } |
| | 86 | |
|
| 0 | 87 | | if (count-- > 0) |
| | 88 | | { |
| 0 | 89 | | this.Label = AmqpCodec.DecodeString(buffer); |
| | 90 | | } |
| | 91 | |
|
| 0 | 92 | | if (count-- > 0) |
| | 93 | | { |
| 0 | 94 | | this.SessionId = AmqpCodec.DecodeString(buffer); |
| | 95 | | } |
| | 96 | |
|
| 0 | 97 | | if (count-- > 0) |
| | 98 | | { |
| 0 | 99 | | this.ReplyToSessionId = AmqpCodec.DecodeString(buffer); |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | if (count-- > 0) |
| | 103 | | { |
| 0 | 104 | | this.ContentType = AmqpCodec.DecodeString(buffer); |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | if (count > 0) |
| | 108 | | { |
| 0 | 109 | | this.properties = AmqpCodec.DecodeMap(buffer); |
| | 110 | | } |
| 0 | 111 | | } |
| | 112 | |
|
| | 113 | | protected override int OnValueSize() |
| | 114 | | { |
| 0 | 115 | | return AmqpCodec.GetStringEncodeSize(this.CorrelationId) + |
| 0 | 116 | | AmqpCodec.GetStringEncodeSize(this.MessageId) + |
| 0 | 117 | | AmqpCodec.GetStringEncodeSize(this.To) + |
| 0 | 118 | | AmqpCodec.GetStringEncodeSize(this.ReplyTo) + |
| 0 | 119 | | AmqpCodec.GetStringEncodeSize(this.Label) + |
| 0 | 120 | | AmqpCodec.GetStringEncodeSize(this.SessionId) + |
| 0 | 121 | | AmqpCodec.GetStringEncodeSize(this.ReplyToSessionId) + |
| 0 | 122 | | AmqpCodec.GetStringEncodeSize(this.ContentType) + |
| 0 | 123 | | AmqpCodec.GetMapEncodeSize(this.properties); |
| | 124 | | } |
| | 125 | | } |
| | 126 | | } |