| | 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 | |
|
| | 7 | | namespace Azure.Messaging.ServiceBus.Amqp.Framing |
| | 8 | | { |
| | 9 | | internal sealed class AmqpSqlRuleFilterCodec : AmqpRuleFilterCodec |
| | 10 | | { |
| | 11 | | public const string Name = AmqpConstants.Vendor + ":sql-filter:list"; |
| | 12 | | public const ulong Code = 0x000001370000006; |
| | 13 | | private const int Fields = 2; |
| | 14 | |
|
| 0 | 15 | | public AmqpSqlRuleFilterCodec() : 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 | | AddFieldToString(Expression != null, stringBuilder, "expression", Expression, ref count); |
| 0 | 28 | | AddFieldToString(CompatibilityLevel != null, stringBuilder, "level", CompatibilityLevel, ref count); |
| 0 | 29 | | stringBuilder.Append(')'); |
| 0 | 30 | | return stringBuilder.ToString(); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | protected override void OnEncode(ByteBuffer buffer) |
| | 34 | | { |
| 0 | 35 | | AmqpCodec.EncodeString(Expression, buffer); |
| 0 | 36 | | AmqpCodec.EncodeInt(CompatibilityLevel, buffer); |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | protected override void OnDecode(ByteBuffer buffer, int count) |
| | 40 | | { |
| 0 | 41 | | if (count-- > 0) |
| | 42 | | { |
| 0 | 43 | | Expression = AmqpCodec.DecodeString(buffer); |
| | 44 | | } |
| | 45 | |
|
| 0 | 46 | | if (count > 0) |
| | 47 | | { |
| 0 | 48 | | CompatibilityLevel = AmqpCodec.DecodeInt(buffer); |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | protected override int OnValueSize() |
| | 53 | | { |
| 0 | 54 | | return AmqpCodec.GetStringEncodeSize(Expression) + |
| 0 | 55 | | AmqpCodec.GetIntEncodeSize(CompatibilityLevel); |
| | 56 | | } |
| | 57 | | } |
| | 58 | | } |