]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/netcore/Thrift/Protocols/Utilities/TProtocolUtil.cs
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / netcore / Thrift / Protocols / Utilities / TProtocolUtil.cs
CommitLineData
f67539c2
TL
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
18using System.Threading;
19using System.Threading.Tasks;
20using Thrift.Protocols.Entities;
21
22namespace Thrift.Protocols.Utilities
23{
24 // ReSharper disable once InconsistentNaming
25 public static class TProtocolUtil
26 {
27 public static async Task SkipAsync(TProtocol protocol, TType type, CancellationToken cancellationToken)
28 {
29 if (cancellationToken.IsCancellationRequested)
30 {
31 await Task.FromCanceled(cancellationToken);
32 }
33
34 protocol.IncrementRecursionDepth();
35 try
36 {
37 switch (type)
38 {
39 case TType.Bool:
40 await protocol.ReadBoolAsync(cancellationToken);
41 break;
42 case TType.Byte:
43 await protocol.ReadByteAsync(cancellationToken);
44 break;
45 case TType.I16:
46 await protocol.ReadI16Async(cancellationToken);
47 break;
48 case TType.I32:
49 await protocol.ReadI32Async(cancellationToken);
50 break;
51 case TType.I64:
52 await protocol.ReadI64Async(cancellationToken);
53 break;
54 case TType.Double:
55 await protocol.ReadDoubleAsync(cancellationToken);
56 break;
57 case TType.String:
58 // Don't try to decode the string, just skip it.
59 await protocol.ReadBinaryAsync(cancellationToken);
60 break;
61 case TType.Struct:
62 await protocol.ReadStructBeginAsync(cancellationToken);
63 while (true)
64 {
65 var field = await protocol.ReadFieldBeginAsync(cancellationToken);
66 if (field.Type == TType.Stop)
67 {
68 break;
69 }
70 await SkipAsync(protocol, field.Type, cancellationToken);
71 await protocol.ReadFieldEndAsync(cancellationToken);
72 }
73 await protocol.ReadStructEndAsync(cancellationToken);
74 break;
75 case TType.Map:
76 var map = await protocol.ReadMapBeginAsync(cancellationToken);
77 for (var i = 0; i < map.Count; i++)
78 {
79 await SkipAsync(protocol, map.KeyType, cancellationToken);
80 await SkipAsync(protocol, map.ValueType, cancellationToken);
81 }
82 await protocol.ReadMapEndAsync(cancellationToken);
83 break;
84 case TType.Set:
85 var set = await protocol.ReadSetBeginAsync(cancellationToken);
86 for (var i = 0; i < set.Count; i++)
87 {
88 await SkipAsync(protocol, set.ElementType, cancellationToken);
89 }
90 await protocol.ReadSetEndAsync(cancellationToken);
91 break;
92 case TType.List:
93 var list = await protocol.ReadListBeginAsync(cancellationToken);
94 for (var i = 0; i < list.Count; i++)
95 {
96 await SkipAsync(protocol, list.ElementType, cancellationToken);
97 }
98 await protocol.ReadListEndAsync(cancellationToken);
99 break;
100 default:
101 throw new TProtocolException(TProtocolException.INVALID_DATA, "Unknown data type " + type.ToString("d"));
102 }
103 }
104 finally
105 {
106 protocol.DecrementRecursionDepth();
107 }
108 }
109 }
110}