Esempio n. 1
0
        public async Task ReadAsync(Thrift.Protocols.TProtocol protocol)
        {
            await protocol.ReadStructBeginAsync();

            var field = await protocol.ReadFieldBeginAsync();

            while (field.Type != TType.Stop)
            {
                if (field.ID == 1)
                {
                    if (field.Type == TType.Struct)
                    {
                        SessionId = new HandleIdentifier();
                        await SessionId.ReadAsync(protocol);
                    }
                    else
                    {
                        await TProtocolUtil.SkipAsync(protocol, field.Type, CancellationToken.None);
                    }
                }
                else
                {
                    await TProtocolUtil.SkipAsync(protocol, field.Type, CancellationToken.None);
                }
                await protocol.ReadFieldEndAsync();

                field = await protocol.ReadFieldBeginAsync();
            }

            await protocol.ReadStructEndAsync();
        }
Esempio n. 2
0
        public static async Task SkipAsync(TProtocol prot, TType type, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                await Task.FromCanceled(cancellationToken);
            }

            prot.IncrementRecursionDepth();
            try
            {
                switch (type)
                {
                case TType.Bool:
                    await prot.ReadBoolAsync(cancellationToken);

                    break;

                case TType.Byte:
                    await prot.ReadByteAsync(cancellationToken);

                    break;

                case TType.I16:
                    await prot.ReadI16Async(cancellationToken);

                    break;

                case TType.I32:
                    await prot.ReadI32Async(cancellationToken);

                    break;

                case TType.I64:
                    await prot.ReadI64Async(cancellationToken);

                    break;

                case TType.Double:
                    await prot.ReadDoubleAsync(cancellationToken);

                    break;

                case TType.String:
                    // Don't try to decode the string, just skip it.
                    await prot.ReadBinaryAsync(cancellationToken);

                    break;

                case TType.Struct:
                    await prot.ReadStructBeginAsync(cancellationToken);

                    while (true)
                    {
                        var field = await prot.ReadFieldBeginAsync(cancellationToken);

                        if (field.Type == TType.Stop)
                        {
                            break;
                        }
                        await SkipAsync(prot, field.Type, cancellationToken);

                        await prot.ReadFieldEndAsync(cancellationToken);
                    }
                    await prot.ReadStructEndAsync(cancellationToken);

                    break;

                case TType.Map:
                    var map = await prot.ReadMapBeginAsync(cancellationToken);

                    for (var i = 0; i < map.Count; i++)
                    {
                        await SkipAsync(prot, map.KeyType, cancellationToken);
                        await SkipAsync(prot, map.ValueType, cancellationToken);
                    }
                    await prot.ReadMapEndAsync(cancellationToken);

                    break;

                case TType.Set:
                    var set = await prot.ReadSetBeginAsync(cancellationToken);

                    for (var i = 0; i < set.Count; i++)
                    {
                        await SkipAsync(prot, set.ElementType, cancellationToken);
                    }
                    await prot.ReadSetEndAsync(cancellationToken);

                    break;

                case TType.List:
                    var list = await prot.ReadListBeginAsync(cancellationToken);

                    for (var i = 0; i < list.Count; i++)
                    {
                        await SkipAsync(prot, list.ElementType, cancellationToken);
                    }
                    await prot.ReadListEndAsync(cancellationToken);

                    break;

                default:
                    throw new TProtocolException(TProtocolException.INVALID_DATA, "Unknown data type " + type.ToString("d"));
                }
            }
            finally
            {
                prot.DecrementRecursionDepth();
            }
        }
 public override async Task ReadStructEndAsync(CancellationToken cancellationToken)
 {
     await _wrappedProtocol.ReadStructEndAsync(cancellationToken);
 }