using System; using System.IO; using System.Collections.Generic; using Google.ProtocolBuffers.Collections; namespace Google.ProtocolBuffers.Serialization.Http { /// /// A delegate used to specify a method that constructs an ICodedInputStream from a .NET Stream. /// public delegate ICodedInputStream CodedInputBuilder(Stream stream); /// /// A delegate used to specify a method that constructs an ICodedOutputStream from a .NET Stream. /// public delegate ICodedOutputStream CodedOutputBuilder(Stream stream); /// /// Defines control information for the various formatting used with HTTP services /// public class MessageFormatOptions { /// The mime type for xml content /// Other valid xml mime types include: application/binary, application/x-protobuf public const string ContentTypeProtoBuffer = "application/vnd.google.protobuf"; /// The mime type for xml content /// Other valid xml mime types include: text/xml public const string ContentTypeXml = "application/xml"; /// The mime type for json content /// /// Other valid json mime types include: application/json, application/x-json, /// application/x-javascript, text/javascript, text/x-javascript, text/x-json, text/json /// public const string ContentTypeJson = "application/json"; /// The mime type for query strings and x-www-form-urlencoded content /// This mime type is input-only public const string ContentFormUrlEncoded = "application/x-www-form-urlencoded"; /// /// Default mime-type handling for input /// private static readonly IDictionary MimeInputDefaults = new ReadOnlyDictionary( new Dictionary(StringComparer.OrdinalIgnoreCase) { {"application/json", JsonFormatReader.CreateInstance}, {"application/x-json", JsonFormatReader.CreateInstance}, {"application/x-javascript", JsonFormatReader.CreateInstance}, {"text/javascript", JsonFormatReader.CreateInstance}, {"text/x-javascript", JsonFormatReader.CreateInstance}, {"text/x-json", JsonFormatReader.CreateInstance}, {"text/json", JsonFormatReader.CreateInstance}, {"text/xml", XmlFormatReader.CreateInstance}, {"application/xml", XmlFormatReader.CreateInstance}, {"application/binary", CodedInputStream.CreateInstance}, {"application/x-protobuf", CodedInputStream.CreateInstance}, {"application/vnd.google.protobuf", CodedInputStream.CreateInstance}, {"application/x-www-form-urlencoded", FormUrlEncodedReader.CreateInstance}, } ); /// /// Default mime-type handling for output /// private static readonly IDictionary MimeOutputDefaults = new ReadOnlyDictionary( new Dictionary(StringComparer.OrdinalIgnoreCase) { {"application/json", JsonFormatWriter.CreateInstance}, {"application/x-json", JsonFormatWriter.CreateInstance}, {"application/x-javascript", JsonFormatWriter.CreateInstance}, {"text/javascript", JsonFormatWriter.CreateInstance}, {"text/x-javascript", JsonFormatWriter.CreateInstance}, {"text/x-json", JsonFormatWriter.CreateInstance}, {"text/json", JsonFormatWriter.CreateInstance}, {"text/xml", XmlFormatWriter.CreateInstance}, {"application/xml", XmlFormatWriter.CreateInstance}, {"application/binary", CodedOutputStream.CreateInstance}, {"application/x-protobuf", CodedOutputStream.CreateInstance}, {"application/vnd.google.protobuf", CodedOutputStream.CreateInstance}, } ); private string _defaultContentType; private string _xmlReaderRootElementName; private string _xmlWriterRootElementName; private ExtensionRegistry _extensionRegistry; private Dictionary _mimeInputTypes; private Dictionary _mimeOutputTypes; /// Provides access to modify the mime-type input stream construction public IDictionary MimeInputTypes { get { return _mimeInputTypes ?? (_mimeInputTypes = new Dictionary( MimeInputDefaults, StringComparer.OrdinalIgnoreCase)); } } /// Provides access to modify the mime-type input stream construction public IDictionary MimeOutputTypes { get { return _mimeOutputTypes ?? (_mimeOutputTypes = new Dictionary( MimeOutputDefaults, StringComparer.OrdinalIgnoreCase)); } } internal IDictionary MimeInputTypesReadOnly { get { return _mimeInputTypes ?? MimeInputDefaults; } } internal IDictionary MimeOutputTypesReadOnly { get { return _mimeOutputTypes ?? MimeOutputDefaults; } } /// /// The default content type to use if the input type is null or empty. If this /// value is not supplied an ArgumentOutOfRangeException exception will be raised. /// public string DefaultContentType { get { return _defaultContentType ?? String.Empty; } set { _defaultContentType = value; } } /// /// The extension registry to use when reading messages /// public ExtensionRegistry ExtensionRegistry { get { return _extensionRegistry ?? ExtensionRegistry.Empty; } set { _extensionRegistry = value; } } /// /// The name of the xml root element when reading messages /// public string XmlReaderRootElementName { get { return _xmlReaderRootElementName ?? XmlFormatReader.DefaultRootElementName; } set { _xmlReaderRootElementName = value; } } /// /// Xml reader options /// public XmlReaderOptions XmlReaderOptions { get; set; } /// /// True to use formatted output including new-lines and default indentation /// public bool FormattedOutput { get; set; } /// /// The name of the xml root element when writing messages /// public string XmlWriterRootElementName { get { return _xmlWriterRootElementName ?? XmlFormatWriter.DefaultRootElementName; } set { _xmlWriterRootElementName = value; } } /// /// Xml writer options /// public XmlWriterOptions XmlWriterOptions { get; set; } } }