public static ReadOnlyMemory <byte> ReadNextTLSVariableLength(this ReadOnlyMemory <byte> bytesIn, int lengthNumBytes, out ReadOnlyMemory <byte> bytesOut) { if (bytesIn.Length < lengthNumBytes) { throw new NotEnoughBytesException($"Expecting {lengthNumBytes} bytes but only have {bytesIn.Length} bytes left."); } bytesIn = bytesIn.Read(lengthNumBytes, out uint length); if (bytesIn.Length < length) { throw new NotEnoughBytesException($"Expecting {length} bytes but only have {bytesIn.Length} bytes left."); } return(bytesIn.Read((int)length, out bytesOut)); }
/// <summary>Reads a value from the buffer that uses the Ice 2.0 encoding. This value cannot contain classes or /// exceptions.</summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="buffer">The byte buffer.</param> /// <param name="reader">The <see cref="InputStreamReader{T}"/> that reads the value from the buffer using an /// <see cref="InputStream"/>.</param> /// <param name="communicator">The communicator (optional).</param> /// <param name="connection">The connection (optional).</param> /// <param name="proxy">The proxy (optional).</param> /// <returns>The value read from the buffer.</returns> /// <exception name="InvalidDataException">Thrown when <c>reader</c> finds invalid data or <c>reader</c> leaves /// unread data in the buffer.</exception> /// <remarks>When reading proxies, communicator, connection or proxy must be non-null.</remarks> public static T Read <T>( this ReadOnlyMemory <byte> buffer, InputStreamReader <T> reader, Communicator?communicator = null, Connection?connection = null, IObjectPrx?proxy = null) => buffer.Read(Encoding.V20, reader, communicator, connection, proxy);
/// <summary>Reads a value from the buffer that uses the 2.0 encoding. Value cannot contain any proxy. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="buffer">The byte buffer.</param> /// <param name="reader">The <see cref="InputStreamReader{T}"/> that reads the value from the buffer using an /// <see cref="InputStream"/>.</param> /// <returns>The value read from the buffer.</returns> /// <exception name="InvalidDataException">Thrown when <c>reader</c> finds invalid data or <c>reader</c> leaves /// unread data in the buffer.</exception> public static T Read <T>(this ReadOnlyMemory <byte> buffer, InputStreamReader <T> reader) => buffer.Read(Encoding.V20, null, reader);
/// <summary>Reads a value from the buffer that uses the Ice 2.0 encoding.</summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="buffer">The byte buffer.</param> /// <param name="communicator">The communicator, which is mandatory only when reading proxies.</param> /// <param name="reader">The <see cref="InputStreamReader{T}"/> that reads the value from the buffer using an /// <see cref="InputStream"/>.</param> /// <returns>The value read from the buffer.</returns> /// <exception name="InvalidDataException">Thrown when <c>reader</c> finds invalid data or <c>reader</c> leaves /// unread data in the buffer.</exception> public static T Read <T>( this ReadOnlyMemory <byte> buffer, Communicator communicator, InputStreamReader <T> reader) => buffer.Read(Encoding.V20, communicator, reader);