1 // Licensed to the Apache Software Foundation(ASF) under one 2 // or more contributor license agreements.See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership.The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 using System; 19 using System.Threading; 20 using System.Threading.Tasks; 21 using Thrift.Protocol.Entities; 22 23 namespace Thrift.Protocol 24 { 25 // ReSharper disable once InconsistentNaming 26 /// <summary> 27 /// TProtocolDecorator forwards all requests to an enclosed TProtocol instance, 28 /// providing a way to author concise concrete decorator subclasses.While it has 29 /// no abstract methods, it is marked abstract as a reminder that by itself, 30 /// it does not modify the behaviour of the enclosed TProtocol. 31 /// </summary> 32 public abstract class TProtocolDecorator : TProtocol 33 { 34 private readonly TProtocol _wrappedProtocol; 35 TProtocolDecorator(TProtocol protocol)36 protected TProtocolDecorator(TProtocol protocol) 37 : base(protocol.Transport) 38 { 39 _wrappedProtocol = protocol ?? throw new ArgumentNullException(nameof(protocol)); 40 } 41 WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken)42 public override async Task WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken) 43 { 44 await _wrappedProtocol.WriteMessageBeginAsync(message, cancellationToken); 45 } 46 WriteMessageEndAsync(CancellationToken cancellationToken)47 public override async Task WriteMessageEndAsync(CancellationToken cancellationToken) 48 { 49 await _wrappedProtocol.WriteMessageEndAsync(cancellationToken); 50 } 51 52 public override async Task WriteStructBeginAsync(TStruct @struct, CancellationToken cancellationToken) 53 { 54 await _wrappedProtocol.WriteStructBeginAsync(@struct, cancellationToken); 55 } 56 WriteStructEndAsync(CancellationToken cancellationToken)57 public override async Task WriteStructEndAsync(CancellationToken cancellationToken) 58 { 59 await _wrappedProtocol.WriteStructEndAsync(cancellationToken); 60 } 61 WriteFieldBeginAsync(TField field, CancellationToken cancellationToken)62 public override async Task WriteFieldBeginAsync(TField field, CancellationToken cancellationToken) 63 { 64 await _wrappedProtocol.WriteFieldBeginAsync(field, cancellationToken); 65 } 66 WriteFieldEndAsync(CancellationToken cancellationToken)67 public override async Task WriteFieldEndAsync(CancellationToken cancellationToken) 68 { 69 await _wrappedProtocol.WriteFieldEndAsync(cancellationToken); 70 } 71 WriteFieldStopAsync(CancellationToken cancellationToken)72 public override async Task WriteFieldStopAsync(CancellationToken cancellationToken) 73 { 74 await _wrappedProtocol.WriteFieldStopAsync(cancellationToken); 75 } 76 WriteMapBeginAsync(TMap map, CancellationToken cancellationToken)77 public override async Task WriteMapBeginAsync(TMap map, CancellationToken cancellationToken) 78 { 79 await _wrappedProtocol.WriteMapBeginAsync(map, cancellationToken); 80 } 81 WriteMapEndAsync(CancellationToken cancellationToken)82 public override async Task WriteMapEndAsync(CancellationToken cancellationToken) 83 { 84 await _wrappedProtocol.WriteMapEndAsync(cancellationToken); 85 } 86 WriteListBeginAsync(TList list, CancellationToken cancellationToken)87 public override async Task WriteListBeginAsync(TList list, CancellationToken cancellationToken) 88 { 89 await _wrappedProtocol.WriteListBeginAsync(list, cancellationToken); 90 } 91 WriteListEndAsync(CancellationToken cancellationToken)92 public override async Task WriteListEndAsync(CancellationToken cancellationToken) 93 { 94 await _wrappedProtocol.WriteListEndAsync(cancellationToken); 95 } 96 WriteSetBeginAsync(TSet set, CancellationToken cancellationToken)97 public override async Task WriteSetBeginAsync(TSet set, CancellationToken cancellationToken) 98 { 99 await _wrappedProtocol.WriteSetBeginAsync(set, cancellationToken); 100 } 101 WriteSetEndAsync(CancellationToken cancellationToken)102 public override async Task WriteSetEndAsync(CancellationToken cancellationToken) 103 { 104 await _wrappedProtocol.WriteSetEndAsync(cancellationToken); 105 } 106 WriteBoolAsync(bool b, CancellationToken cancellationToken)107 public override async Task WriteBoolAsync(bool b, CancellationToken cancellationToken) 108 { 109 await _wrappedProtocol.WriteBoolAsync(b, cancellationToken); 110 } 111 WriteByteAsync(sbyte b, CancellationToken cancellationToken)112 public override async Task WriteByteAsync(sbyte b, CancellationToken cancellationToken) 113 { 114 await _wrappedProtocol.WriteByteAsync(b, cancellationToken); 115 } 116 WriteI16Async(short i16, CancellationToken cancellationToken)117 public override async Task WriteI16Async(short i16, CancellationToken cancellationToken) 118 { 119 await _wrappedProtocol.WriteI16Async(i16, cancellationToken); 120 } 121 WriteI32Async(int i32, CancellationToken cancellationToken)122 public override async Task WriteI32Async(int i32, CancellationToken cancellationToken) 123 { 124 await _wrappedProtocol.WriteI32Async(i32, cancellationToken); 125 } 126 WriteI64Async(long i64, CancellationToken cancellationToken)127 public override async Task WriteI64Async(long i64, CancellationToken cancellationToken) 128 { 129 await _wrappedProtocol.WriteI64Async(i64, cancellationToken); 130 } 131 WriteDoubleAsync(double d, CancellationToken cancellationToken)132 public override async Task WriteDoubleAsync(double d, CancellationToken cancellationToken) 133 { 134 await _wrappedProtocol.WriteDoubleAsync(d, cancellationToken); 135 } 136 WriteStringAsync(string s, CancellationToken cancellationToken)137 public override async Task WriteStringAsync(string s, CancellationToken cancellationToken) 138 { 139 await _wrappedProtocol.WriteStringAsync(s, cancellationToken); 140 } 141 WriteBinaryAsync(byte[] bytes, CancellationToken cancellationToken)142 public override async Task WriteBinaryAsync(byte[] bytes, CancellationToken cancellationToken) 143 { 144 await _wrappedProtocol.WriteBinaryAsync(bytes, cancellationToken); 145 } 146 WriteUuidAsync(Guid uuid, CancellationToken cancellationToken)147 public override async Task WriteUuidAsync(Guid uuid, CancellationToken cancellationToken) 148 { 149 await _wrappedProtocol.WriteUuidAsync(uuid, cancellationToken); 150 } 151 ReadMessageBeginAsync(CancellationToken cancellationToken)152 public override async ValueTask<TMessage> ReadMessageBeginAsync(CancellationToken cancellationToken) 153 { 154 return await _wrappedProtocol.ReadMessageBeginAsync(cancellationToken); 155 } 156 ReadMessageEndAsync(CancellationToken cancellationToken)157 public override async Task ReadMessageEndAsync(CancellationToken cancellationToken) 158 { 159 cancellationToken.ThrowIfCancellationRequested(); 160 await _wrappedProtocol.ReadMessageEndAsync(cancellationToken); 161 Transport.ResetConsumedMessageSize(); 162 } 163 ReadStructBeginAsync(CancellationToken cancellationToken)164 public override async ValueTask<TStruct> ReadStructBeginAsync(CancellationToken cancellationToken) 165 { 166 return await _wrappedProtocol.ReadStructBeginAsync(cancellationToken); 167 } 168 ReadStructEndAsync(CancellationToken cancellationToken)169 public override async Task ReadStructEndAsync(CancellationToken cancellationToken) 170 { 171 await _wrappedProtocol.ReadStructEndAsync(cancellationToken); 172 } 173 ReadFieldBeginAsync(CancellationToken cancellationToken)174 public override async ValueTask<TField> ReadFieldBeginAsync(CancellationToken cancellationToken) 175 { 176 return await _wrappedProtocol.ReadFieldBeginAsync(cancellationToken); 177 } 178 ReadFieldEndAsync(CancellationToken cancellationToken)179 public override async Task ReadFieldEndAsync(CancellationToken cancellationToken) 180 { 181 await _wrappedProtocol.ReadFieldEndAsync(cancellationToken); 182 } 183 ReadMapBeginAsync(CancellationToken cancellationToken)184 public override async ValueTask<TMap> ReadMapBeginAsync(CancellationToken cancellationToken) 185 { 186 return await _wrappedProtocol.ReadMapBeginAsync(cancellationToken); 187 } 188 ReadMapEndAsync(CancellationToken cancellationToken)189 public override async Task ReadMapEndAsync(CancellationToken cancellationToken) 190 { 191 await _wrappedProtocol.ReadMapEndAsync(cancellationToken); 192 } 193 ReadListBeginAsync(CancellationToken cancellationToken)194 public override async ValueTask<TList> ReadListBeginAsync(CancellationToken cancellationToken) 195 { 196 return await _wrappedProtocol.ReadListBeginAsync(cancellationToken); 197 } 198 ReadListEndAsync(CancellationToken cancellationToken)199 public override async Task ReadListEndAsync(CancellationToken cancellationToken) 200 { 201 await _wrappedProtocol.ReadListEndAsync(cancellationToken); 202 } 203 ReadSetBeginAsync(CancellationToken cancellationToken)204 public override async ValueTask<TSet> ReadSetBeginAsync(CancellationToken cancellationToken) 205 { 206 return await _wrappedProtocol.ReadSetBeginAsync(cancellationToken); 207 } 208 ReadSetEndAsync(CancellationToken cancellationToken)209 public override async Task ReadSetEndAsync(CancellationToken cancellationToken) 210 { 211 await _wrappedProtocol.ReadSetEndAsync(cancellationToken); 212 } 213 ReadBoolAsync(CancellationToken cancellationToken)214 public override async ValueTask<bool> ReadBoolAsync(CancellationToken cancellationToken) 215 { 216 return await _wrappedProtocol.ReadBoolAsync(cancellationToken); 217 } 218 ReadByteAsync(CancellationToken cancellationToken)219 public override async ValueTask<sbyte> ReadByteAsync(CancellationToken cancellationToken) 220 { 221 return await _wrappedProtocol.ReadByteAsync(cancellationToken); 222 } 223 ReadI16Async(CancellationToken cancellationToken)224 public override async ValueTask<short> ReadI16Async(CancellationToken cancellationToken) 225 { 226 return await _wrappedProtocol.ReadI16Async(cancellationToken); 227 } 228 ReadI32Async(CancellationToken cancellationToken)229 public override async ValueTask<int> ReadI32Async(CancellationToken cancellationToken) 230 { 231 return await _wrappedProtocol.ReadI32Async(cancellationToken); 232 } 233 ReadI64Async(CancellationToken cancellationToken)234 public override async ValueTask<long> ReadI64Async(CancellationToken cancellationToken) 235 { 236 return await _wrappedProtocol.ReadI64Async(cancellationToken); 237 } 238 ReadDoubleAsync(CancellationToken cancellationToken)239 public override async ValueTask<double> ReadDoubleAsync(CancellationToken cancellationToken) 240 { 241 return await _wrappedProtocol.ReadDoubleAsync(cancellationToken); 242 } 243 ReadStringAsync(CancellationToken cancellationToken)244 public override async ValueTask<string> ReadStringAsync(CancellationToken cancellationToken) 245 { 246 return await _wrappedProtocol.ReadStringAsync(cancellationToken); 247 } 248 ReadBinaryAsync(CancellationToken cancellationToken)249 public override async ValueTask<byte[]> ReadBinaryAsync(CancellationToken cancellationToken) 250 { 251 return await _wrappedProtocol.ReadBinaryAsync(cancellationToken); 252 } 253 ReadUuidAsync(CancellationToken cancellationToken)254 public override async ValueTask<Guid> ReadUuidAsync(CancellationToken cancellationToken) 255 { 256 return await _wrappedProtocol.ReadUuidAsync(cancellationToken); 257 } 258 259 // Returns the minimum amount of bytes needed to store the smallest possible instance of TType. GetMinSerializedSize(TType type)260 public override int GetMinSerializedSize(TType type) 261 { 262 return _wrappedProtocol.GetMinSerializedSize(type); 263 } 264 265 266 } 267 } 268