private int Read(byte[] buffer, int offset, int count) { var result = mInput.Read(buffer, offset, count); mPosition += result; return(result); }
private void EnsureOutputData() { while (mDecoder.AvailableOutputLength == 0 && !mDecoder.IsOutputComplete) { if (mOffset == mEnding) { mOffset = 0; mEnding = 0; var fetched = mInput.Read(mBuffer, 0, mBuffer.Length); System.Diagnostics.Debug.Assert(0 <= fetched && fetched <= mBuffer.Length); if (fetched == 0) { mDecoder.Decode(null, 0, 0, null, true); System.Diagnostics.Debug.Assert(mDecoder.AvailableOutputLength > 0 || mDecoder.IsOutputComplete); continue; } mEnding = fetched; } var written = mDecoder.Decode(mBuffer, mOffset, mEnding - mOffset, (int)Math.Min(Int32.MaxValue, mLength - mPosition), false); System.Diagnostics.Debug.Assert(0 <= written && written <= mEnding - mOffset); mOffset += written; } }
private int DecodeInto(byte[] buffer, int offset, int count) { if (mOffset == mEnding) { mOffset = 0; mEnding = 0; } while (mEnding - mOffset < 5) { if (mInputEnd) { // if less than 5 bytes are left they are copied int n = 0; while (mOffset < mEnding && count > 0) { buffer[offset++] = mBuffer[mOffset++]; count--; n++; } return(n); } if (mBuffer.Length - mOffset < 5) { Buffer.BlockCopy(mBuffer, mOffset, mBuffer, 0, mEnding - mOffset); mEnding -= mOffset; mOffset = 0; } int delta = mInput.Read(mBuffer, mEnding, mBuffer.Length - mEnding); if (delta == 0) { mInputEnd = true; } else { mEnding += delta; } } unsafe { fixed(byte *pBuffer = mBuffer) { int delta = x86_Convert(pBuffer + mOffset, Math.Min(mEnding - mOffset, count), (uint)mBufferPos); if (delta == 0) { throw new NotSupportedException(); } Buffer.BlockCopy(mBuffer, mOffset, buffer, offset, delta); mOffset += delta; mBufferPos += delta; return(delta); } } }
public override int Read(byte[] buffer, int offset, int count) { if (mInput == null) { throw new InvalidOperationException(); } return(mInput.Read(buffer, offset, count)); }
public byte ReadByte() { if (mStream.Read(mBuffer, 0, 1) == 0) { throw new EndOfStreamException(); } return(mBuffer[0]); }
private void Decode() { if (mBufferOffset == mBufferEnding) { #if DEBUG // Avoid confusing people if they break into the debugger before mBufferOffset has been updated. mBufferOffset = 0; mBufferEnding = 0; #endif mBufferEnding = mInput.Read(mBuffer, 0, mBuffer.Length); mBufferOffset = mDecoder.Decode(mBuffer, 0, mBufferEnding, null, mBufferEnding == 0); } else { mBufferOffset += mDecoder.Decode(mBuffer, mBufferOffset, mBufferEnding - mBufferOffset, null, false); } }
public int Read(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (offset < 0 || offset > buffer.Length) { throw new ArgumentOutOfRangeException(nameof(offset)); } if (count < 0 || count > buffer.Length - offset) { throw new ArgumentOutOfRangeException(nameof(count)); } if (count == 0) { return(0); } return(mOutputStream.Read(buffer, offset, count)); }
public IEnumerable <byte> Run() { const uint kBurstSize = (1u << 18); var tempBuffer = new byte[1]; byte prevByte = 0; uint processedBytes = 0; for (;;) { byte b = 0; uint i; for (i = 0; i < kBurstSize; i++) { if (mMainStream.Read(tempBuffer, 0, 1) == 0) { yield break; } b = tempBuffer[0]; mWritten++; yield return(b); if (IsJ(prevByte, b)) { break; } prevByte = b; } processedBytes += i; if (i == kBurstSize) { continue; } if (mStatusDecoder[GetIndex(prevByte, b)].Decode(mRangeDecoder) == 1) { var s = (b == 0xE8) ? mCallStream : mJumpStream; uint src = 0; for (i = 0; i < 4; i++) { if (s.Read(tempBuffer, 0, 1) == 0) { throw new EndOfStreamException(); } src <<= 8; src |= tempBuffer[0]; } uint dest = src - (uint)(mWritten + 4); mWritten++; yield return((byte)dest); mWritten++; yield return((byte)(dest >> 8)); mWritten++; yield return((byte)(dest >> 16)); mWritten++; yield return((byte)(dest >> 24)); prevByte = (byte)(dest >> 24); processedBytes += 4; } else { prevByte = b; } } }