protected override void AddResponseBody(BinaryWriter writer) { writer.Write(this.ReturnCode); writer.Write(this.Utf8Output); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.Output); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.ErrorOutput); }
public async Task WriteAsync(PipeStream outStream, CancellationToken cancellationToken) { using (var writer = new BinaryWriter(new MemoryStream(), Encoding.Unicode)) { // Format the response CompilerServerLogger.Log("Formatting Response"); writer.Write(this.ReturnCode); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.Output); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.ErrorOutput); writer.Flush(); cancellationToken.ThrowIfCancellationRequested(); // Send the response to the client // Grab the MemoryStream and its internal buffer to prevent // making another copy. var stream = (MemoryStream)writer.BaseStream; // Write the length of the response uint length = (uint)stream.Length; CompilerServerLogger.Log("Writing response length"); // There is no way to know the number of bytes written to // the pipe stream. We just have to assume all of them are written. await outStream.WriteAsync(BitConverter.GetBytes(length), 0, 4, cancellationToken).ConfigureAwait(false); // Write the response CompilerServerLogger.Log("Writing response of size {0}", length); // There is no way to know the number of bytes written to // the pipe stream. We just have to assume all of them are written. await outStream.WriteAsync(stream.GetBuffer(), 0, (int)length, cancellationToken).ConfigureAwait(false); } }
public void WriteToBinaryWriter(BinaryWriter writer) { writer.Write(this.ArgumentId); writer.Write(this.ArgumentIndex); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.Value); }