csharptest | c2d2c1a | 2011-09-08 20:02:11 -0500 | [diff] [blame] | 1 | using System;
|
csharptest | 2cf6e1b | 2011-09-16 10:55:10 -0500 | [diff] [blame^] | 2 | using System.IO;
|
| 3 | using System.Collections.Generic;
|
| 4 | using Google.ProtocolBuffers.Collections;
|
csharptest | c2d2c1a | 2011-09-08 20:02:11 -0500 | [diff] [blame] | 5 |
|
csharptest | 60fd773 | 2011-09-09 12:18:16 -0500 | [diff] [blame] | 6 | namespace Google.ProtocolBuffers.Serialization.Http
|
csharptest | c2d2c1a | 2011-09-08 20:02:11 -0500 | [diff] [blame] | 7 | {
|
| 8 | /// <summary>
|
| 9 | /// Defines control information for the various formatting used with HTTP services
|
| 10 | /// </summary>
|
| 11 | public struct MessageFormatOptions
|
| 12 | {
|
| 13 | /// <summary>The mime type for xml content</summary>
|
| 14 | /// <remarks>Other valid xml mime types include: application/binary, application/x-protobuf</remarks>
|
| 15 | public const string ContentTypeProtoBuffer = "application/vnd.google.protobuf";
|
| 16 |
|
| 17 | /// <summary>The mime type for xml content</summary>
|
| 18 | /// <remarks>Other valid xml mime types include: text/xml</remarks>
|
| 19 | public const string ContentTypeXml = "application/xml";
|
| 20 |
|
| 21 | /// <summary>The mime type for json content</summary>
|
| 22 | /// <remarks>
|
| 23 | /// Other valid json mime types include: application/json, application/x-json,
|
| 24 | /// application/x-javascript, text/javascript, text/x-javascript, text/x-json, text/json
|
| 25 | /// </remarks>
|
| 26 | public const string ContentTypeJson = "application/json";
|
| 27 |
|
csharptest | 2cf6e1b | 2011-09-16 10:55:10 -0500 | [diff] [blame^] | 28 | /// <summary>The mime type for query strings and x-www-form-urlencoded content</summary>
|
| 29 | /// <remarks>This mime type is input-only</remarks>
|
| 30 | public const string ContentFormUrlEncoded = "application/x-www-form-urlencoded";
|
| 31 |
|
| 32 | /// <summary>
|
| 33 | /// Default mime-type handling for input
|
| 34 | /// </summary>
|
| 35 | private static readonly IDictionary<string, Converter<Stream, ICodedInputStream>> MimeInputDefaults =
|
| 36 | new ReadOnlyDictionary<string, Converter<Stream, ICodedInputStream>>(
|
| 37 | new Dictionary<string, Converter<Stream, ICodedInputStream>>(StringComparer.OrdinalIgnoreCase)
|
| 38 | {
|
| 39 | {"application/json", JsonFormatReader.CreateInstance},
|
| 40 | {"application/x-json", JsonFormatReader.CreateInstance},
|
| 41 | {"application/x-javascript", JsonFormatReader.CreateInstance},
|
| 42 | {"text/javascript", JsonFormatReader.CreateInstance},
|
| 43 | {"text/x-javascript", JsonFormatReader.CreateInstance},
|
| 44 | {"text/x-json", JsonFormatReader.CreateInstance},
|
| 45 | {"text/json", JsonFormatReader.CreateInstance},
|
| 46 | {"text/xml", XmlFormatReader.CreateInstance},
|
| 47 | {"application/xml", XmlFormatReader.CreateInstance},
|
| 48 | {"application/binary", CodedInputStream.CreateInstance},
|
| 49 | {"application/x-protobuf", CodedInputStream.CreateInstance},
|
| 50 | {"application/vnd.google.protobuf", CodedInputStream.CreateInstance},
|
| 51 | {"application/x-www-form-urlencoded", FormUrlEncodedReader.CreateInstance},
|
| 52 | }
|
| 53 | );
|
| 54 |
|
| 55 | /// <summary>
|
| 56 | /// Default mime-type handling for output
|
| 57 | /// </summary>
|
| 58 | private static readonly IDictionary<string, Converter<Stream, ICodedOutputStream>> MimeOutputDefaults =
|
| 59 | new ReadOnlyDictionary<string, Converter<Stream, ICodedOutputStream>>(
|
| 60 | new Dictionary<string, Converter<Stream, ICodedOutputStream>>(StringComparer.OrdinalIgnoreCase)
|
| 61 | {
|
| 62 | {"application/json", JsonFormatWriter.CreateInstance},
|
| 63 | {"application/x-json", JsonFormatWriter.CreateInstance},
|
| 64 | {"application/x-javascript", JsonFormatWriter.CreateInstance},
|
| 65 | {"text/javascript", JsonFormatWriter.CreateInstance},
|
| 66 | {"text/x-javascript", JsonFormatWriter.CreateInstance},
|
| 67 | {"text/x-json", JsonFormatWriter.CreateInstance},
|
| 68 | {"text/json", JsonFormatWriter.CreateInstance},
|
| 69 | {"text/xml", XmlFormatWriter.CreateInstance},
|
| 70 | {"application/xml", XmlFormatWriter.CreateInstance},
|
| 71 | {"application/binary", CodedOutputStream.CreateInstance},
|
| 72 | {"application/x-protobuf", CodedOutputStream.CreateInstance},
|
| 73 | {"application/vnd.google.protobuf", CodedOutputStream.CreateInstance},
|
| 74 | }
|
| 75 | );
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
csharptest | c2d2c1a | 2011-09-08 20:02:11 -0500 | [diff] [blame] | 80 | private string _defaultContentType;
|
| 81 | private string _xmlReaderRootElementName;
|
| 82 | private string _xmlWriterRootElementName;
|
| 83 | private ExtensionRegistry _extensionRegistry;
|
csharptest | 2cf6e1b | 2011-09-16 10:55:10 -0500 | [diff] [blame^] | 84 | private Dictionary<string, Converter<Stream, ICodedInputStream>> _mimeInputTypes;
|
| 85 | private Dictionary<string, Converter<Stream, ICodedOutputStream>> _mimeOutputTypes;
|
| 86 |
|
| 87 | /// <summary> Provides access to modify the mime-type input stream construction </summary>
|
| 88 | public IDictionary<string, Converter<Stream, ICodedInputStream>> MimeInputTypes
|
| 89 | {
|
| 90 | get
|
| 91 | {
|
| 92 | return _mimeInputTypes ??
|
| 93 | (_mimeInputTypes = new Dictionary<string, Converter<Stream, ICodedInputStream>>(
|
| 94 | MimeInputDefaults, StringComparer.OrdinalIgnoreCase));
|
| 95 | }
|
| 96 | }
|
| 97 |
|
| 98 | /// <summary> Provides access to modify the mime-type input stream construction </summary>
|
| 99 | public IDictionary<string, Converter<Stream, ICodedOutputStream>> MimeOutputTypes
|
| 100 | {
|
| 101 | get
|
| 102 | {
|
| 103 | return _mimeOutputTypes ??
|
| 104 | (_mimeOutputTypes = new Dictionary<string, Converter<Stream, ICodedOutputStream>>(
|
| 105 | MimeOutputDefaults, StringComparer.OrdinalIgnoreCase));
|
| 106 | }
|
| 107 | }
|
| 108 |
|
| 109 | internal IDictionary<string, Converter<Stream, ICodedInputStream>> MimeInputTypesReadOnly
|
| 110 | { get { return _mimeInputTypes ?? MimeInputDefaults; } }
|
| 111 |
|
| 112 | internal IDictionary<string, Converter<Stream, ICodedOutputStream>> MimeOutputTypesReadOnly
|
| 113 | { get { return _mimeOutputTypes ?? MimeOutputDefaults; } }
|
csharptest | c2d2c1a | 2011-09-08 20:02:11 -0500 | [diff] [blame] | 114 |
|
| 115 | /// <summary>
|
| 116 | /// The default content type to use if the input type is null or empty. If this
|
| 117 | /// value is not supplied an ArgumentOutOfRangeException exception will be raised.
|
| 118 | /// </summary>
|
| 119 | public string DefaultContentType
|
| 120 | {
|
| 121 | get { return _defaultContentType ?? String.Empty; }
|
| 122 | set { _defaultContentType = value; }
|
| 123 | }
|
| 124 |
|
| 125 | /// <summary>
|
| 126 | /// The extension registry to use when reading messages
|
| 127 | /// </summary>
|
| 128 | public ExtensionRegistry ExtensionRegistry
|
| 129 | {
|
| 130 | get { return _extensionRegistry ?? ExtensionRegistry.Empty; }
|
| 131 | set { _extensionRegistry = value; }
|
| 132 | }
|
| 133 |
|
| 134 | /// <summary>
|
| 135 | /// The name of the xml root element when reading messages
|
| 136 | /// </summary>
|
| 137 | public string XmlReaderRootElementName
|
| 138 | {
|
| 139 | get { return _xmlReaderRootElementName ?? XmlFormatReader.DefaultRootElementName; }
|
| 140 | set { _xmlReaderRootElementName = value; }
|
| 141 | }
|
| 142 |
|
| 143 | /// <summary>
|
| 144 | /// Xml reader options
|
| 145 | /// </summary>
|
| 146 | public XmlReaderOptions XmlReaderOptions { get; set; }
|
| 147 |
|
| 148 | /// <summary>
|
| 149 | /// True to use formatted output including new-lines and default indentation
|
| 150 | /// </summary>
|
| 151 | public bool FormattedOutput { get; set; }
|
| 152 |
|
| 153 | /// <summary>
|
| 154 | /// The name of the xml root element when writing messages
|
| 155 | /// </summary>
|
| 156 | public string XmlWriterRootElementName
|
| 157 | {
|
| 158 | get { return _xmlWriterRootElementName ?? XmlFormatWriter.DefaultRootElementName; }
|
| 159 | set { _xmlWriterRootElementName = value; }
|
| 160 | }
|
| 161 |
|
| 162 | /// <summary>
|
| 163 | /// Xml writer options
|
| 164 | /// </summary>
|
| 165 | public XmlWriterOptions XmlWriterOptions { get; set; }
|
| 166 | }
|
| 167 | } |