src/Orleans.Serialization/Buffers/Reader.cs
/// <summary>
/// Creates a new reader beginning at the specified position.
/// </summary>        
/// <param name="position">
/// The position in the input stream to fork from.
/// </param>        
/// <param name="forked">
/// The forked reader instance.
/// </param>        
Creates a new reader beginning at the specified position.
Creates a new reader beginning at the specified position .
public void ForkFrom(long position, out Reader<TInput> forked)
        {
            if (IsReadOnlySequenceInput)
            {
                ref var sequence = ref Unsafe.As<TInput, ReadOnlySequence<byte>>(ref _input);
                var slicedSequence = sequence.Slice(position - _sequenceOffset);
                forked = new Reader<TInput>(Unsafe.As<ReadOnlySequence<byte>, TInput>(ref slicedSequence), Session, position);
                if (forked.Position != position)
                {
                    ThrowInvalidPosition(position, forked.Position);
                }
            }
            else if (IsSpanInput)
            {
                forked = new Reader<TInput>(_currentSpan.Slice((int)position), Session, position);
                if (forked.Position != position || position > int.MaxValue)
                {
                    ThrowInvalidPosition(position, forked.Position);
                }
            }
            else if (_input is ReaderInput input)
            {
                input.Seek(position);
                forked = new Reader<TInput>(_input, Session, 0);
                if (forked.Position != position)
                {
                    ThrowInvalidPosition(position, forked.Position);
                }
            }
            else
            {
                throw new NotSupportedException($"Type {typeof(TInput)} is not supported");
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            static void ThrowInvalidPosition(long expectedPosition, long actualPosition)
            {
                throw new InvalidOperationException($"Expected to arrive at position {expectedPosition} after {nameof(ForkFrom)}, but resulting position is {actualPosition}");
            }
        }
public void ForkFrom ( long position , out Reader < TInput > forked ) { if ( IsReadOnlySequenceInput ) { ref var sequence = ref Unsafe . As < TInput , ReadOnlySequence < byte > > ( ref _input ) ; var slicedSequence = sequence . Slice ( position - _sequenceOffset ) ; forked = new Reader < TInput > ( Unsafe . As < ReadOnlySequence < byte > , TInput > ( ref slicedSequence ) , Session , position ) ; if ( forked . Position != position ) { ThrowInvalidPosition ( position , forked . Position ) ; } } else if ( IsSpanInput ) { forked = new Reader < TInput > ( _currentSpan . Slice ( ( int ) position ) , Session , position ) ; if ( forked . Position != position || position > int . MaxValue ) { ThrowInvalidPosition ( position , forked . Position ) ; } } else if ( _input is ReaderInput input ) { input . Seek ( position ) ; forked = new Reader < TInput > ( _input , Session , 0 ) ; if ( forked . Position != position ) { ThrowInvalidPosition ( position , forked . Position ) ; } } else { throw new NotSupportedException ( $" Type  { typeof ( TInput ) }  is not supported " ) ; } [ MethodImpl ( MethodImplOptions . NoInlining ) ] static void ThrowInvalidPosition ( long expectedPosition , long actualPosition ) { throw new InvalidOperationException ( $" Expected to arrive at position  { expectedPosition }  after  { nameof ( ForkFrom ) } , but resulting position is  { actualPosition } " ) ; } }
Creates a new reader beginning at the specified position.
Creates a new reader beginning at the specified position .
position
long
The position in the input stream to fork from.
The position in the input stream to fork from .
Reader<TInput>
out
forked
The forked reader instance.
The forked reader instance .