From 108c8fc183856d53fe277ab2954d14e283729ba7 Mon Sep 17 00:00:00 2001 From: JKorf Date: Thu, 21 Mar 2024 21:34:15 +0100 Subject: [PATCH] Small fixes --- .../Converters/JsonNet/JsonNetMessageAccessor.cs | 5 +++-- .../Converters/SystemTextJson/EnumConverter.cs | 2 ++ .../SystemTextJson/SystemTextJsonMessageAccessor.cs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs b/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs index 240763ac..e19903b0 100644 --- a/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs +++ b/CryptoExchange.Net/Converters/JsonNet/JsonNetMessageAccessor.cs @@ -243,8 +243,9 @@ public async Task Read(Stream stream, bool bufferStream) // We don't need to buffer the stream, so don't bother keeping the reference } - var length = stream.CanSeek ? stream.Length : 4096; - using var reader = new StreamReader(stream, Encoding.UTF8, false, (int)Math.Max(2, length), true); + var readStream = _stream ?? stream; + var length = readStream.CanSeek ? readStream.Length : 4096; + using var reader = new StreamReader(readStream, Encoding.UTF8, false, (int)Math.Max(2, length), true); using var jsonTextReader = new JsonTextReader(reader); try diff --git a/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs b/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs index d5a14f68..29126ca0 100644 --- a/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs +++ b/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs @@ -92,6 +92,8 @@ public EnumConverterInner(bool writeAsInt, bool warnOnMissingEntry) { JsonTokenType.String => reader.GetString(), JsonTokenType.Number => reader.GetInt16().ToString(), + JsonTokenType.True => "true", + JsonTokenType.False => "false", _ => null }; diff --git a/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs b/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs index 3910896b..7a26c5cd 100644 --- a/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs +++ b/CryptoExchange.Net/Converters/SystemTextJson/SystemTextJsonMessageAccessor.cs @@ -219,7 +219,7 @@ public async Task Read(Stream stream, bool bufferStream) try { - _document = await JsonDocument.ParseAsync(stream).ConfigureAwait(false); + _document = await JsonDocument.ParseAsync(_stream ?? stream).ConfigureAwait(false); IsJson = true; } catch (Exception)