/// <summary> /// Reads a value of type <typeparamref name="T"/> from <paramref name="source"/>. /// </summary> /// <exception cref="IndexOutOfRangeException">Thrown if the <paramref name="source"/> does not have enough data to read a value of type <typeparamref name="T"/>.</exception> public static T Read <T>(this IHFormat format, ReadOnlySpan <byte> source, out int bytesRead) where T : struct { if (!format.TryRead(source, out T value, out bytesRead)) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(value); }