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)); }
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>()); }
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; }
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())); }
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)); }
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); }