예제 #1
0
            public async Task <T> DecodeAsync <T>(CancellationToken cancellationToken = default(CancellationToken))
            {
                if (_codec.Wrap)
                {
                    await Multicodec.ConsumeHeaderAsync(_stream, _codec.Header, cancellationToken);
                }

                var hdr = await Multicodec.PeekHeaderAsync(_stream, cancellationToken);

                if (hdr == null || hdr.Length == 0)
                {
                    throw new EndOfStreamException();
                }

                var subcodec = _codec._codecs.SingleOrDefault(c => c.Header.SequenceEqual(hdr));

                if (subcodec == null)
                {
                    throw new Exception($"no codec found for {Encoding.UTF8.GetString(hdr)}");
                }

                _codec.Last = subcodec;

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

                return(CBORObject.Read(_stream).ToObject <T>());
            }
예제 #3
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;
            }
예제 #4
0
            public async Task <T> DecodeAsync <T>(CancellationToken cancellationToken)
            {
                if (_codec._multicodec)
                {
                    await Multicodec.ConsumeHeaderAsync(_stream, _codec.Header, cancellationToken);
                }

                var cbor = CBORObject.Read(_stream);

                return(JsonConvert.DeserializeObject <T>(cbor.ToJSONString()));
            }
예제 #5
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));
            }
예제 #6
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);
            }