/// <summary> /// Write the JSON message to the output stream. /// </summary> /// <param name="message"> /// The message to write. /// </param> private void WriteJsonMessage(string message) { // Build the header message. var header = string.Format("Content-Length: {0}{1}{2}{1}{2}", message.Length, (char)0x0D, (char)0x0A); var headerData = Encoding.UTF8.GetBytes(header); SourceStream.Write(headerData, 0, headerData.Length); // Write the body data. var bodyData = Encoding.UTF8.GetBytes(message); SourceStream.Write(bodyData, 0, bodyData.Length); SourceStream.Flush(); // debug the new message. if (DebugStream != null) { lock (DebugStream) { DebugStream.WriteLine("*****************************************"); DebugStream.WriteLine(" Direction: {0}", Direction); DebugStream.WriteLine(" Timestamp: {0}", DateTime.Now); DebugStream.WriteLine("*****************************************"); DebugStream.WriteLine(message); DebugStream.WriteLine("*****************************************"); DebugStream.Flush(); } } }
/// <summary> /// Writes 4 floating point bytes at a time, inputting from <see cref="AbstractPcmConversionStream.BytesPerSample"/> /// bytes per PCM sample write. /// </summary> /// <param name="buffer"></param> /// <param name="offset"></param> /// <param name="count"></param> protected override void InternalWrite(byte[] buffer, int offset, int count) { var wrote = 0; while (wrote < count) { PCMToFloat(buffer, offset + wrote, tempBuffer, 0); SourceStream.Write(tempBuffer, 0, sizeof(float)); wrote += BytesPerSample; } }
/// <summary> /// Writes to the underlying stream /// </summary> public override void Write(byte[] buffer, int offset, int count) { SourceStream.Write(buffer, offset, count); }