Commit a09b4910 authored by Jon Skeet's avatar Jon Skeet

Delete "lite" project and serialization project+code

We'll probably want a lot of the code from the serialization project when we do JSON, but enough of it will change that it's not worth keeping in a broken state for now.
parent d1b88f43
using System;
using System.Globalization;
using System.Xml;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Provides a base class for text-parsing readers
/// </summary>
public abstract class AbstractTextReader : AbstractReader
{
/// <summary> Constructs a new reader </summary>
protected AbstractTextReader() { }
/// <summary>
/// Reads a typed field as a string
/// </summary>
protected abstract bool ReadAsText(ref string textValue, Type type);
/// <summary>
/// Returns true if it was able to read a String from the input
/// </summary>
protected override bool Read(ref string value)
{
string text = null;
if (ReadAsText(ref text, typeof(string)))
{
value = text;
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a Boolean from the input
/// </summary>
protected override bool Read(ref bool value)
{
string text = null;
if (ReadAsText(ref text, typeof(bool)))
{
value = XmlConvert.ToBoolean(text);
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a Int32 from the input
/// </summary>
protected override bool Read(ref int value)
{
string text = null;
if (ReadAsText(ref text, typeof(int)))
{
value = XmlConvert.ToInt32(text);
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a UInt32 from the input
/// </summary>
protected override bool Read(ref uint value)
{
string text = null;
if (ReadAsText(ref text, typeof(uint)))
{
value = XmlConvert.ToUInt32(text);
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a Int64 from the input
/// </summary>
protected override bool Read(ref long value)
{
string text = null;
if (ReadAsText(ref text, typeof(long)))
{
value = XmlConvert.ToInt64(text);
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a UInt64 from the input
/// </summary>
protected override bool Read(ref ulong value)
{
string text = null;
if (ReadAsText(ref text, typeof(ulong)))
{
value = XmlConvert.ToUInt64(text);
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a Single from the input
/// </summary>
protected override bool Read(ref float value)
{
string text = null;
if (ReadAsText(ref text, typeof(float)))
{
value = XmlConvert.ToSingle(text);
return true;
}
return false;
}
/// <summary>
/// Returns true if it was able to read a Double from the input
/// </summary>
protected override bool Read(ref double value)
{
string text = null;
if (ReadAsText(ref text, typeof(double)))
{
value = XmlConvert.ToDouble(text);
return true;
}
return false;
}
/// <summary>
/// Provides decoding of bytes read from the input stream
/// </summary>
protected virtual ByteString DecodeBytes(string bytes)
{
return ByteString.FromBase64(bytes);
}
/// <summary>
/// Returns true if it was able to read a ByteString from the input
/// </summary>
protected override bool Read(ref ByteString value)
{
string text = null;
if (ReadAsText(ref text, typeof(ByteString)))
{
value = DecodeBytes(text);
return true;
}
return false;
}
/// <summary>
/// returns true if it was able to read a single value into the value reference. The value
/// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
/// </summary>
protected override bool ReadEnum(ref object value)
{
string text = null;
if (ReadAsText(ref text, typeof(Enum)))
{
int number;
if (FrameworkPortability.TryParseInt32(text, NumberStyles.Integer, FrameworkPortability.InvariantCulture, out number))
{
value = number;
return true;
}
value = text;
return true;
}
return false;
}
}
}
\ No newline at end of file
using System;
using System.Xml;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Provides a base class for text writers
/// </summary>
public abstract class AbstractTextWriter : AbstractWriter
{
/// <summary>
/// Encodes raw bytes to be written to the stream
/// </summary>
protected virtual string EncodeBytes(ByteString bytes)
{
return bytes.ToBase64();
}
/// <summary>
/// Writes a typed field as a text value
/// </summary>
protected abstract void WriteAsText(string field, string textValue, object typedValue);
/// <summary>
/// Writes a String value
/// </summary>
protected override void Write(string field, string value)
{
WriteAsText(field, value, value);
}
/// <summary>
/// Writes a Boolean value
/// </summary>
protected override void Write(string field, bool value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a Int32 value
/// </summary>
protected override void Write(string field, int value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a UInt32 value
/// </summary>
protected override void Write(string field, uint value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a Int64 value
/// </summary>
protected override void Write(string field, long value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a UInt64 value
/// </summary>
protected override void Write(string field, ulong value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a Single value
/// </summary>
protected override void Write(string field, float value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a Double value
/// </summary>
protected override void Write(string field, double value)
{
WriteAsText(field, XmlConvert.ToString(value), value);
}
/// <summary>
/// Writes a set of bytes
/// </summary>
protected override void Write(string field, ByteString value)
{
WriteAsText(field, EncodeBytes(value), value);
}
/// <summary>
/// Writes a System.Enum by the numeric and textual value
/// </summary>
protected override void WriteEnum(string field, int number, string name)
{
WriteAsText(field, name, number);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Globalization;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Allows reading messages from a name/value dictionary
/// </summary>
public class DictionaryReader : AbstractReader
{
private readonly IEnumerator<KeyValuePair<string, object>> _input;
private bool _ready;
/// <summary>
/// Creates a dictionary reader from an enumeration of KeyValuePair data, like an IDictionary
/// </summary>
public DictionaryReader(IEnumerable<KeyValuePair<string, object>> input)
{
_input = input.GetEnumerator();
_ready = _input.MoveNext();
}
/// <summary>
/// No-op
/// </summary>
public override void ReadMessageStart()
{ }
/// <summary>
/// No-op
/// </summary>
public override void ReadMessageEnd()
{ }
/// <summary>
/// Merges the contents of stream into the provided message builder
/// </summary>
public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
{
builder.WeakMergeFrom(this, registry);
return builder;
}
/// <summary>
/// Peeks at the next field in the input stream and returns what information is available.
/// </summary>
/// <remarks>
/// This may be called multiple times without actually reading the field. Only after the field
/// is either read, or skipped, should PeekNext return a different value.
/// </remarks>
protected override bool PeekNext(out string field)
{
field = _ready ? _input.Current.Key : null;
return _ready;
}
/// <summary>
/// Causes the reader to skip past this field
/// </summary>
protected override void Skip()
{
_ready = _input.MoveNext();
}
private bool GetValue<T>(ref T value)
{
if (!_ready)
{
return false;
}
object obj = _input.Current.Value;
if (obj is T)
{
value = (T) obj;
}
else
{
try
{
if (obj is IConvertible)
{
value = (T)Convert.ChangeType(obj, typeof(T), FrameworkPortability.InvariantCulture);
}
else
{
value = (T) obj;
}
}
catch
{
_ready = _input.MoveNext();
return false;
}
}
_ready = _input.MoveNext();
return true;
}
/// <summary>
/// Returns true if it was able to read a Boolean from the input
/// </summary>
protected override bool Read(ref bool value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a Int32 from the input
/// </summary>
protected override bool Read(ref int value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a UInt32 from the input
/// </summary>
protected override bool Read(ref uint value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a Int64 from the input
/// </summary>
protected override bool Read(ref long value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a UInt64 from the input
/// </summary>
protected override bool Read(ref ulong value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a Single from the input
/// </summary>
protected override bool Read(ref float value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a Double from the input
/// </summary>
protected override bool Read(ref double value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a String from the input
/// </summary>
protected override bool Read(ref string value)
{
return GetValue(ref value);
}
/// <summary>
/// Returns true if it was able to read a ByteString from the input
/// </summary>
protected override bool Read(ref ByteString value)
{
byte[] rawbytes = null;
if (GetValue(ref rawbytes))
{
value = ByteString.CopyFrom(rawbytes);
return true;
}
return false;
}
/// <summary>
/// returns true if it was able to read a single value into the value reference. The value
/// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
/// </summary>
protected override bool ReadEnum(ref object value)
{
return GetValue(ref value);
}
/// <summary>
/// Merges the input stream into the provided IBuilderLite
/// </summary>
protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
{
IDictionary<string, object> values = null;
if (GetValue(ref values))
{
new DictionaryReader(values).Merge(builder, registry);
return true;
}
return false;
}
public override bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
{
object[] array = null;
if (GetValue(ref array))
{
if (typeof(T) == typeof(ByteString))
{
ICollection<ByteString> output = (ICollection<ByteString>) items;
foreach (byte[] item in array)
{
output.Add(ByteString.CopyFrom(item));
}
}
else
{
foreach (T item in array)
{
items.Add(item);
}
}
return true;
}
return false;
}
public override bool ReadEnumArray(string field, ICollection<object> items)
{
object[] array = null;
if (GetValue(ref array))
{
foreach (object item in array)
{
items.Add(item);
}
return true;
}
return false;
}
public override bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
ExtensionRegistry registry)
{
object[] array = null;
if (GetValue(ref array))
{
foreach (IDictionary<string, object> item in array)
{
IBuilderLite builder = messageType.WeakCreateBuilderForType();
new DictionaryReader(item).Merge(builder);
items.Add((T) builder.WeakBuild());
}
return true;
}
return false;
}
public override bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
ExtensionRegistry registry)
{
return ReadMessageArray(field, items, messageType, registry);
}
}
}
\ No newline at end of file
using System;
using System.Collections;
using System.Collections.Generic;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Allows writing messages to a name/value dictionary
/// </summary>
public class DictionaryWriter : AbstractWriter
{
private readonly IDictionary<string, object> _output;
/// <summary>
/// Constructs a writer using a new dictionary
/// </summary>
public DictionaryWriter()
: this(new Dictionary<string, object>(StringComparer.Ordinal))
{
}
/// <summary>
/// Constructs a writer using an existing dictionary
/// </summary>
public DictionaryWriter(IDictionary<string, object> output)
{
ThrowHelper.ThrowIfNull(output, "output");
_output = output;
}
/// <summary>
/// Creates the dictionary instance for a child message.
/// </summary>
protected virtual DictionaryWriter Create()
{
return new DictionaryWriter();
}
/// <summary>
/// Accesses the dictionary that is backing this writer
/// </summary>
public IDictionary<string, object> ToDictionary()
{
return _output;
}
/// <summary>
/// Writes the message to the the formatted stream.
/// </summary>
public override void WriteMessage(IMessageLite message)
{
message.WriteTo(this);
}
/// <summary>
/// No-op
/// </summary>
public override void WriteMessageStart()
{ }
/// <summary>
/// No-op
/// </summary>
public override void WriteMessageEnd()
{ }
/// <summary>
/// Writes a Boolean value
/// </summary>
protected override void Write(string field, bool value)
{
_output[field] = value;
}
/// <summary>
/// Writes a Int32 value
/// </summary>
protected override void Write(string field, int value)
{
_output[field] = value;
}
/// <summary>
/// Writes a UInt32 value
/// </summary>
protected override void Write(string field, uint value)
{
_output[field] = value;
}
/// <summary>
/// Writes a Int64 value
/// </summary>
protected override void Write(string field, long value)
{
_output[field] = value;
}
/// <summary>
/// Writes a UInt64 value
/// </summary>
protected override void Write(string field, ulong value)
{
_output[field] = value;
}
/// <summary>
/// Writes a Single value
/// </summary>
protected override void Write(string field, float value)
{
_output[field] = value;
}
/// <summary>
/// Writes a Double value
/// </summary>
protected override void Write(string field, double value)
{
_output[field] = value;
}
/// <summary>
/// Writes a String value
/// </summary>
protected override void Write(string field, string value)
{
_output[field] = value;
}
/// <summary>
/// Writes a set of bytes
/// </summary>
protected override void Write(string field, ByteString value)
{
_output[field] = value.ToByteArray();
}
/// <summary>
/// Writes a message or group as a field
/// </summary>
protected override void WriteMessageOrGroup(string field, IMessageLite message)
{
DictionaryWriter writer = Create();
writer.WriteMessage(message);
_output[field] = writer.ToDictionary();
}
/// <summary>
/// Writes a System.Enum by the numeric and textual value
/// </summary>
protected override void WriteEnum(string field, int number, string name)
{
_output[field] = number;
}
/// <summary>
/// Writes an array of field values
/// </summary>
protected override void WriteArray(FieldType fieldType, string field, IEnumerable items)
{
List<object> objects = new List<object>();
foreach (object o in items)
{
switch (fieldType)
{
case FieldType.Group:
case FieldType.Message:
{
DictionaryWriter writer = Create();
writer.WriteMessage((IMessageLite) o);
objects.Add(writer.ToDictionary());
}
break;
case FieldType.Bytes:
objects.Add(((ByteString) o).ToByteArray());
break;
case FieldType.Enum:
if (o is IEnumLite)
{
objects.Add(((IEnumLite) o).Number);
}
else
{
objects.Add((int) o);
}
break;
default:
objects.Add(o);
break;
}
}
_output[field] = objects.ToArray();
}
}
}
\ No newline at end of file
using System;
using System.Text;
using System.IO;
using System.Xml;
using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.Serialization.Http;
namespace Google.ProtocolBuffers
{
/// <summary>
/// Extension methods for using serializers on instances of IMessageLite/IBuilderLite
/// </summary>
public static class Extensions
{
#region IMessageLite Extension
/// <summary>
/// Serializes the message to JSON text. This is a trivial wrapper
/// around Serialization.JsonFormatWriter.WriteMessage.
/// </summary>
public static string ToJson(
#if !NOEXTENSIONS
this
#endif
IMessageLite message)
{
JsonFormatWriter w = JsonFormatWriter.CreateInstance();
w.WriteMessage(message);
return w.ToString();
}
/// <summary>
/// Serializes the message to XML text. This is a trivial wrapper
/// around Serialization.XmlFormatWriter.WriteMessage.
/// </summary>
public static string ToXml(
#if !NOEXTENSIONS
this
#endif
IMessageLite message)
{
StringWriter w = new StringWriter(new StringBuilder(4096));
XmlFormatWriter.CreateInstance(w).WriteMessage(message);
return w.ToString();
}
/// <summary>
/// Serializes the message to XML text using the element name provided.
/// This is a trivial wrapper around Serialization.XmlFormatWriter.WriteMessage.
/// </summary>
public static string ToXml(
#if !NOEXTENSIONS
this
#endif
IMessageLite message, string rootElementName)
{
StringWriter w = new StringWriter(new StringBuilder(4096));
XmlFormatWriter.CreateInstance(w).WriteMessage(rootElementName, message);
return w.ToString();
}
/// <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();
}
#endregion
#region IBuilderLite Extensions
/// <summary>
/// Merges a JSON object into this builder and returns
/// </summary>
public static TBuilder MergeFromJson<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, string jsonText) where TBuilder : IBuilderLite
{
return JsonFormatReader.CreateInstance(jsonText)
.Merge(builder);
}
/// <summary>
/// Merges a JSON object into this builder and returns
/// </summary>
public static TBuilder MergeFromJson<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, TextReader reader) where TBuilder : IBuilderLite
{
return MergeFromJson(builder, reader, ExtensionRegistry.Empty);
}
/// <summary>
/// Merges a JSON object into this builder using the extensions provided and returns
/// </summary>
public static TBuilder MergeFromJson<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, TextReader reader, ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite
{
return JsonFormatReader.CreateInstance(reader)
.Merge(builder, extensionRegistry);
}
/// <summary>
/// Merges an XML object into this builder and returns
/// </summary>
public static TBuilder MergeFromXml<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, XmlReader reader) where TBuilder : IBuilderLite
{
return MergeFromXml(builder, XmlFormatReader.DefaultRootElementName, reader, ExtensionRegistry.Empty);
}
/// <summary>
/// Merges an XML object into this builder and returns
/// </summary>
public static TBuilder MergeFromXml<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, string rootElementName, XmlReader reader) where TBuilder : IBuilderLite
{
return MergeFromXml(builder, rootElementName, reader, ExtensionRegistry.Empty);
}
/// <summary>
/// Merges an XML object into this builder using the extensions provided and returns
/// </summary>
public static TBuilder MergeFromXml<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, string rootElementName, XmlReader reader,
ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite
{
return XmlFormatReader.CreateInstance(reader)
.Merge(rootElementName, builder, extensionRegistry);
}
/// <summary>
/// Merges the message from the input stream based on the contentType provided
/// </summary>
/// <typeparam name="TBuilder">A type derived from IBuilderLite</typeparam>
/// <param name="builder">An instance of a message builder</param>
/// <param name="options">Options specific to reading this message and/or content type</param>
/// <param name="contentType">The mime type of the input stream content</param>
/// <param name="input">The stream to read the message from</param>
/// <returns>The same builder instance that was supplied in the builder parameter</returns>
public static TBuilder MergeFrom<TBuilder>(
#if !NOEXTENSIONS
this
#endif
TBuilder builder, MessageFormatOptions options, string contentType, Stream input) where TBuilder : IBuilderLite
{
ICodedInputStream codedInput = MessageFormatFactory.CreateInputStream(options, contentType, input);
codedInput.ReadMessageStart();
builder.WeakMergeFrom(codedInput, options.ExtensionRegistry);
codedInput.ReadMessageEnd();
return builder;
}
#endregion
}
}
using System;
using System.IO;
using System.Text;
namespace Google.ProtocolBuffers.Serialization.Http
{
/// <summary>
/// Allows reading messages from a name/value dictionary
/// </summary>
public class FormUrlEncodedReader : AbstractTextReader
{
private readonly TextReader _input;
private string _fieldName, _fieldValue;
private bool _ready;
/// <summary>
/// Creates a dictionary reader from an enumeration of KeyValuePair data, like an IDictionary
/// </summary>
FormUrlEncodedReader(TextReader input)
{
_input = input;
int ch = input.Peek();
if (ch == '?')
{
input.Read();
}
_ready = ReadNext();
}
#region CreateInstance overloads
/// <summary>
/// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
/// </summary>
public static FormUrlEncodedReader CreateInstance(Stream stream)
{
return new FormUrlEncodedReader(new StreamReader(stream, Encoding.UTF8, false));
}
/// <summary>
/// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
/// </summary>
public static FormUrlEncodedReader CreateInstance(byte[] bytes)
{
return new FormUrlEncodedReader(new StreamReader(new MemoryStream(bytes, false), Encoding.UTF8, false));
}
/// <summary>
/// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
/// </summary>
public static FormUrlEncodedReader CreateInstance(string text)
{
return new FormUrlEncodedReader(new StringReader(text));
}
/// <summary>
/// Constructs a FormUrlEncodedReader to parse form data, or url query text into a message.
/// </summary>
public static FormUrlEncodedReader CreateInstance(TextReader input)
{
return new FormUrlEncodedReader(input);
}
#endregion
private bool ReadNext()
{
StringBuilder field = new StringBuilder(32);
StringBuilder value = new StringBuilder(64);
int ch;
while (-1 != (ch = _input.Read()) && ch != '=' && ch != '&')
{
field.Append((char)ch);
}
if (ch != -1 && ch != '&')
{
while (-1 != (ch = _input.Read()) && ch != '&')
{
value.Append((char)ch);
}
}
_fieldName = field.ToString();
_fieldValue = Uri.UnescapeDataString(value.Replace('+', ' ').ToString());
return !String.IsNullOrEmpty(_fieldName);
}
/// <summary>
/// No-op
/// </summary>
public override void ReadMessageStart()
{ }
/// <summary>
/// No-op
/// </summary>
public override void ReadMessageEnd()
{ }
/// <summary>
/// Merges the contents of stream into the provided message builder
/// </summary>
public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
{
builder.WeakMergeFrom(this, registry);
return builder;
}
/// <summary>
/// Causes the reader to skip past this field
/// </summary>
protected override void Skip()
{
_ready = ReadNext();
}
/// <summary>
/// Peeks at the next field in the input stream and returns what information is available.
/// </summary>
/// <remarks>
/// This may be called multiple times without actually reading the field. Only after the field
/// is either read, or skipped, should PeekNext return a different value.
/// </remarks>
protected override bool PeekNext(out string field)
{
field = _ready ? _fieldName : null;
return field != null;
}
/// <summary>
/// Returns true if it was able to read a String from the input
/// </summary>
protected override bool ReadAsText(ref string value, Type typeInfo)
{
if (_ready)
{
value = _fieldValue;
_ready = ReadNext();
return true;
}
return false;
}
/// <summary>
/// It's unlikely this will work for anything but text data as bytes UTF8 are transformed to text and back to bytes
/// </summary>
protected override ByteString DecodeBytes(string bytes)
{ return ByteString.CopyFromUtf8(bytes); }
/// <summary>
/// Not Supported
/// </summary>
public override bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
{ throw new NotSupportedException(); }
/// <summary>
/// Not Supported
/// </summary>
protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
{ throw new NotSupportedException(); }
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Xml;
using System.Text;
namespace Google.ProtocolBuffers.Serialization.Http
{
/// <summary>
/// Extensions and helpers to abstract the reading/writing of messages by a client-specified content type.
/// </summary>
public static class MessageFormatFactory
{
/// <summary>
/// Constructs an ICodedInputStream from the input stream based on the contentType provided
/// </summary>
/// <param name="options">Options specific to reading this message and/or content type</param>
/// <param name="contentType">The mime type of the input stream content</param>
/// <param name="input">The stream to read the message from</param>
/// <returns>The ICodedInputStream that can be given to the IBuilder.MergeFrom(...) method</returns>
public static ICodedInputStream CreateInputStream(MessageFormatOptions options, string contentType, Stream input)
{
ICodedInputStream codedInput = ContentTypeToInputStream(contentType, options, input);
if (codedInput is XmlFormatReader)
{
XmlFormatReader reader = (XmlFormatReader)codedInput;
reader.RootElementName = options.XmlReaderRootElementName;
reader.Options = options.XmlReaderOptions;
}
return codedInput;
}
/// <summary>
/// Writes the message instance to the stream using the content type provided
/// </summary>
/// <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>
/// <remarks> If you do not dispose of ICodedOutputStream some formats may yield incomplete output </remarks>
public static ICodedOutputStream CreateOutputStream(MessageFormatOptions options, string contentType, Stream output)
{
ICodedOutputStream codedOutput = ContentTypeToOutputStream(contentType, options, output);
if (codedOutput is JsonFormatWriter)
{
JsonFormatWriter writer = (JsonFormatWriter)codedOutput;
if (options.FormattedOutput)
{
writer.Formatted();
}
}
else if (codedOutput is XmlFormatWriter)
{
XmlFormatWriter writer = (XmlFormatWriter)codedOutput;
if (options.FormattedOutput)
{
XmlWriterSettings settings = new XmlWriterSettings()
{
CheckCharacters = false,
NewLineHandling = NewLineHandling.Entitize,
OmitXmlDeclaration = true,
Encoding = new UTF8Encoding(false),
Indent = true,
IndentChars = " ",
};
// Don't know how else to change xml writer options?
codedOutput = writer = XmlFormatWriter.CreateInstance(XmlWriter.Create(output, settings));
}
writer.RootElementName = options.XmlWriterRootElementName;
writer.Options = options.XmlWriterOptions;
}
return codedOutput;
}
private static ICodedInputStream ContentTypeToInputStream(string contentType, MessageFormatOptions options, Stream input)
{
contentType = (contentType ?? String.Empty).Split(';')[0].Trim();
CodedInputBuilder factory;
if(!options.MimeInputTypesReadOnly.TryGetValue(contentType, out factory) || factory == null)
{
if(String.IsNullOrEmpty(options.DefaultContentType) ||
!options.MimeInputTypesReadOnly.TryGetValue(options.DefaultContentType, out factory) || factory == null)
{
throw new ArgumentOutOfRangeException("contentType");
}
}
return factory(input);
}
private static ICodedOutputStream ContentTypeToOutputStream(string contentType, MessageFormatOptions options, Stream output)
{
contentType = (contentType ?? String.Empty).Split(';')[0].Trim();
CodedOutputBuilder factory;
if (!options.MimeOutputTypesReadOnly.TryGetValue(contentType, out factory) || factory == null)
{
if (String.IsNullOrEmpty(options.DefaultContentType) ||
!options.MimeOutputTypesReadOnly.TryGetValue(options.DefaultContentType, out factory) || factory == null)
{
throw new ArgumentOutOfRangeException("contentType");
}
}
return factory(output);
}
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
namespace Google.ProtocolBuffers.Serialization.Http
{
/// <summary>
/// A delegate used to specify a method that constructs an ICodedInputStream from a .NET Stream.
/// </summary>
public delegate ICodedInputStream CodedInputBuilder(Stream stream);
/// <summary>
/// A delegate used to specify a method that constructs an ICodedOutputStream from a .NET Stream.
/// </summary>
public delegate ICodedOutputStream CodedOutputBuilder(Stream stream);
/// <summary>
/// Defines control information for the various formatting used with HTTP services
/// </summary>
public class MessageFormatOptions
{
/// <summary>The mime type for xml content</summary>
/// <remarks>Other valid xml mime types include: application/binary, application/x-protobuf</remarks>
public const string ContentTypeProtoBuffer = "application/vnd.google.protobuf";
/// <summary>The mime type for xml content</summary>
/// <remarks>Other valid xml mime types include: text/xml</remarks>
public const string ContentTypeXml = "application/xml";
/// <summary>The mime type for json content</summary>
/// <remarks>
/// Other valid json mime types include: application/json, application/x-json,
/// application/x-javascript, text/javascript, text/x-javascript, text/x-json, text/json
/// </remarks>
public const string ContentTypeJson = "application/json";
/// <summary>The mime type for query strings and x-www-form-urlencoded content</summary>
/// <remarks>This mime type is input-only</remarks>
public const string ContentFormUrlEncoded = "application/x-www-form-urlencoded";
/// <summary>
/// Default mime-type handling for input
/// </summary>
private static readonly IDictionary<string, CodedInputBuilder> MimeInputDefaults =
new ReadOnlyDictionary<string, CodedInputBuilder>(
new Dictionary<string, CodedInputBuilder>(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},
}
);
/// <summary>
/// Default mime-type handling for output
/// </summary>
private static readonly IDictionary<string, CodedOutputBuilder> MimeOutputDefaults =
new ReadOnlyDictionary<string, CodedOutputBuilder>(
new Dictionary<string, CodedOutputBuilder>(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<string, CodedInputBuilder> _mimeInputTypes;
private Dictionary<string, CodedOutputBuilder> _mimeOutputTypes;
/// <summary> Provides access to modify the mime-type input stream construction </summary>
public IDictionary<string, CodedInputBuilder> MimeInputTypes
{
get
{
return _mimeInputTypes ??
(_mimeInputTypes = new Dictionary<string, CodedInputBuilder>(
MimeInputDefaults, StringComparer.OrdinalIgnoreCase));
}
}
/// <summary> Provides access to modify the mime-type input stream construction </summary>
public IDictionary<string, CodedOutputBuilder> MimeOutputTypes
{
get
{
return _mimeOutputTypes ??
(_mimeOutputTypes = new Dictionary<string, CodedOutputBuilder>(
MimeOutputDefaults, StringComparer.OrdinalIgnoreCase));
}
}
internal IDictionary<string, CodedInputBuilder> MimeInputTypesReadOnly
{ get { return _mimeInputTypes ?? MimeInputDefaults; } }
internal IDictionary<string, CodedOutputBuilder> MimeOutputTypesReadOnly
{ get { return _mimeOutputTypes ?? MimeOutputDefaults; } }
/// <summary>
/// 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.
/// </summary>
public string DefaultContentType
{
get { return _defaultContentType ?? String.Empty; }
set { _defaultContentType = value; }
}
/// <summary>
/// The extension registry to use when reading messages
/// </summary>
public ExtensionRegistry ExtensionRegistry
{
get { return _extensionRegistry ?? ExtensionRegistry.Empty; }
set { _extensionRegistry = value; }
}
/// <summary>
/// The name of the xml root element when reading messages
/// </summary>
public string XmlReaderRootElementName
{
get { return _xmlReaderRootElementName ?? XmlFormatReader.DefaultRootElementName; }
set { _xmlReaderRootElementName = value; }
}
/// <summary>
/// Xml reader options
/// </summary>
public XmlReaderOptions XmlReaderOptions { get; set; }
/// <summary>
/// True to use formatted output including new-lines and default indentation
/// </summary>
public bool FormattedOutput { get; set; }
/// <summary>
/// The name of the xml root element when writing messages
/// </summary>
public string XmlWriterRootElementName
{
get { return _xmlWriterRootElementName ?? XmlFormatWriter.DefaultRootElementName; }
set { _xmlWriterRootElementName = value; }
}
/// <summary>
/// Xml writer options
/// </summary>
public XmlWriterOptions XmlWriterOptions { get; set; }
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// JsonFormatReader is used to parse Json into a message or an array of messages
/// </summary>
public class JsonFormatReader : AbstractTextReader
{
private readonly JsonCursor _input;
// The expected token that ends the current item, either ']' or '}'
private readonly Stack<int> _stopChar;
private enum ReaderState
{
Start,
BeginValue,
EndValue,
BeginObject,
BeginArray
}
private string _current;
private ReaderState _state;
/// <summary>
/// Constructs a JsonFormatReader to parse Json into a message, this method does not use text encoding, all bytes MUST
/// represent ASCII character values.
/// </summary>
public static JsonFormatReader CreateInstance(Stream stream)
{
return new JsonFormatReader(JsonCursor.CreateInstance(stream));
}
/// <summary>
/// Constructs a JsonFormatReader to parse Json into a message, this method does not use text encoding, all bytes MUST
/// represent ASCII character values.
/// </summary>
public static JsonFormatReader CreateInstance(byte[] bytes)
{
return new JsonFormatReader(JsonCursor.CreateInstance(bytes));
}
/// <summary>
/// Constructs a JsonFormatReader to parse Json into a message
/// </summary>
public static JsonFormatReader CreateInstance(string jsonText)
{
return new JsonFormatReader(JsonCursor.CreateInstance(jsonText));
}
/// <summary>
/// Constructs a JsonFormatReader to parse Json into a message
/// </summary>
public static JsonFormatReader CreateInstance(TextReader input)
{
return new JsonFormatReader(JsonCursor.CreateInstance(input));
}
/// <summary>
/// Constructs a JsonFormatReader to parse Json into a message
/// </summary>
internal JsonFormatReader(JsonCursor input)
{
_input = input;
_stopChar = new Stack<int>();
_stopChar.Push(-1);
_state = ReaderState.Start;
}
/// <summary>
/// Constructs a JsonFormatReader to parse Json into a message
/// </summary>
protected JsonFormatReader(TextReader input)
: this(JsonCursor.CreateInstance(input))
{
}
/// <summary>
/// Returns true if the reader is currently on an array element
/// </summary>
public bool IsArrayMessage
{
get { return _input.NextChar == '['; }
}
/// <summary>
/// Returns an enumerator that is used to cursor over an array of messages
/// </summary>
/// <remarks>
/// This is generally used when receiving an array of messages rather than a single root message
/// </remarks>
public IEnumerable<JsonFormatReader> EnumerateArray()
{
foreach (string ignored in ForeachArrayItem(_current))
{
yield return this;
}
}
/// <summary>
/// Reads the root-message preamble specific to this formatter
/// </summary>
public override void ReadMessageStart()
{
_input.Consume('{');
_stopChar.Push('}');
_state = ReaderState.BeginObject;
}
/// <summary>
/// Reads the root-message close specific to this formatter
/// </summary>
public override void ReadMessageEnd()
{
_input.Consume((char)_stopChar.Pop());
_state = ReaderState.EndValue;
}
/// <summary>
/// Merges the contents of stream into the provided message builder
/// </summary>
public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
{
ReadMessageStart();
builder.WeakMergeFrom(this, registry);
ReadMessageEnd();
return builder;
}
/// <summary>
/// Causes the reader to skip past this field
/// </summary>
protected override void Skip()
{
object temp;
_input.ReadVariant(out temp);
_state = ReaderState.EndValue;
}
/// <summary>
/// Peeks at the next field in the input stream and returns what information is available.
/// </summary>
/// <remarks>
/// This may be called multiple times without actually reading the field. Only after the field
/// is either read, or skipped, should PeekNext return a different value.
/// </remarks>
protected override bool PeekNext(out string field)
{
field = _current;
if (_state == ReaderState.BeginValue)
{
return true;
}
int next = _input.NextChar;
if (next == _stopChar.Peek())
{
return false;
}
_input.Assert(next != -1, "Unexpected end of file.");
//not sure about this yet, it will allow {, "a":true }
if (_state == ReaderState.EndValue && !_input.TryConsume(','))
{
return false;
}
field = _current = _input.ReadString();
_input.Consume(':');
_state = ReaderState.BeginValue;
return true;
}
/// <summary>
/// Returns true if it was able to read a String from the input
/// </summary>
protected override bool ReadAsText(ref string value, Type typeInfo)
{
object temp;
JsonCursor.JsType type = _input.ReadVariant(out temp);
_state = ReaderState.EndValue;
_input.Assert(type != JsonCursor.JsType.Array && type != JsonCursor.JsType.Object,
"Encountered {0} while expecting {1}", type, typeInfo);
if (type == JsonCursor.JsType.Null)
{
return false;
}
if (type == JsonCursor.JsType.True)
{
value = "1";
}
else if (type == JsonCursor.JsType.False)
{
value = "0";
}
else
{
value = temp as string;
}
//exponent representation of integer number:
if (value != null && type == JsonCursor.JsType.Number &&
(typeInfo != typeof(double) && typeInfo != typeof(float)) &&
value.IndexOf("e", StringComparison.OrdinalIgnoreCase) > 0)
{
value = XmlConvert.ToString((long) Math.Round(XmlConvert.ToDouble(value), 0));
}
return value != null;
}
/// <summary>
/// Returns true if it was able to read a ByteString from the input
/// </summary>
protected override bool Read(ref ByteString value)
{
string bytes = null;
if (Read(ref bytes))
{
value = ByteString.FromBase64(bytes);
return true;
}
return false;
}
/// <summary>
/// Cursors through the array elements and stops at the end of the array
/// </summary>
protected override IEnumerable<string> ForeachArrayItem(string field)
{
_input.Consume('[');
_stopChar.Push(']');
_state = ReaderState.BeginArray;
while (_input.NextChar != ']')
{
_current = field;
yield return field;
if (!_input.TryConsume(','))
{
break;
}
}
_input.Consume((char) _stopChar.Pop());
_state = ReaderState.EndValue;
}
/// <summary>
/// Merges the input stream into the provided IBuilderLite
/// </summary>
protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
{
Merge(builder, registry);
return true;
}
}
}
\ No newline at end of file
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ProtocolBuffers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ProtocolBuffers")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("2.4.1.555")]
[assembly: AssemblyVersion("2.4.1.555")]
#if !NOFILEVERSION
[assembly: AssemblyFileVersion("2.4.1.555")]
#endif
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{231391AF-449C-4A39-986C-AD7F270F4750}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
<AssemblyName>Google.ProtocolBuffers.Serialization</AssemblyName>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile92</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
<Link>FrameworkPortability.cs</Link>
</Compile>
<Compile Include="Extensions.cs" />
<Compile Include="Http\FormUrlEncodedReader.cs" />
<Compile Include="Http\MessageFormatFactory.cs" />
<Compile Include="Http\MessageFormatOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AbstractReader.cs" />
<Compile Include="AbstractTextReader.cs" />
<Compile Include="AbstractTextWriter.cs" />
<Compile Include="AbstractWriter.cs" />
<Compile Include="DictionaryReader.cs" />
<Compile Include="DictionaryWriter.cs" />
<Compile Include="JsonFormatReader.cs" />
<Compile Include="JsonFormatWriter.cs" />
<Compile Include="JsonTextCursor.cs" />
<Compile Include="RecursionLimitExceeded.cs" />
<Compile Include="XmlFormatReader.cs" />
<Compile Include="XmlFormatWriter.cs" />
<Compile Include="XmlReaderOptions.cs" />
<Compile Include="XmlWriterOptions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffers</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Google.ProtocolBuffers.Serialization</RootNamespace>
<AssemblyName>Google.ProtocolBuffersLite.Serialization</AssemblyName>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile92</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' != 'v2.0'" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\ProtocolBuffers\FrameworkPortability.cs">
<Link>FrameworkPortability.cs</Link>
</Compile>
<Compile Include="Extensions.cs" />
<Compile Include="Http\FormUrlEncodedReader.cs" />
<Compile Include="Http\MessageFormatFactory.cs" />
<Compile Include="Http\MessageFormatOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AbstractReader.cs" />
<Compile Include="AbstractTextReader.cs" />
<Compile Include="AbstractTextWriter.cs" />
<Compile Include="AbstractWriter.cs" />
<Compile Include="DictionaryReader.cs" />
<Compile Include="DictionaryWriter.cs" />
<Compile Include="JsonFormatReader.cs" />
<Compile Include="JsonFormatWriter.cs" />
<Compile Include="JsonTextCursor.cs" />
<Compile Include="RecursionLimitExceeded.cs" />
<Compile Include="XmlFormatReader.cs" />
<Compile Include="XmlFormatWriter.cs" />
<Compile Include="XmlReaderOptions.cs" />
<Compile Include="XmlWriterOptions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.csproj">
<Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffersLite</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// The exception raised when a recursion limit is reached while parsing input.
/// </summary>
public sealed class RecursionLimitExceededException : FormatException
{
const string message = "Possible malicious message had too many levels of nesting.";
internal RecursionLimitExceededException() : base(message)
{
}
}
}
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Writes a proto buffer to an XML document or fragment. .NET 3.5 users may also
/// use this class to produce Json by setting the options to support Json and providing
/// an XmlWriter obtained from <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory"/>.
/// </summary>
public class XmlFormatWriter : AbstractTextWriter
{
private static readonly Encoding DefaultEncoding = new UTF8Encoding(false);
public const string DefaultRootElementName = "root";
private readonly XmlWriter _output;
// The default element name used for WriteMessageStart
private string _rootElementName;
// Used to assert matching WriteMessageStart/WriteMessageEnd calls
private int _messageOpenCount;
private static XmlWriterSettings DefaultSettings(Encoding encoding)
{
return new XmlWriterSettings()
{
CheckCharacters = false,
NewLineHandling = NewLineHandling.Entitize,
OmitXmlDeclaration = true,
Encoding = encoding,
};
}
/// <summary>
/// Constructs the XmlFormatWriter to write to the given TextWriter
/// </summary>
public static XmlFormatWriter CreateInstance(TextWriter output)
{
return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(output.Encoding)));
}
/// <summary>
/// Constructs the XmlFormatWriter to write to the given stream
/// </summary>
public static XmlFormatWriter CreateInstance(Stream output)
{
return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(DefaultEncoding)));
}
/// <summary>
/// Constructs the XmlFormatWriter to write to the given stream
/// </summary>
public static XmlFormatWriter CreateInstance(Stream output, Encoding encoding)
{
return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(encoding)));
}
/// <summary>
/// Constructs the XmlFormatWriter to write to the given XmlWriter
/// </summary>
public static XmlFormatWriter CreateInstance(XmlWriter output)
{
return new XmlFormatWriter(output);
}
protected XmlFormatWriter(XmlWriter output)
{
_output = output;
_messageOpenCount = 0;
_rootElementName = DefaultRootElementName;
}
/// <summary>
/// Gets or sets the default element name to use when using the Merge&lt;TBuilder>()
/// </summary>
public string RootElementName
{
get { return _rootElementName; }
set
{
ThrowHelper.ThrowIfNull(value, "RootElementName");
_rootElementName = value;
}
}
/// <summary>
/// Gets or sets the options to use while generating the XML
/// </summary>
public XmlWriterOptions Options { get; set; }
/// <summary>
/// Sets the options to use while generating the XML
/// </summary>
public XmlFormatWriter SetOptions(XmlWriterOptions options)
{
Options = options;
return this;
}
private bool TestOption(XmlWriterOptions option)
{
return (Options & option) != 0;
}
/// <summary>
/// Completes any pending write operations
/// </summary>
public override void Flush()
{
_output.Flush();
base.Flush();
}
/// <summary>
/// Used to write the root-message preamble, in xml this is open element for RootElementName,
/// by default "&lt;root&gt;". After this call you can call IMessageLite.MergeTo(...) and
/// complete the message with a call to WriteMessageEnd().
/// </summary>
public override void WriteMessageStart()
{
WriteMessageStart(_rootElementName);
}
/// <summary>
/// Used to write the root-message preamble, in xml this is open element for elementName.
/// After this call you can call IMessageLite.MergeTo(...) and complete the message with
/// a call to WriteMessageEnd().
/// </summary>
public void WriteMessageStart(string elementName)
{
if (TestOption(XmlWriterOptions.OutputJsonTypes))
{
_output.WriteStartElement("root"); // json requires this is the root-element
_output.WriteAttributeString("type", "object");
}
else
{
_output.WriteStartElement(elementName);
}
_messageOpenCount++;
}
/// <summary>
/// Used to complete a root-message previously started with a call to WriteMessageStart()
/// </summary>
public override void WriteMessageEnd()
{
if (_messageOpenCount <= 0)
{
throw new InvalidOperationException();
}
_output.WriteEndElement();
_output.Flush();
_messageOpenCount--;
}
/// <summary>
/// Writes a message as an element using the name defined in <see cref="RootElementName"/>
/// </summary>
public override void WriteMessage(IMessageLite message)
{
WriteMessage(_rootElementName, message);
}
/// <summary>
/// Writes a message as an element with the given name
/// </summary>
public void WriteMessage(string elementName, IMessageLite message)
{
WriteMessageStart(elementName);
message.WriteTo(this);
WriteMessageEnd();
}
/// <summary>
/// Writes a message
/// </summary>
protected override void WriteMessageOrGroup(string field, IMessageLite message)
{
_output.WriteStartElement(field);
if (TestOption(XmlWriterOptions.OutputJsonTypes))
{
_output.WriteAttributeString("type", "object");
}
message.WriteTo(this);
_output.WriteEndElement();
}
/// <summary>
/// Writes a String value
/// </summary>
protected override void WriteAsText(string field, string textValue, object typedValue)
{
_output.WriteStartElement(field);
if (TestOption(XmlWriterOptions.OutputJsonTypes))
{
if (typedValue is int || typedValue is uint || typedValue is long || typedValue is ulong ||
typedValue is double || typedValue is float)
{
_output.WriteAttributeString("type", "number");
}
else if (typedValue is bool)
{
_output.WriteAttributeString("type", "boolean");
}
}
_output.WriteString(textValue);
//Empty strings should not be written as empty elements '<item/>', rather as '<item></item>'
if (_output.WriteState == WriteState.Element)
{
_output.WriteRaw("");
}
_output.WriteEndElement();
}
/// <summary>
/// Writes an array of field values
/// </summary>
protected override void WriteArray(FieldType fieldType, string field, IEnumerable items)
{
//see if it's empty
IEnumerator eitems = items.GetEnumerator();
try
{
if (!eitems.MoveNext())
{
return;
}
}
finally
{
if (eitems is IDisposable)
{
((IDisposable) eitems).Dispose();
}
}
if (TestOption(XmlWriterOptions.OutputNestedArrays | XmlWriterOptions.OutputJsonTypes))
{
_output.WriteStartElement(field);
if (TestOption(XmlWriterOptions.OutputJsonTypes))
{
_output.WriteAttributeString("type", "array");
}
base.WriteArray(fieldType, "item", items);
_output.WriteEndElement();
}
else
{
base.WriteArray(fieldType, field, items);
}
}
/// <summary>
/// Writes a System.Enum by the numeric and textual value
/// </summary>
protected override void WriteEnum(string field, int number, string name)
{
_output.WriteStartElement(field);
if (!TestOption(XmlWriterOptions.OutputJsonTypes) && TestOption(XmlWriterOptions.OutputEnumValues))
{
_output.WriteAttributeString("value", XmlConvert.ToString(number));
}
_output.WriteString(name);
_output.WriteEndElement();
}
}
}
\ No newline at end of file
using System;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Options available for the xml reader output
/// </summary>
[Flags]
public enum XmlReaderOptions
{
/// <summary> Simple xml formatting with no attributes </summary>
None,
/// <summary> Requires that arrays items are nested in an &lt;item> element </summary>
ReadNestedArrays = 1,
}
}
\ No newline at end of file
using System;
namespace Google.ProtocolBuffers.Serialization
{
/// <summary>
/// Options available for the xml writer output
/// </summary>
[Flags]
public enum XmlWriterOptions
{
/// <summary> Simple xml formatting with no attributes </summary>
None,
/// <summary> Writes the 'value' attribute on all enumerations with the numeric identifier </summary>
OutputEnumValues = 0x1,
/// <summary> Embeds array items into child &lt;item> elements </summary>
OutputNestedArrays = 0x4,
/// <summary> Outputs the 'type' attribute for compatibility with the <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory">JsonReaderWriterFactory</see> </summary>
/// <remarks> This option must, by nessessity, also enable NestedArrayItems </remarks>
OutputJsonTypes = 0x8,
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Google.ProtocolBuffers</RootNamespace>
<AssemblyName>Google.ProtocolBuffersLite</AssemblyName>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile92</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
<OldToolsVersion>3.5</OldToolsVersion>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>DEBUG;TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>TRACE;LITE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractBuilderLite.cs" />
<Compile Include="AbstractMessageLite.cs" />
<Compile Include="ByteArray.cs" />
<Compile Include="CodedOutputStream.ComputeSize.cs" />
<Compile Include="Collections\Dictionaries.cs" />
<Compile Include="Collections\Enumerables.cs" />
<Compile Include="Collections\IPopsicleList.cs" />
<Compile Include="Collections\Lists.cs" />
<Compile Include="Collections\PopsicleList.cs" />
<Compile Include="Collections\ReadOnlyDictionary.cs" />
<Compile Include="Descriptors\FieldMappingAttribute.cs" />
<Compile Include="Descriptors\FieldType.cs" />
<Compile Include="Descriptors\MappedType.cs" />
<Compile Include="EnumLite.cs" />
<Compile Include="ExtendableBuilderLite.cs" />
<Compile Include="ExtendableMessageLite.cs" />
<Compile Include="FieldSet.cs" />
<Compile Include="FrameworkPortability.cs" />
<Compile Include="GeneratedBuilderLite.cs" />
<Compile Include="GeneratedExtensionLite.cs" />
<Compile Include="GeneratedMessageLite.cs" />
<Compile Include="ICodedInputStream.cs" />
<Compile Include="ICodedOutputStream.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ByteString.cs" />
<Compile Include="CodedInputStream.cs" />
<Compile Include="CodedOutputStream.cs" />
<Compile Include="ExtensionRegistryLite.cs" />
<Compile Include="IBuilderLite.cs" />
<Compile Include="IMessageLite.cs" />
<Compile Include="InvalidProtocolBufferException.cs" />
<Compile Include="SortedList.cs" />
<Compile Include="ThrowHelper.cs" />
<Compile Include="UninitializedMessageException.cs" />
<Compile Include="WireFormat.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.IO;
using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
public class AbstractMessageLiteTest
{
[Test]
public void TestMessageLiteToByteString()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ)
.Build();
ByteString b = msg.ToByteString();
Assert.AreEqual(4, b.Length);
Assert.AreEqual(TestRequiredLite.DFieldNumber << 3, b[0]);
Assert.AreEqual(42, b[1]);
Assert.AreEqual(TestRequiredLite.EnFieldNumber << 3, b[2]);
Assert.AreEqual((int) ExtraEnum.EXLITE_BAZ, b[3]);
}
[Test]
public void TestMessageLiteToByteArray()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ)
.Build();
ByteString b = msg.ToByteString();
ByteString copy = ByteString.CopyFrom(msg.ToByteArray());
Assert.AreEqual(b, copy);
}
[Test]
public void TestMessageLiteWriteTo()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ)
.Build();
MemoryStream ms = new MemoryStream();
msg.WriteTo(ms);
Assert.AreEqual(msg.ToByteArray(), ms.ToArray());
}
[Test]
public void TestMessageLiteWriteDelimitedTo()
{
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ)
.Build();
MemoryStream ms = new MemoryStream();
msg.WriteDelimitedTo(ms);
byte[] buffer = ms.ToArray();
Assert.AreEqual(5, buffer.Length);
Assert.AreEqual(4, buffer[0]);
byte[] msgBytes = new byte[4];
Array.Copy(buffer, 1, msgBytes, 0, 4);
Assert.AreEqual(msg.ToByteArray(), msgBytes);
}
[Test]
public void TestIMessageLiteWeakCreateBuilderForType()
{
IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType());
}
[Test]
public void TestMessageLiteWeakToBuilder()
{
IMessageLite msg = TestRequiredLite.CreateBuilder()
.SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ)
.Build();
IMessageLite copy = msg.WeakToBuilder().WeakBuild();
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
}
[Test]
public void TestMessageLiteWeakDefaultInstanceForType()
{
IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.IsTrue(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType));
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Deployment.Parts>
</Deployment.Parts>
</Deployment>
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment