private static void TryFlushOrResize(int required, StreamProtoWriter writer, ref State state) { if (writer.TryFlush(ref state) && // try emptying the buffer (writer.ioBuffer.Length - writer.ioIndex) >= required) { return; } // either can't empty the buffer, or that didn't help; need more space BufferPool.ResizeAndFlushLeft(ref writer.ioBuffer, required + writer.ioIndex, 0, writer.ioIndex); }
private static void TryFlushOrResize(int required, ProtoWriter writer) { if (writer.flushLock == 0) { Flush(writer); // try emptying the buffer if ((writer.ioBuffer.Length - writer.ioIndex) >= required) { return; } } // either can't empty the buffer, or that didn't help; need more space BufferPool.ResizeAndFlushLeft(ref writer.ioBuffer, required + writer.ioIndex, 0, writer.ioIndex); }
private static void DemandSpace(int required, ProtoWriter writer) { if ((int)writer.ioBuffer.Length - writer.ioIndex < required) { if (writer.flushLock == 0) { ProtoWriter.Flush(writer); if ((int)writer.ioBuffer.Length - writer.ioIndex >= required) { return; } } BufferPool.ResizeAndFlushLeft(ref writer.ioBuffer, required + writer.ioIndex, 0, writer.ioIndex); } }
internal void Ensure(int count, bool strict) { if (count > ioBuffer.Length) { BufferPool.ResizeAndFlushLeft(ref ioBuffer, count, ioIndex, available); ioIndex = 0; } else if (ioIndex + count >= ioBuffer.Length) { Helpers.BlockCopy(ioBuffer, ioIndex, ioBuffer, 0, available); ioIndex = 0; } count -= available; int num = ioIndex + available; int num2 = ioBuffer.Length - num; if (isFixedLength && dataRemaining < num2) { num2 = dataRemaining; } int num3; while (count > 0 && num2 > 0 && (num3 = source.Read(ioBuffer, num, num2)) > 0) { available += num3; count -= num3; num2 -= num3; num += num3; if (isFixedLength) { dataRemaining -= num3; } } if (!strict) { return; } if (count <= 0) { return; } throw EoF(this); }
internal void Ensure(int count, bool strict) { Helpers.DebugAssert(available <= count, "Asking for data without checking first"); if (count > ioBuffer.Length) { BufferPool.ResizeAndFlushLeft(ref ioBuffer, count, ioIndex, available); ioIndex = 0; } else if (ioIndex + count >= ioBuffer.Length) { // need to shift the buffer data to the left to make space Helpers.BlockCopy(ioBuffer, ioIndex, ioBuffer, 0, available); ioIndex = 0; } count -= available; int writePos = ioIndex + available, bytesRead; int canRead = ioBuffer.Length - writePos; if (isFixedLength) { // throttle it if needed if (dataRemaining < canRead) { canRead = dataRemaining; } } while (count > 0 && (bytesRead = source.Read(ioBuffer, writePos, canRead)) > 0) { available += bytesRead; count -= bytesRead; canRead -= bytesRead; writePos += bytesRead; if (isFixedLength) { dataRemaining -= bytesRead; } } if (strict && count > 0) { throw EoF(this); } }
internal void Ensure(int count, bool strict) { if (count > this.ioBuffer.Length) { BufferPool.ResizeAndFlushLeft(ref this.ioBuffer, count, this.ioIndex, this.available); this.ioIndex = 0; } else if (this.ioIndex + count >= this.ioBuffer.Length) { Helpers.BlockCopy(this.ioBuffer, this.ioIndex, this.ioBuffer, 0, this.available); this.ioIndex = 0; } count -= this.available; int num = this.ioIndex + this.available; int num2 = this.ioBuffer.Length - num; if (this.isFixedLength && this.dataRemaining < num2) { num2 = this.dataRemaining; } int num3; while (count > 0 && num2 > 0 && (num3 = this.source.Read(this.ioBuffer, num, num2)) > 0) { this.available += num3; count -= num3; num2 -= num3; num += num3; if (this.isFixedLength) { this.dataRemaining -= num3; } } if (strict && count > 0) { throw ProtoReader.EoF(this); } }