private void EnsureBufferIsSufficient(int sourceCount) { var maxLength = encoder.GetMaxEncodedLength(sourceCount); if (encodedBuffer != null && encodedBuffer.Length >= maxLength) { return; } var newLength = encodedBuffer == null ? 1024 : encodedBuffer.Length * 2; while (newLength < maxLength) { newLength *= 2; } encodedBuffer = new byte[newLength]; }