| | 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 | |
|
| | 9 | | sealed class AmqpSqlFilterCodec : AmqpFilterCodec |
| | 10 | | { |
| 0 | 11 | | public static readonly string Name = AmqpConstants.Vendor + ":sql-filter:list"; |
| | 12 | | public const ulong Code = 0x000001370000006; |
| | 13 | | const int Fields = 2; |
| | 14 | |
|
| 0 | 15 | | public AmqpSqlFilterCodec() : base(Name, Code) { } |
| | 16 | |
|
| 0 | 17 | | public string Expression { get; set; } |
| | 18 | |
|
| 0 | 19 | | public int? CompatibilityLevel { get; set; } |
| | 20 | |
|
| 0 | 21 | | protected override int FieldCount => Fields; |
| | 22 | |
|
| | 23 | | public override string ToString() |
| | 24 | | { |
| 0 | 25 | | var stringBuilder = new StringBuilder("sql("); |
| 0 | 26 | | var count = 0; |
| 0 | 27 | | this.AddFieldToString(this.Expression != null, stringBuilder, "expression", this.Expression, ref count); |
| 0 | 28 | | this.AddFieldToString(this.CompatibilityLevel != null, stringBuilder, "level", this.CompatibilityLevel, ref |
| 0 | 29 | | stringBuilder.Append(')'); |
| 0 | 30 | | return stringBuilder.ToString(); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | protected override void OnEncode(ByteBuffer buffer) |
| | 34 | | { |
| 0 | 35 | | AmqpCodec.EncodeString(this.Expression, buffer); |
| 0 | 36 | | AmqpCodec.EncodeInt(this.CompatibilityLevel, buffer); |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | protected override void OnDecode(ByteBuffer buffer, int count) |
| | 40 | | { |
| 0 | 41 | | if (count-- > 0) |
| | 42 | | { |
| 0 | 43 | | this.Expression = AmqpCodec.DecodeString(buffer); |
| | 44 | | } |
| | 45 | |
|
| 0 | 46 | | if (count > 0) |
| | 47 | | { |
| 0 | 48 | | this.CompatibilityLevel = AmqpCodec.DecodeInt(buffer); |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | protected override int OnValueSize() |
| | 53 | | { |
| 0 | 54 | | return AmqpCodec.GetStringEncodeSize(this.Expression) + |
| 0 | 55 | | AmqpCodec.GetIntEncodeSize(this.CompatibilityLevel); |
| | 56 | | } |
| | 57 | | } |
| | 58 | |
|
| | 59 | | } |