public void TestWriteProtoMimeTypes() { foreach (string type in ProtobufTypes) { Assert.IsTrue( MessageFormatFactory.CreateOutputStream(new MessageFormatOptions(), type, Stream.Null) is CodedOutputStream); } Assert.IsTrue( MessageFormatFactory.CreateOutputStream(new MessageFormatOptions() { DefaultContentType = "application/vnd.google.protobuf" }, null, Stream.Null) is CodedOutputStream); }
public void TestWriteXmlMimeTypes() { foreach (string type in XmlTypes) { Assert.IsTrue( MessageFormatFactory.CreateOutputStream(new MessageFormatOptions(), type, Stream.Null) is XmlFormatWriter); } Assert.IsTrue( MessageFormatFactory.CreateOutputStream(new MessageFormatOptions() { DefaultContentType = "application/xml" }, null, Stream.Null) is XmlFormatWriter); }
/// <summary> /// Writes the message instance to the stream using the content type provided /// </summary> /// <param name="message">An instance of a message</param> /// <param name="options">Options specific to writing this message and/or content type</param> /// <param name="contentType">The mime type of the content to be written</param> /// <param name="output">The stream to write the message to</param> public static void WriteTo( #if !NOEXTENSIONS this #endif IMessageLite message, MessageFormatOptions options, string contentType, Stream output) { ICodedOutputStream codedOutput = MessageFormatFactory.CreateOutputStream(options, contentType, output); // Output the appropriate message preamble codedOutput.WriteMessageStart(); // Write the message content to the output message.WriteTo(codedOutput); // Write the closing message fragment codedOutput.WriteMessageEnd(); codedOutput.Flush(); }