/// <summary>
/// Advances the stream by a number of positions and returns the original position.
/// </summary>
/// <param name="count">The number of positions to advance.</param>
/// <exception cref="InvalidOperationException">
/// Thrown if the position will fall outside the bounds of the underlying array segment.
/// </exception>
/// <returns>the position of the stream before advancing.</returns>
private int CheckedAdvance(int count)
{
if (_currentOffset + count > _segmentEnd)
{
throw PacketReadingException.EndOfStream();
}
int old = _currentOffset;
_currentOffset += count;
return(old);
}