Example #1
0
            public async Task<T> DecodeAsync<T>(CancellationToken cancellationToken)
            {
                if (_codec._multicodec)
                    await Multicodec.ConsumeHeaderAsync(_stream, _codec.Header, cancellationToken);

                var bytes = await MessageIo.ReadMessageAsync(_stream, cancellationToken);

                return (T)(object)bytes;
            }
Example #2
0
            public async Task <T> DecodeAsync <T>(CancellationToken cancellationToken = default(CancellationToken))
            {
                if (_codec._multicodec)
                {
                    await Multicodec.ConsumeHeaderAsync(_stream, _codec.Header, cancellationToken);
                }

                if (_codec._msgio)
                {
                    return(Deserialize <T>(await MessageIo.ReadMessageAsync(_stream, cancellationToken)));
                }

                return(ProtoBuf.Serializer.DeserializeWithLengthPrefix <T>(_stream, PrefixStyle.Fixed32BigEndian));
            }
Example #3
0
            public async Task<T> DecodeAsync<T>(CancellationToken cancellationToken)
            {
                if (_codec._multicodec)
                    await Multicodec.ConsumeHeaderAsync(_stream, _codec.Header, cancellationToken);

                var json = string.Empty;
                if (_codec._msgio)
                {
                    var bytes = await MessageIo.ReadMessageAsync(_stream, cancellationToken);
                    json = Encoding.UTF8.GetString(bytes);
                }
                else
                {
                    json = await ReadLineAsync(_stream, cancellationToken);
                }

                return JsonConvert.DeserializeObject<T>(json);
            }