// places an integer in the buffer private static void appendInt(BuffersState bufState, int value) { byte[] buf = bufState.buffers[bufState.bufferIndex]; storeInt(buf, bufState.byteIndex, value); bufState.byteIndex += SIZE_OF_INT; bufState.checkIndices(); }
// places a byte array, but without bounds private static void appendBytes(BuffersState bufState, byte[] array) { int currentPos = 0; int bytesLeft = array.Length; while (bytesLeft >= SIZE_OF_INT) { byte[] buf = bufState.buffers[bufState.bufferIndex]; int contiguousBlockSize = Math.Min( buf.Length - bufState.byteIndex, bytesLeft & ~0x03 ); for (int i = 0; i != contiguousBlockSize; ++i) { buf[bufState.byteIndex + i] = array[currentPos + i]; } currentPos += contiguousBlockSize; bytesLeft -= contiguousBlockSize; bufState.byteIndex += contiguousBlockSize; bufState.checkIndices(); } if (bytesLeft != 0) { // padding required byte[] buf = bufState.buffers[bufState.bufferIndex]; for (int i = 0; i != bytesLeft; ++i) { buf[bufState.byteIndex + i] = array[currentPos + i]; } bufState.byteIndex += SIZE_OF_INT; bufState.checkIndices(); } }
// places a byte array, but without bounds private static void appendBytes(BuffersState bufState, byte[] array) { int currentPos = 0; int bytesLeft = array.Length; while(bytesLeft >= SIZE_OF_INT) { byte[] buf = bufState.buffers[bufState.bufferIndex]; int contiguousBlockSize = Math.Min( buf.Length - bufState.byteIndex, bytesLeft & ~0x03 ); for(int i = 0; i != contiguousBlockSize; ++i) { buf[bufState.byteIndex + i] = array[currentPos + i]; } currentPos += contiguousBlockSize; bytesLeft -= contiguousBlockSize; bufState.byteIndex += contiguousBlockSize; bufState.checkIndices(); } if(bytesLeft != 0) { // padding required byte[] buf = bufState.buffers[bufState.bufferIndex]; for(int i = 0; i != bytesLeft; ++i) { buf[bufState.byteIndex + i] = array[currentPos + i]; } bufState.byteIndex += SIZE_OF_INT; bufState.checkIndices(); } }