-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise MessagePackSerializer.Deserialize<T>(Stream) to support multip…
…le reads
- Loading branch information
Showing
3 changed files
with
97 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 0 additions & 127 deletions
127
src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackStreamReader.cs
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackStreamReadingState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) All contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Buffers; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Nerdbank.Streams; | ||
|
||
namespace MessagePack | ||
{ | ||
public struct MessagePackStreamReadingState | ||
{ | ||
internal readonly Stream Stream; | ||
internal SequencePool.Rental SequenceRental; | ||
internal SequencePosition? EndOfLastMessage; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MessagePackStreamReadingState"/> struct. | ||
/// </summary> | ||
/// <param name="stream">The stream to read from.</param> | ||
internal MessagePackStreamReadingState(Stream stream) | ||
{ | ||
this.Stream = stream ?? throw new ArgumentNullException(nameof(stream)); | ||
this.SequenceRental = SequencePool.Shared.Rent(); | ||
this.EndOfLastMessage = null; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the sequence that we read data from the <see cref="Stream"/> into. | ||
/// </summary> | ||
internal Sequence<byte> ReadData => this.SequenceRental.Value; | ||
|
||
internal bool IsDefault => this.Stream == null; | ||
|
||
/// <summary> | ||
/// Gets any bytes that have been read since the last complete message returned from <see cref="ReadAsync(CancellationToken)"/>. | ||
/// </summary> | ||
public ReadOnlySequence<byte> RemainingBytes => this.EndOfLastMessage.HasValue ? this.ReadData.AsReadOnlySequence.Slice(this.EndOfLastMessage.Value) : this.ReadData.AsReadOnlySequence; | ||
} | ||
} |