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