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