Example #1
0
        public ValueTask <int> WritePayloadAsync(ArraySegment <byte> payload, IOBehavior ioBehavior)
        {
            // break the payload up into (possibly more than one) uncompressed packets
            return(ProtocolUtility.WritePayloadAsync(m_uncompressedStreamByteHandler, GetNextUncompressedSequenceNumber, payload, ioBehavior).ContinueWith(_ =>
            {
                if (m_uncompressedStream.Length == 0)
                {
                    return default(ValueTask <int>);
                }

                ArraySegment <byte> uncompressedData;
                if (!m_uncompressedStream.TryGetBuffer(out uncompressedData))
                {
                    throw new InvalidOperationException("Couldn't get uncompressed stream buffer.");
                }

                return CompressAndWrite(uncompressedData, ioBehavior)
                .ContinueWith(__ =>
                {
                    // reset the uncompressed stream to accept more data
                    m_uncompressedStream.SetLength(0);
                    return default(ValueTask <int>);
                });
            }));
        }
Example #2
0
 public ValueTask <int> WritePayloadAsync(ArraySegment <byte> payload, IOBehavior ioBehavior) =>
 ProtocolUtility.WritePayloadAsync(m_byteHandler, GetNextSequenceNumber, payload, ioBehavior);
Example #3
0
 public ValueTask <ArraySegment <byte> > ReadPayloadAsync(ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) =>
 ProtocolUtility.ReadPayloadAsync(m_bufferedByteReader, m_byteHandler, GetNextSequenceNumber, default(ArraySegment <byte>), protocolErrorBehavior, ioBehavior);
Example #4
0
 public ValueTask <ArraySegment <byte> > ReadPayloadAsync(ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) =>
 ProtocolUtility.ReadPayloadAsync(m_bufferedByteReader, new CompressedByteHandler(this, protocolErrorBehavior), () => default(int?), default(ArraySegment <byte>), protocolErrorBehavior, ioBehavior);