public async ValueTask <GatewayPayloadJsonModel> ReceiveAsync(CancellationToken cancellationToken)
        {
            var jsonStream = await _ws.ReceiveAsync(cancellationToken).ConfigureAwait(false);

            if (LogsPayloads)
            {
                var stream = new MemoryStream();
                await jsonStream.CopyToAsync(stream, cancellationToken).ConfigureAwait(false);

                Logger.LogTrace("Received payload: {0}", Encoding.UTF8.GetString(stream.GetBuffer()));
                stream.Position = 0;
                jsonStream      = stream;
            }

            return(Serializer.Deserialize <GatewayPayloadJsonModel>(jsonStream));
        }
Beispiel #2
0
        public async ValueTask <GatewayPayloadJsonModel> ReceiveAsync(CancellationToken cancellationToken = default)
        {
            // TODO: optimise the streams
            var jsonStream = await _ws.ReceiveAsync(cancellationToken).ConfigureAwait(false);

            if (jsonStream is not MemoryStream memoryStream || !memoryStream.TryGetBuffer(out var json))
            {
                memoryStream = new MemoryStream();
                jsonStream.CopyTo(memoryStream);
                memoryStream.TryGetBuffer(out json);
            }

            if (LogsPayloads)
            {
                Logger.LogTrace("Received payload: {0}", Encoding.UTF8.GetString(json));
            }

            return(Serializer.Deserialize <GatewayPayloadJsonModel>(json));
        }