Transparently encodes a single message.

At construction, the passed message is first appended to the WriteBuffer object passed to CreateAsync. Afterwards, when data is written to this stream then it is first encoded and the encoded form is then appended to the WriteBuffer object.

Caution: DisposeAsync must be called in the end.

If necessary, the message plus payload is automatically partitioned into multiple packets such that the unencoded length of each packet does not exceed 1024 bytes.

Inheritance: NonSeekableStream
コード例 #1
0
        private async Task <NonSeekableStream> WriteMessageCoreAsync(
            S101Message message, CancellationToken cancellationToken)
        {
            this.AssertNotDisposed();

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if ((this.stream != null) && this.stream.CanWrite)
            {
                throw new InvalidOperationException(
                          "DisposeAsync() has not been called on the payload stream of the previous message.");
            }

            this.stream = await MessageEncodingStream.CreateAsync(this.writeBuffer, message, cancellationToken);

            if (!message.CanHavePayload)
            {
                await this.stream.DisposeAsync(cancellationToken);

                this.stream = null;
            }

            return(this.stream);
        }
コード例 #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal static async Task <MessageEncodingStream> CreateAsync(
            WriteBuffer rawBuffer, S101Message message, CancellationToken cancellationToken)
        {
            message.PacketFlags =
                PacketFlags.FirstPacket | (message.CanHaveMultiplePackets ? PacketFlags.None : PacketFlags.LastPacket);
            var framingStream = await FramingStream.CreateAsync(rawBuffer, cancellationToken);

            var result = new MessageEncodingStream(message, rawBuffer, framingStream);
            await message.WriteToAsync(result.unframedBuffer, cancellationToken);

            return(result);
        }
コード例 #3
0
 private async Task DisposeCoreAsync(CancellationToken cancellationToken)
 {
     try
     {
         if (this.stream != null)
         {
             await this.stream.DisposeAsync(cancellationToken);
         }
     }
     finally
     {
         this.disposed = true;
         this.stream   = null;
     }
 }
コード例 #4
0
ファイル: S101Writer.cs プロジェクト: Lawo/ember-plus-sharp
 private async Task DisposeCoreAsync(CancellationToken cancellationToken)
 {
     try
     {
         if (this.stream != null)
         {
             await this.stream.DisposeAsync(cancellationToken);
         }
     }
     finally
     {
         this.disposed = true;
         this.stream = null;
     }
 }
コード例 #5
0
ファイル: S101Writer.cs プロジェクト: Lawo/ember-plus-sharp
        private async Task<NonSeekableStream> WriteMessageCoreAsync(
            S101Message message, CancellationToken cancellationToken)
        {
            this.AssertNotDisposed();

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if ((this.stream != null) && this.stream.CanWrite)
            {
                throw new InvalidOperationException(
                    "DisposeAsync() has not been called on the payload stream of the previous message.");
            }

            this.stream = await MessageEncodingStream.CreateAsync(this.writeBuffer, message, cancellationToken);

            if (!message.CanHavePayload)
            {
                await this.stream.DisposeAsync(cancellationToken);
                this.stream = null;
            }

            return this.stream;
        }
コード例 #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal static async Task<MessageEncodingStream> CreateAsync(
            WriteBuffer rawBuffer, S101Message message, CancellationToken cancellationToken)
        {
            message.PacketFlags =
                PacketFlags.FirstPacket | (message.CanHaveMultiplePackets ? PacketFlags.None : PacketFlags.LastPacket);
            var framingStream = await FramingStream.CreateAsync(rawBuffer, cancellationToken);
            var result = new MessageEncodingStream(message, rawBuffer, framingStream);
            await message.WriteToAsync(result.unframedBuffer, cancellationToken);
            return result;
        }