Пример #1
0
        public async Task ReadString()
        {
            await _Protocol.WriteStringAsync("Thrift String Benchmark");

            for (int i = 0; i < NumberOfOperationsPerIteration; i++)
            {
                _Stream.Seek(0, SeekOrigin.Begin);

                await _Protocol.ReadStringAsync();
            }
        }
Пример #2
0
        async Task <string> GetJsonFromThrift(byte[] bytes)
        {
            try
            {
                var _memoryBufferTransport = new TMemoryBufferTransport(bytes, new TConfiguration());
                var _thrift = new TCompactProtocol(_memoryBufferTransport);
                while (true)
                {
                    var field = await _thrift.ReadFieldBeginAsync(CancellationToken.None);

                    if (field.Type == TType.Stop)
                    {
                        break;
                    }

                    if (field.Type == TType.String)
                    {
                        var str = await _thrift.ReadStringAsync(CancellationToken.None);

                        if (!string.IsNullOrEmpty(str))
                        {
                            if (str.StartsWith("{") && str.EndsWith("}"))
                            {
                                return(str);
                            }
                        }
                    }
                    await _thrift.ReadFieldEndAsync(CancellationToken.None);
                }
            }
            catch { }
            var json = Encoding.UTF8.GetString(bytes);

            try
            {
                if (json.Contains("{") && json.Contains("}"))
                {
                    var str = json.Substring(json.IndexOf("{"));
                    str = str.Substring(0, str.LastIndexOf("}") + 1);
                    return(str);
                }
            }
            catch { }
            return(json);
        }