src/Orleans.Core.Abstractions/IDs/IdSpanCodec.cs
/// <summary>
/// Reads an <see cref="IdSpan"/> value from a reader without any field framing.
/// </summary>
/// <typeparam name="TInput">The underlying reader input type.</typeparam>
/// <param name="reader">The reader.</param>
/// <returns>An <see cref="IdSpan"/>.</returns>
Reads an  value from a reader without any field framing.
Reads an value from a reader without any field framing .
public static unsafe IdSpan ReadRaw<TInput>(ref Reader<TInput> reader)
    {
        byte[] payloadArray = default;
        var hashCode = reader.ReadInt32();
        var length = reader.ReadVarUInt32();
        if (!reader.TryReadBytes((int)length, out var payloadSpan))
        {
            payloadSpan = payloadArray = reader.ReadBytes(length);
        }
        var candidateHashCode = hashCode;
        while (_cache.TryGetValue(candidateHashCode, out var existing))
        {
            if (existing.GetHashCode() != hashCode)
            {
                break;
            }
            var existingSpan = new ReadOnlySpan<byte>(IdSpan.UnsafeGetArray(existing));
            if (existingSpan.SequenceEqual(payloadSpan))
            {
                return existing;
            }
            ++candidateHashCode;
        }
        if (payloadArray is null)
        {
            payloadArray = new byte[length];
            payloadSpan.CopyTo(payloadArray);
        }
        var value = IdSpan.UnsafeCreate(payloadArray, hashCode);
        while (!_cache.TryAdd(candidateHashCode++, value))
        {
        }
        return value;
    }
public static unsafe IdSpan ReadRaw < TInput > ( ref Reader < TInput > reader ) { byte [ ] payloadArray = default ; var hashCode = reader . ReadInt32 ( ) ; var length = reader . ReadVarUInt32 ( ) ; if ( ! reader . TryReadBytes ( ( int ) length , out var payloadSpan ) ) { payloadSpan = payloadArray = reader . ReadBytes ( length ) ; } var candidateHashCode = hashCode ; while ( _cache . TryGetValue ( candidateHashCode , out var existing ) ) { if ( existing . GetHashCode ( ) != hashCode ) { break ; } var existingSpan = new ReadOnlySpan < byte > ( IdSpan . UnsafeGetArray ( existing ) ) ; if ( existingSpan . SequenceEqual ( payloadSpan ) ) { return existing ; } ++ candidateHashCode ; } if ( payloadArray is null ) { payloadArray = new byte [ length ] ; payloadSpan . CopyTo ( payloadArray ) ; } var value = IdSpan . UnsafeCreate ( payloadArray , hashCode ) ; while ( ! _cache . TryAdd ( candidateHashCode ++ , value ) ) { } return value ; }
Reads an  value from a reader without any field framing.
Reads an value from a reader without any field framing .
// Search through  // Try the next slot.  // Insert the value at the first available position.
None
Reader<TInput>
ref
reader
None
typeparam
The underlying reader input type.
The underlying reader input type .