private void WriteBase64Text(byte[] buffer, int offset, int count) { if (_base64Chars == null) { _base64Chars = new byte[512]; } Base64Encoding encoding = XmlConverter.Base64Encoding; while (count >= 3) { int byteCount = Math.Min(_base64Chars.Length / 4 * 3, count - count % 3); int charCount = byteCount / 3 * 4; encoding.GetChars(buffer, offset, byteCount, _base64Chars, 0); _signingWriter.WriteText(_base64Chars, 0, charCount); if (_text) { _writer.WriteText(_base64Chars, 0, charCount); } offset += byteCount; count -= byteCount; } if (count > 0) { encoding.GetChars(buffer, offset, count, _base64Chars, 0); _signingWriter.WriteText(_base64Chars, 0, 4); if (_text) { _writer.WriteText(_base64Chars, 0, 4); } } }
private async Task InternalWriteBase64TextAsync(byte[] buffer, int offset, int count) { Base64Encoding encoding = XmlConverter.Base64Encoding; while (count >= 3) { int byteCount = Math.Min(bufferLength / 4 * 3, count - count % 3); int charCount = byteCount / 3 * 4; int charOffset; BytesWithOffset bufferResult = await GetBufferAsync(charCount).ConfigureAwait(false); byte[] chars = bufferResult.Bytes; charOffset = bufferResult.Offset; Advance(encoding.GetChars(buffer, offset, byteCount, chars, charOffset)); offset += byteCount; count -= byteCount; } if (count > 0) { int charOffset; BytesWithOffset bufferResult = await GetBufferAsync(4).ConfigureAwait(false); byte[] chars = bufferResult.Bytes; charOffset = bufferResult.Offset; Advance(encoding.GetChars(buffer, offset, count, chars, charOffset)); } }
private void WriteBase64Text(byte[] buffer, int offset, int count) { if (this.base64Chars == null) { this.base64Chars = new byte[0x200]; } Base64Encoding encoding = XmlConverter.Base64Encoding; while (count >= 3) { int byteCount = Math.Min((int)((this.base64Chars.Length / 4) * 3), (int)(count - (count % 3))); int num2 = (byteCount / 3) * 4; encoding.GetChars(buffer, offset, byteCount, this.base64Chars, 0); this.signingWriter.WriteText(this.base64Chars, 0, num2); if (this.text) { this.writer.WriteText(this.base64Chars, 0, num2); } offset += byteCount; count -= byteCount; } if (count > 0) { encoding.GetChars(buffer, offset, count, this.base64Chars, 0); this.signingWriter.WriteText(this.base64Chars, 0, 4); if (this.text) { this.writer.WriteText(this.base64Chars, 0, 4); } } }
static void OnGetBufferComplete(IAsyncEventArgs state) { GetBufferEventResult result = ((GetBufferAsyncEventArgs)state).Result; InternalWriteBase64TextAsyncWriter thisPtr = (InternalWriteBase64TextAsyncWriter)state.AsyncState; XmlWriteBase64AsyncArguments writerArgs = thisPtr.writerState.Arguments; Exception completionException = null; bool completeSelf = false; try { if (state.Exception != null) { completionException = state.Exception; completeSelf = true; } else { byte[] chars = result.Buffer; int offset = result.Offset; Base64Encoding encoding = XmlConverter.Base64Encoding; int byteCount = Math.Min(bufferLength / 4 * 3, writerArgs.Count - writerArgs.Count % 3); int charCount = byteCount / 3 * 4; thisPtr.writer.Advance(encoding.GetChars( writerArgs.Buffer, writerArgs.Offset, byteCount, chars, offset)); if (byteCount >= 3) { writerArgs.Offset += byteCount; writerArgs.Count -= byteCount; } if (thisPtr.InternalWriteBase64TextAsync(thisPtr.writerState) == AsyncCompletionResult.Completed) { completeSelf = true; } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } completionException = exception; completeSelf = true; } if (completeSelf) { thisPtr.writerState.Complete(false, completionException); } }
private void WriteBase64Text(byte[] buffer, int offset, int count) { Base64Encoding encoding = XmlConverter.Base64Encoding; while (count >= 3) { int num3; int byteCount = Math.Min(0x180, count - (count % 3)); int num2 = (byteCount / 3) * 4; byte[] chars = base.GetBuffer(num2, out num3); base.Advance(encoding.GetChars(buffer, offset, byteCount, chars, num3)); offset += byteCount; count -= byteCount; } if (count > 0) { int num4; byte[] buffer3 = base.GetBuffer(4, out num4); base.Advance(encoding.GetChars(buffer, offset, count, buffer3, num4)); } }
private void InternalWriteBase64Text(byte[] buffer, int offset, int count) { Base64Encoding encoding = XmlConverter.Base64Encoding; while (count >= 3) { int byteCount = Math.Min(bufferLength / 4 * 3, count - count % 3); int charCount = byteCount / 3 * 4; int charOffset; byte[] chars = GetBuffer(charCount, out charOffset); Advance(encoding.GetChars(buffer, offset, byteCount, chars, charOffset)); offset += byteCount; count -= byteCount; } if (count > 0) { int charOffset; byte[] chars = GetBuffer(4, out charOffset); Advance(encoding.GetChars(buffer, offset, count, chars, charOffset)); } }
bool HandleWriteCharacters(IAsyncResult result) { int byteCount = Math.Min(bufferLength / 4 * 3, count - count % 3); int charCount = byteCount / 3 * 4; int charOffset; if (result == null) { result = writer.BeginGetBuffer(charCount, onWriteCharacters, this); if (!result.CompletedSynchronously) { return(false); } } byte[] chars = writer.EndGetBuffer(result, out charOffset); writer.Advance(encoding.GetChars(this.buffer, this.offset, byteCount, chars, charOffset)); this.offset += byteCount; this.count -= byteCount; return(true); }
AsyncCompletionResult InternalWriteBase64TextAsync(AsyncEventArgs <XmlWriteBase64AsyncArguments> writerState) { GetBufferAsyncEventArgs bufferState = this.getBufferState; GetBufferArgs bufferArgs = this.getBufferArgs; XmlWriteBase64AsyncArguments writerArgs = writerState.Arguments; if (bufferState == null) { // Need to initialize the cached getBufferState // used to call GetBufferAsync() multiple times. bufferState = new GetBufferAsyncEventArgs(); bufferArgs = new GetBufferArgs(); this.getBufferState = bufferState; this.getBufferArgs = bufferArgs; } Base64Encoding encoding = XmlConverter.Base64Encoding; while (writerArgs.Count >= 3) { int byteCount = Math.Min(bufferLength / 4 * 3, writerArgs.Count - writerArgs.Count % 3); int charCount = byteCount / 3 * 4; bufferArgs.Count = charCount; bufferState.Set(onGetBufferComplete, bufferArgs, this); if (writer.GetBufferAsync(bufferState) == AsyncCompletionResult.Completed) { GetBufferEventResult getbufferResult = bufferState.Result; bufferState.Complete(true); writer.Advance(encoding.GetChars( writerArgs.Buffer, writerArgs.Offset, byteCount, getbufferResult.Buffer, getbufferResult.Offset)); writerArgs.Offset += byteCount; writerArgs.Count -= byteCount; } else { return(AsyncCompletionResult.Queued); } } if (writerArgs.Count > 0) { bufferArgs.Count = 4; bufferState.Set(onGetBufferComplete, bufferArgs, this); if (writer.GetBufferAsync(bufferState) == AsyncCompletionResult.Completed) { GetBufferEventResult getbufferResult = bufferState.Result; bufferState.Complete(true); writer.Advance(encoding.GetChars( writerArgs.Buffer, writerArgs.Offset, writerArgs.Count, getbufferResult.Buffer, getbufferResult.Offset)); } else { return(AsyncCompletionResult.Queued); } } return(AsyncCompletionResult.Completed); }