| | | 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 AmqpSqlRuleActionCodec : AmqpRuleActionCodec |
| | | 10 | | { |
| | | 11 | | public const string Name = AmqpConstants.Vendor + ":sql-rule-action:list"; |
| | | 12 | | public const ulong Code = 0x0000013700000006; |
| | | 13 | | private 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 | | AddFieldToString(SqlExpression != null, sb, "expression", SqlExpression, ref count); |
| | 0 | 36 | | AddFieldToString(CompatibilityLevel != null, sb, "level", 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(SqlExpression, buffer); |
| | 0 | 44 | | AmqpCodec.EncodeInt(CompatibilityLevel, buffer); |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | protected override void OnDecode(ByteBuffer buffer, int count) |
| | | 48 | | { |
| | 0 | 49 | | if (count-- > 0) |
| | | 50 | | { |
| | 0 | 51 | | SqlExpression = AmqpCodec.DecodeString(buffer); |
| | | 52 | | } |
| | | 53 | | |
| | 0 | 54 | | if (count > 0) |
| | | 55 | | { |
| | 0 | 56 | | CompatibilityLevel = AmqpCodec.DecodeInt(buffer); |
| | | 57 | | } |
| | 0 | 58 | | } |
| | | 59 | | |
| | | 60 | | protected override int OnValueSize() |
| | | 61 | | { |
| | 0 | 62 | | return AmqpCodec.GetStringEncodeSize(SqlExpression) + |
| | 0 | 63 | | AmqpCodec.GetIntEncodeSize(CompatibilityLevel); |
| | | 64 | | } |
| | | 65 | | } |
| | | 66 | | } |