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.
This commit is contained in:
parent
d1b88f4310
commit
a09b491080
@ -1,686 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Google.ProtocolBuffers.Descriptors;
|
||||
|
||||
//Disable CS3011: only CLS-compliant members can be abstract
|
||||
#pragma warning disable 3011
|
||||
|
||||
namespace Google.ProtocolBuffers.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a base-class that provides some basic functionality for handling type dispatching
|
||||
/// </summary>
|
||||
public abstract class AbstractReader : ICodedInputStream
|
||||
{
|
||||
private const int DefaultMaxDepth = 64;
|
||||
private int _depth;
|
||||
|
||||
/// <summary> Constructs a new reader </summary>
|
||||
protected AbstractReader() { MaxDepth = DefaultMaxDepth; }
|
||||
|
||||
/// <summary> Gets or sets the maximum recursion depth allowed </summary>
|
||||
public int MaxDepth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Merges the contents of stream into the provided message builder
|
||||
/// </summary>
|
||||
public TBuilder Merge<TBuilder>(TBuilder builder) where TBuilder : IBuilderLite
|
||||
{
|
||||
return Merge(builder, ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges the contents of stream into the provided message builder
|
||||
/// </summary>
|
||||
public abstract TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
|
||||
where TBuilder : IBuilderLite;
|
||||
|
||||
/// <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 abstract bool PeekNext(out string field);
|
||||
|
||||
/// <summary>
|
||||
/// Causes the reader to skip past this field
|
||||
/// </summary>
|
||||
protected abstract void Skip();
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a Boolean from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref bool value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a Int32 from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref int value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a UInt32 from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref uint value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a Int64 from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref long value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a UInt64 from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref ulong value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a Single from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref float value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a Double from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref double value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a String from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref string value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a ByteString from the input
|
||||
/// </summary>
|
||||
protected abstract bool Read(ref ByteString value);
|
||||
|
||||
/// <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 abstract bool ReadEnum(ref object value);
|
||||
|
||||
/// <summary>
|
||||
/// Merges the input stream into the provided IBuilderLite
|
||||
/// </summary>
|
||||
protected abstract bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry);
|
||||
|
||||
/// <summary>
|
||||
/// Reads the root-message preamble specific to this formatter
|
||||
/// </summary>
|
||||
public abstract void ReadMessageStart();
|
||||
|
||||
/// <summary>
|
||||
/// Reads the root-message close specific to this formatter
|
||||
/// </summary>
|
||||
public abstract void ReadMessageEnd();
|
||||
|
||||
/// <summary>
|
||||
/// Merges the input stream into the provided IBuilderLite
|
||||
/// </summary>
|
||||
public virtual bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
|
||||
{
|
||||
return ReadMessage(value, registry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cursors through the array elements and stops at the end of the array
|
||||
/// </summary>
|
||||
protected virtual IEnumerable<string> ForeachArrayItem(string field)
|
||||
{
|
||||
string next = field;
|
||||
while (true)
|
||||
{
|
||||
yield return next;
|
||||
|
||||
if (!PeekNext(out next) || next != field)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an array of T messages
|
||||
/// </summary>
|
||||
public virtual bool ReadMessageArray<T>(string field, ICollection<T> items, IMessageLite messageType,
|
||||
ExtensionRegistry registry)
|
||||
{
|
||||
bool success = false;
|
||||
foreach (string next in ForeachArrayItem(field))
|
||||
{
|
||||
IBuilderLite builder = messageType.WeakCreateBuilderForType();
|
||||
if (ReadMessage(builder, registry))
|
||||
{
|
||||
items.Add((T) builder.WeakBuild());
|
||||
success |= true;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an array of T messages as a proto-buffer group
|
||||
/// </summary>
|
||||
public virtual bool ReadGroupArray<T>(string field, ICollection<T> items, IMessageLite messageType,
|
||||
ExtensionRegistry registry)
|
||||
{
|
||||
bool success = false;
|
||||
foreach (string next in ForeachArrayItem(field))
|
||||
{
|
||||
IBuilderLite builder = messageType.WeakCreateBuilderForType();
|
||||
if (ReadGroup(builder, registry))
|
||||
{
|
||||
items.Add((T) builder.WeakBuild());
|
||||
success |= true;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an array of System.Enum type T and adds them to the collection
|
||||
/// </summary>
|
||||
public virtual bool ReadEnumArray(string field, ICollection<object> items)
|
||||
{
|
||||
bool success = false;
|
||||
foreach (string next in ForeachArrayItem(field))
|
||||
{
|
||||
object temp = null;
|
||||
if (ReadEnum(ref temp))
|
||||
{
|
||||
items.Add(temp);
|
||||
success |= true;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an array of T, where T is a primitive type defined by FieldType
|
||||
/// </summary>
|
||||
public virtual bool ReadArray<T>(FieldType type, string field, ICollection<T> items)
|
||||
{
|
||||
bool success = false;
|
||||
foreach (string next in ForeachArrayItem(field))
|
||||
{
|
||||
object temp = null;
|
||||
if (ReadField(type, ref temp))
|
||||
{
|
||||
items.Add((T) temp);
|
||||
success |= true;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns true if it was able to read a single primitive value of FieldType into the value reference
|
||||
/// </summary>
|
||||
public virtual bool ReadField(FieldType type, ref object value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case FieldType.Bool:
|
||||
{
|
||||
bool temp = false;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.Int64:
|
||||
case FieldType.SInt64:
|
||||
case FieldType.SFixed64:
|
||||
{
|
||||
long temp = 0;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.UInt64:
|
||||
case FieldType.Fixed64:
|
||||
{
|
||||
ulong temp = 0;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.Int32:
|
||||
case FieldType.SInt32:
|
||||
case FieldType.SFixed32:
|
||||
{
|
||||
int temp = 0;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.UInt32:
|
||||
case FieldType.Fixed32:
|
||||
{
|
||||
uint temp = 0;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.Float:
|
||||
{
|
||||
float temp = float.NaN;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.Double:
|
||||
{
|
||||
double temp = float.NaN;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.String:
|
||||
{
|
||||
string temp = null;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FieldType.Bytes:
|
||||
{
|
||||
ByteString temp = null;
|
||||
if (Read(ref temp))
|
||||
{
|
||||
value = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#region ICodedInputStream Members
|
||||
|
||||
bool ICodedInputStream.ReadTag(out uint fieldTag, out string fieldName)
|
||||
{
|
||||
fieldTag = 0;
|
||||
if (PeekNext(out fieldName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadDouble(ref double value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadFloat(ref float value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadUInt64(ref ulong value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadInt64(ref long value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadInt32(ref int value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadFixed64(ref ulong value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadFixed32(ref uint value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadBool(ref bool value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadString(ref string value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
|
||||
{
|
||||
if (_depth++ > MaxDepth)
|
||||
{
|
||||
throw new RecursionLimitExceededException();
|
||||
}
|
||||
ReadGroup(builder, extensionRegistry);
|
||||
_depth--;
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
|
||||
{
|
||||
if (_depth++ > MaxDepth)
|
||||
{
|
||||
throw new RecursionLimitExceededException();
|
||||
}
|
||||
ReadMessage(builder, extensionRegistry);
|
||||
_depth--;
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadBytes(ref ByteString value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadUInt32(ref uint value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
|
||||
{
|
||||
value = null;
|
||||
unknown = null;
|
||||
if (ReadEnum(ref unknown))
|
||||
{
|
||||
if (unknown is int)
|
||||
{
|
||||
value = mapping.FindValueByNumber((int) unknown);
|
||||
}
|
||||
else if (unknown is string)
|
||||
{
|
||||
value = mapping.FindValueByName((string) unknown);
|
||||
}
|
||||
return value != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadEnum<T>(ref T value, out object rawValue)
|
||||
{
|
||||
rawValue = null;
|
||||
if (ReadEnum(ref rawValue))
|
||||
{
|
||||
if (!EnumParser<T>.TryConvert(rawValue, ref value))
|
||||
{
|
||||
value = default(T);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadSFixed32(ref int value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadSFixed64(ref long value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadSInt32(ref int value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadSInt64(ref long value)
|
||||
{
|
||||
return Read(ref value);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName,
|
||||
ICollection<object> list)
|
||||
{
|
||||
ReadArray(fieldType, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list,
|
||||
out ICollection<object> unknown, IEnumLiteMap mapping)
|
||||
{
|
||||
unknown = null;
|
||||
List<object> array = new List<object>();
|
||||
if (ReadEnumArray(fieldName, array))
|
||||
{
|
||||
foreach (object rawValue in array)
|
||||
{
|
||||
IEnumLite item = null;
|
||||
if (rawValue is int)
|
||||
{
|
||||
item = mapping.FindValueByNumber((int) rawValue);
|
||||
}
|
||||
else if (rawValue is string)
|
||||
{
|
||||
item = mapping.FindValueByName((string) rawValue);
|
||||
}
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unknown == null)
|
||||
{
|
||||
unknown = new List<object>();
|
||||
}
|
||||
unknown.Add(rawValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list,
|
||||
out ICollection<object> unknown)
|
||||
{
|
||||
unknown = null;
|
||||
List<object> array = new List<object>();
|
||||
if (ReadEnumArray(fieldName, array))
|
||||
{
|
||||
foreach (object rawValue in array)
|
||||
{
|
||||
T val = default(T);
|
||||
if (EnumParser<T>.TryConvert(rawValue, ref val))
|
||||
{
|
||||
list.Add(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unknown == null)
|
||||
{
|
||||
unknown = new List<object>();
|
||||
}
|
||||
unknown.Add(rawValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
|
||||
ExtensionRegistry registry)
|
||||
{
|
||||
if (_depth++ > MaxDepth)
|
||||
{
|
||||
throw new RecursionLimitExceededException();
|
||||
}
|
||||
ReadMessageArray(fieldName, list, messageType, registry);
|
||||
_depth--;
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
|
||||
ExtensionRegistry registry)
|
||||
{
|
||||
if (_depth++ > MaxDepth)
|
||||
{
|
||||
throw new RecursionLimitExceededException();
|
||||
}
|
||||
ReadGroupArray(fieldName, list, messageType, registry);
|
||||
_depth--;
|
||||
}
|
||||
|
||||
bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)
|
||||
{
|
||||
return ReadField(fieldType, ref value);
|
||||
}
|
||||
|
||||
bool ICodedInputStream.IsAtEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
string next;
|
||||
return PeekNext(out next) == false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ICodedInputStream.SkipField()
|
||||
{
|
||||
Skip();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list)
|
||||
{
|
||||
ReadArray(FieldType.String, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list)
|
||||
{
|
||||
ReadArray(FieldType.Bytes, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list)
|
||||
{
|
||||
ReadArray(FieldType.Bool, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
|
||||
{
|
||||
ReadArray(FieldType.Int32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list)
|
||||
{
|
||||
ReadArray(FieldType.SInt32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list)
|
||||
{
|
||||
ReadArray(FieldType.UInt32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list)
|
||||
{
|
||||
ReadArray(FieldType.Fixed32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list)
|
||||
{
|
||||
ReadArray(FieldType.SFixed32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
|
||||
{
|
||||
ReadArray(FieldType.Int64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list)
|
||||
{
|
||||
ReadArray(FieldType.SInt64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
|
||||
{
|
||||
ReadArray(FieldType.UInt64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list)
|
||||
{
|
||||
ReadArray(FieldType.Fixed64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list)
|
||||
{
|
||||
ReadArray(FieldType.SFixed64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list)
|
||||
{
|
||||
ReadArray(FieldType.Double, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedInputStream.ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list)
|
||||
{
|
||||
ReadArray(FieldType.Float, fieldName, list);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,503 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Google.ProtocolBuffers.Descriptors;
|
||||
|
||||
//Disable CS3011: only CLS-compliant members can be abstract
|
||||
#pragma warning disable 3011
|
||||
|
||||
namespace Google.ProtocolBuffers.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a base class for writers that performs some basic type dispatching
|
||||
/// </summary>
|
||||
public abstract class AbstractWriter : ICodedOutputStream
|
||||
{
|
||||
/// <summary>
|
||||
/// Completes any pending write operations
|
||||
/// </summary>
|
||||
public virtual void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the message to the the formatted stream.
|
||||
/// </summary>
|
||||
public abstract void WriteMessage(IMessageLite message);
|
||||
|
||||
/// <summary>
|
||||
/// Used to write any nessary root-message preamble. After this call you can call
|
||||
/// IMessageLite.MergeTo(...) and complete the message with a call to WriteMessageEnd().
|
||||
/// These three calls are identical to just calling WriteMessage(message);
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// AbstractWriter writer;
|
||||
/// writer.WriteMessageStart();
|
||||
/// message.WriteTo(writer);
|
||||
/// writer.WriteMessageEnd();
|
||||
/// // ... or, but not both ...
|
||||
/// writer.WriteMessage(message);
|
||||
/// </example>
|
||||
public abstract void WriteMessageStart();
|
||||
|
||||
/// <summary>
|
||||
/// Used to complete a root-message previously started with a call to WriteMessageStart()
|
||||
/// </summary>
|
||||
public abstract void WriteMessageEnd();
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Boolean value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, Boolean value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Int32 value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, Int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a UInt32 value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, UInt32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Int64 value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, Int64 value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a UInt64 value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, UInt64 value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Single value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, Single value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Double value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, Double value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a String value
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, String value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a set of bytes
|
||||
/// </summary>
|
||||
protected abstract void Write(string field, ByteString value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a message or group as a field
|
||||
/// </summary>
|
||||
protected abstract void WriteMessageOrGroup(string field, IMessageLite message);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a System.Enum by the numeric and textual value
|
||||
/// </summary>
|
||||
protected abstract void WriteEnum(string field, int number, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a field of the type determined by field.FieldType
|
||||
/// </summary>
|
||||
protected virtual void WriteField(FieldType fieldType, string field, object value)
|
||||
{
|
||||
switch (fieldType)
|
||||
{
|
||||
case FieldType.Bool:
|
||||
Write(field, (bool) value);
|
||||
break;
|
||||
case FieldType.Int64:
|
||||
case FieldType.SInt64:
|
||||
case FieldType.SFixed64:
|
||||
Write(field, (long) value);
|
||||
break;
|
||||
case FieldType.UInt64:
|
||||
case FieldType.Fixed64:
|
||||
Write(field, (ulong) value);
|
||||
break;
|
||||
case FieldType.Int32:
|
||||
case FieldType.SInt32:
|
||||
case FieldType.SFixed32:
|
||||
Write(field, (int) value);
|
||||
break;
|
||||
case FieldType.UInt32:
|
||||
case FieldType.Fixed32:
|
||||
Write(field, (uint) value);
|
||||
break;
|
||||
case FieldType.Float:
|
||||
Write(field, (float) value);
|
||||
break;
|
||||
case FieldType.Double:
|
||||
Write(field, (double) value);
|
||||
break;
|
||||
case FieldType.String:
|
||||
Write(field, (string) value);
|
||||
break;
|
||||
case FieldType.Bytes:
|
||||
Write(field, (ByteString) value);
|
||||
break;
|
||||
case FieldType.Group:
|
||||
WriteMessageOrGroup(field, (IMessageLite) value);
|
||||
break;
|
||||
case FieldType.Message:
|
||||
WriteMessageOrGroup(field, (IMessageLite) value);
|
||||
break;
|
||||
case FieldType.Enum:
|
||||
{
|
||||
if (value is IEnumLite)
|
||||
{
|
||||
WriteEnum(field, ((IEnumLite) value).Number, ((IEnumLite) value).Name);
|
||||
}
|
||||
else if (value is IConvertible)
|
||||
{
|
||||
WriteEnum(field, ((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture),
|
||||
((IConvertible)value).ToString(FrameworkPortability.InvariantCulture));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Expected an Enum type for field " + field);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an array of field values
|
||||
/// </summary>
|
||||
protected virtual void WriteArray(FieldType fieldType, string field, IEnumerable items)
|
||||
{
|
||||
foreach (object obj in items)
|
||||
{
|
||||
WriteField(fieldType, field, obj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a numeric unknown field of wire type: Fixed32, Fixed64, or Variant
|
||||
/// </summary>
|
||||
protected virtual void WriteUnknown(WireFormat.WireType wireType, int fieldNumber, ulong value)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unknown field, Expect WireType of GroupStart or LengthPrefix
|
||||
/// </summary>
|
||||
protected virtual void WriteUnknown(WireFormat.WireType wireType, int fieldNumber, ByteString value)
|
||||
{
|
||||
}
|
||||
|
||||
#region ICodedOutputStream Members
|
||||
|
||||
void ICodedOutputStream.WriteUnknownGroup(int fieldNumber, IMessageLite value)
|
||||
{
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteUnknownBytes(int fieldNumber, ByteString value)
|
||||
{
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteUnknownField(int fieldNumber, WireFormat.WireType type, ulong value)
|
||||
{
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteMessageSetExtension(int fieldNumber, string fieldName, IMessageLite value)
|
||||
{
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteMessageSetExtension(int fieldNumber, string fieldName, ByteString value)
|
||||
{
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteField(FieldType fieldType, int fieldNumber, string fieldName, object value)
|
||||
{
|
||||
WriteField(fieldType, fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteDouble(int fieldNumber, string fieldName, double value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteFloat(int fieldNumber, string fieldName, float value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteUInt64(int fieldNumber, string fieldName, ulong value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteInt64(int fieldNumber, string fieldName, long value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteInt32(int fieldNumber, string fieldName, int value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteFixed64(int fieldNumber, string fieldName, ulong value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteFixed32(int fieldNumber, string fieldName, uint value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteBool(int fieldNumber, string fieldName, bool value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteString(int fieldNumber, string fieldName, string value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteGroup(int fieldNumber, string fieldName, IMessageLite value)
|
||||
{
|
||||
WriteMessageOrGroup(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteMessage(int fieldNumber, string fieldName, IMessageLite value)
|
||||
{
|
||||
WriteMessageOrGroup(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteBytes(int fieldNumber, string fieldName, ByteString value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteUInt32(int fieldNumber, string fieldName, uint value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteEnum(int fieldNumber, string fieldName, int value, object rawValue)
|
||||
{
|
||||
WriteEnum(fieldName, value, rawValue.ToString());
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSFixed32(int fieldNumber, string fieldName, int value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSFixed64(int fieldNumber, string fieldName, long value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSInt32(int fieldNumber, string fieldName, int value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSInt64(int fieldNumber, string fieldName, long value)
|
||||
{
|
||||
Write(fieldName, value);
|
||||
}
|
||||
|
||||
|
||||
void ICodedOutputStream.WriteArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list)
|
||||
{
|
||||
WriteArray(fieldType, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteGroupArray<T>(int fieldNumber, string fieldName, IEnumerable<T> list)
|
||||
{
|
||||
WriteArray(FieldType.Group, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteMessageArray<T>(int fieldNumber, string fieldName, IEnumerable<T> list)
|
||||
{
|
||||
WriteArray(FieldType.Message, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteStringArray(int fieldNumber, string fieldName, IEnumerable<string> list)
|
||||
{
|
||||
WriteArray(FieldType.String, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteBytesArray(int fieldNumber, string fieldName, IEnumerable<ByteString> list)
|
||||
{
|
||||
WriteArray(FieldType.Bytes, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteBoolArray(int fieldNumber, string fieldName, IEnumerable<bool> list)
|
||||
{
|
||||
WriteArray(FieldType.Bool, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteInt32Array(int fieldNumber, string fieldName, IEnumerable<int> list)
|
||||
{
|
||||
WriteArray(FieldType.Int32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSInt32Array(int fieldNumber, string fieldName, IEnumerable<int> list)
|
||||
{
|
||||
WriteArray(FieldType.SInt32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteUInt32Array(int fieldNumber, string fieldName, IEnumerable<uint> list)
|
||||
{
|
||||
WriteArray(FieldType.UInt32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteFixed32Array(int fieldNumber, string fieldName, IEnumerable<uint> list)
|
||||
{
|
||||
WriteArray(FieldType.Fixed32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSFixed32Array(int fieldNumber, string fieldName, IEnumerable<int> list)
|
||||
{
|
||||
WriteArray(FieldType.SFixed32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteInt64Array(int fieldNumber, string fieldName, IEnumerable<long> list)
|
||||
{
|
||||
WriteArray(FieldType.Int64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSInt64Array(int fieldNumber, string fieldName, IEnumerable<long> list)
|
||||
{
|
||||
WriteArray(FieldType.SInt64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteUInt64Array(int fieldNumber, string fieldName, IEnumerable<ulong> list)
|
||||
{
|
||||
WriteArray(FieldType.UInt64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteFixed64Array(int fieldNumber, string fieldName, IEnumerable<ulong> list)
|
||||
{
|
||||
WriteArray(FieldType.Fixed64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteSFixed64Array(int fieldNumber, string fieldName, IEnumerable<long> list)
|
||||
{
|
||||
WriteArray(FieldType.SFixed64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteDoubleArray(int fieldNumber, string fieldName, IEnumerable<double> list)
|
||||
{
|
||||
WriteArray(FieldType.Double, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteFloatArray(int fieldNumber, string fieldName, IEnumerable<float> list)
|
||||
{
|
||||
WriteArray(FieldType.Float, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WriteEnumArray<T>(int fieldNumber, string fieldName, IEnumerable<T> list)
|
||||
{
|
||||
WriteArray(FieldType.Enum, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName,
|
||||
IEnumerable list)
|
||||
{
|
||||
WriteArray(fieldType, fieldName, list);
|
||||
}
|
||||
|
||||
|
||||
void ICodedOutputStream.WritePackedBoolArray(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<bool> list)
|
||||
{
|
||||
WriteArray(FieldType.Bool, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedInt32Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<int> list)
|
||||
{
|
||||
WriteArray(FieldType.Int32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedSInt32Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<int> list)
|
||||
{
|
||||
WriteArray(FieldType.SInt32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedUInt32Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<uint> list)
|
||||
{
|
||||
WriteArray(FieldType.UInt32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedFixed32Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<uint> list)
|
||||
{
|
||||
WriteArray(FieldType.Fixed32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedSFixed32Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<int> list)
|
||||
{
|
||||
WriteArray(FieldType.SFixed32, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedInt64Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<long> list)
|
||||
{
|
||||
WriteArray(FieldType.Int64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedSInt64Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<long> list)
|
||||
{
|
||||
WriteArray(FieldType.SInt64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedUInt64Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<ulong> list)
|
||||
{
|
||||
WriteArray(FieldType.UInt64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedFixed64Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<ulong> list)
|
||||
{
|
||||
WriteArray(FieldType.Fixed64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedSFixed64Array(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<long> list)
|
||||
{
|
||||
WriteArray(FieldType.SFixed64, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedDoubleArray(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<double> list)
|
||||
{
|
||||
WriteArray(FieldType.Double, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedFloatArray(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<float> list)
|
||||
{
|
||||
WriteArray(FieldType.Float, fieldName, list);
|
||||
}
|
||||
|
||||
void ICodedOutputStream.WritePackedEnumArray<T>(int fieldNumber, string fieldName, int computedSize,
|
||||
IEnumerable<T> list)
|
||||
{
|
||||
WriteArray(FieldType.Enum, fieldName, list);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,265 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,200 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
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(); }
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
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; }
|
||||
}
|
||||
}
|
@ -1,262 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,541 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Google.ProtocolBuffers.Descriptors;
|
||||
|
||||
namespace Google.ProtocolBuffers.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// JsonFormatWriter is a .NET 2.0 friendly json formatter for proto buffer messages. For .NET 3.5
|
||||
/// you may also use the XmlFormatWriter with an XmlWriter created by the
|
||||
/// <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory">JsonReaderWriterFactory</see>.
|
||||
/// </summary>
|
||||
public abstract class JsonFormatWriter : AbstractTextWriter
|
||||
{
|
||||
#region buffering implementations
|
||||
|
||||
private class JsonTextWriter : JsonFormatWriter
|
||||
{
|
||||
private readonly char[] _buffer;
|
||||
private TextWriter _output;
|
||||
private int _bufferPos;
|
||||
|
||||
public JsonTextWriter(TextWriter output)
|
||||
{
|
||||
_buffer = new char[4096];
|
||||
_bufferPos = 0;
|
||||
_output = output;
|
||||
_counter.Add(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the output of TextWriter.ToString() where TextWriter is the ctor argument.
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
Flush();
|
||||
|
||||
if (_output != null)
|
||||
{
|
||||
return _output.ToString();
|
||||
}
|
||||
|
||||
return new String(_buffer, 0, _bufferPos);
|
||||
}
|
||||
|
||||
protected override void WriteToOutput(char[] chars, int offset, int len)
|
||||
{
|
||||
if (_bufferPos + len >= _buffer.Length)
|
||||
{
|
||||
if (_output == null)
|
||||
{
|
||||
_output = new StringWriter(new StringBuilder(_buffer.Length*2 + len));
|
||||
}
|
||||
Flush();
|
||||
}
|
||||
|
||||
if (len < _buffer.Length)
|
||||
{
|
||||
if (len <= 12)
|
||||
{
|
||||
int stop = offset + len;
|
||||
for (int i = offset; i < stop; i++)
|
||||
{
|
||||
_buffer[_bufferPos++] = chars[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy(chars, offset << 1, _buffer, _bufferPos << 1, len << 1);
|
||||
_bufferPos += len;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_output.Write(chars, offset, len);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void WriteToOutput(char ch)
|
||||
{
|
||||
if (_bufferPos >= _buffer.Length)
|
||||
{
|
||||
if (_output == null)
|
||||
{
|
||||
_output = new StringWriter(new StringBuilder(_buffer.Length * 2));
|
||||
}
|
||||
Flush();
|
||||
}
|
||||
_buffer[_bufferPos++] = ch;
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
if (_bufferPos > 0 && _output != null)
|
||||
{
|
||||
_output.Write(_buffer, 0, _bufferPos);
|
||||
_bufferPos = 0;
|
||||
}
|
||||
base.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
private class JsonStreamWriter : JsonFormatWriter
|
||||
{
|
||||
static readonly Encoding Encoding = new UTF8Encoding(false);
|
||||
private readonly byte[] _buffer;
|
||||
private Stream _output;
|
||||
private int _bufferPos;
|
||||
|
||||
public JsonStreamWriter(Stream output)
|
||||
{
|
||||
_buffer = new byte[8192];
|
||||
_bufferPos = 0;
|
||||
_output = output;
|
||||
_counter.Add(0);
|
||||
}
|
||||
|
||||
protected override void WriteToOutput(char[] chars, int offset, int len)
|
||||
{
|
||||
if (_bufferPos + len >= _buffer.Length)
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
|
||||
if (len < _buffer.Length)
|
||||
{
|
||||
if (len <= 12)
|
||||
{
|
||||
int stop = offset + len;
|
||||
for (int i = offset; i < stop; i++)
|
||||
{
|
||||
_buffer[_bufferPos++] = (byte) chars[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_bufferPos += Encoding.GetBytes(chars, offset, len, _buffer, _bufferPos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] temp = Encoding.GetBytes(chars, offset, len);
|
||||
_output.Write(temp, 0, temp.Length);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void WriteToOutput(char ch)
|
||||
{
|
||||
if (_bufferPos >= _buffer.Length)
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
_buffer[_bufferPos++] = (byte) ch;
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
if (_bufferPos > 0 && _output != null)
|
||||
{
|
||||
_output.Write(_buffer, 0, _bufferPos);
|
||||
_bufferPos = 0;
|
||||
}
|
||||
base.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//Tracks the writer depth and the array element count at that depth.
|
||||
private readonly List<int> _counter;
|
||||
//True if the top-level of the writer is an array as opposed to a single message.
|
||||
private bool _isArray;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a JsonFormatWriter, use the ToString() member to extract the final Json on completion.
|
||||
/// </summary>
|
||||
protected JsonFormatWriter()
|
||||
{
|
||||
_counter = new List<int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a JsonFormatWriter, use ToString() to extract the final output
|
||||
/// </summary>
|
||||
public static JsonFormatWriter CreateInstance()
|
||||
{
|
||||
return new JsonTextWriter(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a JsonFormatWriter to output to the given text writer
|
||||
/// </summary>
|
||||
public static JsonFormatWriter CreateInstance(TextWriter output)
|
||||
{
|
||||
return new JsonTextWriter(output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a JsonFormatWriter to output to the given stream
|
||||
/// </summary>
|
||||
public static JsonFormatWriter CreateInstance(Stream output)
|
||||
{
|
||||
return new JsonStreamWriter(output);
|
||||
}
|
||||
|
||||
/// <summary> Write to the output stream </summary>
|
||||
protected void WriteToOutput(string format, params object[] args)
|
||||
{
|
||||
WriteToOutput(String.Format(format, args));
|
||||
}
|
||||
|
||||
/// <summary> Write to the output stream </summary>
|
||||
protected void WriteToOutput(string text)
|
||||
{
|
||||
WriteToOutput(text.ToCharArray(), 0, text.Length);
|
||||
}
|
||||
|
||||
/// <summary> Write to the output stream </summary>
|
||||
protected abstract void WriteToOutput(char ch);
|
||||
|
||||
/// <summary> Write to the output stream </summary>
|
||||
protected abstract void WriteToOutput(char[] chars, int offset, int len);
|
||||
|
||||
/// <summary> Sets the output formatting to use Environment.NewLine with 4-character indentions </summary>
|
||||
public JsonFormatWriter Formatted()
|
||||
{
|
||||
NewLine = FrameworkPortability.NewLine;
|
||||
Indent = " ";
|
||||
Whitespace = " ";
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary> Gets or sets the characters to use for the new-line, default = empty </summary>
|
||||
public string NewLine { get; set; }
|
||||
|
||||
/// <summary> Gets or sets the text to use for indenting, default = empty </summary>
|
||||
public string Indent { get; set; }
|
||||
|
||||
/// <summary> Gets or sets the whitespace to use to separate the text, default = empty </summary>
|
||||
public string Whitespace { get; set; }
|
||||
|
||||
private void Seperator()
|
||||
{
|
||||
if (_counter.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Mismatched open/close in Json writer.");
|
||||
}
|
||||
|
||||
int index = _counter.Count - 1;
|
||||
if (_counter[index] > 0)
|
||||
{
|
||||
WriteToOutput(',');
|
||||
}
|
||||
|
||||
WriteLine(String.Empty);
|
||||
_counter[index] = _counter[index] + 1;
|
||||
}
|
||||
|
||||
private void WriteLine(string content)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(NewLine))
|
||||
{
|
||||
WriteToOutput(NewLine);
|
||||
for (int i = 1; i < _counter.Count; i++)
|
||||
{
|
||||
WriteToOutput(Indent);
|
||||
}
|
||||
}
|
||||
else if (!String.IsNullOrEmpty(Whitespace))
|
||||
{
|
||||
WriteToOutput(Whitespace);
|
||||
}
|
||||
|
||||
WriteToOutput(content);
|
||||
}
|
||||
|
||||
private void WriteName(string field)
|
||||
{
|
||||
Seperator();
|
||||
if (!String.IsNullOrEmpty(field))
|
||||
{
|
||||
WriteToOutput('"');
|
||||
WriteToOutput(field);
|
||||
WriteToOutput('"');
|
||||
WriteToOutput(':');
|
||||
if (!String.IsNullOrEmpty(Whitespace))
|
||||
{
|
||||
WriteToOutput(Whitespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EncodeText(string value)
|
||||
{
|
||||
char[] text = value.ToCharArray();
|
||||
int len = text.Length;
|
||||
int pos = 0;
|
||||
|
||||
while (pos < len)
|
||||
{
|
||||
int next = pos;
|
||||
while (next < len && text[next] >= 32 && text[next] < 127 && text[next] != '\\' && text[next] != '/' &&
|
||||
text[next] != '"')
|
||||
{
|
||||
next++;
|
||||
}
|
||||
WriteToOutput(text, pos, next - pos);
|
||||
if (next < len)
|
||||
{
|
||||
switch (text[next])
|
||||
{
|
||||
case '"':
|
||||
WriteToOutput(@"\""");
|
||||
break;
|
||||
case '\\':
|
||||
WriteToOutput(@"\\");
|
||||
break;
|
||||
//odd at best to escape '/', most Json implementations don't, but it is defined in the rfc-4627
|
||||
case '/':
|
||||
WriteToOutput(@"\/");
|
||||
break;
|
||||
case '\b':
|
||||
WriteToOutput(@"\b");
|
||||
break;
|
||||
case '\f':
|
||||
WriteToOutput(@"\f");
|
||||
break;
|
||||
case '\n':
|
||||
WriteToOutput(@"\n");
|
||||
break;
|
||||
case '\r':
|
||||
WriteToOutput(@"\r");
|
||||
break;
|
||||
case '\t':
|
||||
WriteToOutput(@"\t");
|
||||
break;
|
||||
default:
|
||||
WriteToOutput(@"\u{0:x4}", (int) text[next]);
|
||||
break;
|
||||
}
|
||||
next++;
|
||||
}
|
||||
pos = next;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a String value
|
||||
/// </summary>
|
||||
protected override void WriteAsText(string field, string textValue, object typedValue)
|
||||
{
|
||||
WriteName(field);
|
||||
if (typedValue is bool || typedValue is int || typedValue is uint || typedValue is long ||
|
||||
typedValue is ulong || typedValue is double || typedValue is float)
|
||||
{
|
||||
WriteToOutput(textValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToOutput('"');
|
||||
if (typedValue is string)
|
||||
{
|
||||
EncodeText(textValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToOutput(textValue);
|
||||
}
|
||||
WriteToOutput('"');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Double value
|
||||
/// </summary>
|
||||
protected override void Write(string field, double value)
|
||||
{
|
||||
if (double.IsNaN(value) || double.IsNegativeInfinity(value) || double.IsPositiveInfinity(value))
|
||||
{
|
||||
throw new InvalidOperationException("This format does not support NaN, Infinity, or -Infinity");
|
||||
}
|
||||
base.Write(field, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Single value
|
||||
/// </summary>
|
||||
protected override void Write(string field, float value)
|
||||
{
|
||||
if (float.IsNaN(value) || float.IsNegativeInfinity(value) || float.IsPositiveInfinity(value))
|
||||
{
|
||||
throw new InvalidOperationException("This format does not support NaN, Infinity, or -Infinity");
|
||||
}
|
||||
base.Write(field, value);
|
||||
}
|
||||
|
||||
// Treat enum as string
|
||||
protected override void WriteEnum(string field, int number, string name)
|
||||
{
|
||||
Write(field, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an array of field values
|
||||
/// </summary>
|
||||
protected override void WriteArray(FieldType type, string field, IEnumerable items)
|
||||
{
|
||||
IEnumerator enumerator = items.GetEnumerator();
|
||||
try
|
||||
{
|
||||
if (!enumerator.MoveNext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (enumerator is IDisposable)
|
||||
{
|
||||
((IDisposable) enumerator).Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
WriteName(field);
|
||||
WriteToOutput("[");
|
||||
_counter.Add(0);
|
||||
|
||||
base.WriteArray(type, String.Empty, items);
|
||||
|
||||
_counter.RemoveAt(_counter.Count - 1);
|
||||
WriteLine("]");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a message
|
||||
/// </summary>
|
||||
protected override void WriteMessageOrGroup(string field, IMessageLite message)
|
||||
{
|
||||
WriteName(field);
|
||||
WriteMessage(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the message to the the formatted stream.
|
||||
/// </summary>
|
||||
public override void WriteMessage(IMessageLite message)
|
||||
{
|
||||
WriteMessageStart();
|
||||
message.WriteTo(this);
|
||||
WriteMessageEnd();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to write the root-message preamble, in json this is the left-curly brace '{'.
|
||||
/// After this call you can call IMessageLite.MergeTo(...) and complete the message with
|
||||
/// a call to WriteMessageEnd().
|
||||
/// </summary>
|
||||
public override void WriteMessageStart()
|
||||
{
|
||||
if (_isArray)
|
||||
{
|
||||
Seperator();
|
||||
}
|
||||
WriteToOutput("{");
|
||||
_counter.Add(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to complete a root-message previously started with a call to WriteMessageStart()
|
||||
/// </summary>
|
||||
public override void WriteMessageEnd()
|
||||
{
|
||||
_counter.RemoveAt(_counter.Count - 1);
|
||||
WriteLine("}");
|
||||
Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used in streaming arrays of objects to the writer
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// using(writer.StartArray())
|
||||
/// foreach(IMessageLite m in messages)
|
||||
/// writer.WriteMessage(m);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public sealed class JsonArray : IDisposable
|
||||
{
|
||||
private JsonFormatWriter _writer;
|
||||
|
||||
internal JsonArray(JsonFormatWriter writer)
|
||||
{
|
||||
_writer = writer;
|
||||
_writer.WriteToOutput("[");
|
||||
_writer._counter.Add(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Causes the end of the array character to be written.
|
||||
/// </summary>
|
||||
private void EndArray()
|
||||
{
|
||||
if (_writer != null)
|
||||
{
|
||||
_writer._counter.RemoveAt(_writer._counter.Count - 1);
|
||||
_writer.WriteLine("]");
|
||||
_writer.Flush();
|
||||
}
|
||||
_writer = null;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
EndArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to write an array of messages as the output rather than a single message.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// using(writer.StartArray())
|
||||
/// foreach(IMessageLite m in messages)
|
||||
/// writer.WriteMessage(m);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public JsonArray StartArray()
|
||||
{
|
||||
if (_isArray)
|
||||
{
|
||||
Seperator();
|
||||
}
|
||||
_isArray = true;
|
||||
return new JsonArray(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,442 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Google.ProtocolBuffers.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// JSon Tokenizer used by JsonFormatReader
|
||||
/// </summary>
|
||||
internal abstract class JsonCursor
|
||||
{
|
||||
public enum JsType
|
||||
{
|
||||
String,
|
||||
Number,
|
||||
Object,
|
||||
Array,
|
||||
True,
|
||||
False,
|
||||
Null
|
||||
}
|
||||
|
||||
#region Buffering implementations
|
||||
|
||||
private class JsonStreamCursor : JsonCursor
|
||||
{
|
||||
private readonly byte[] _buffer;
|
||||
private int _bufferPos;
|
||||
private readonly Stream _input;
|
||||
|
||||
public JsonStreamCursor(Stream input)
|
||||
{
|
||||
_input = input;
|
||||
_next = _input.ReadByte();
|
||||
}
|
||||
|
||||
public JsonStreamCursor(byte[] input)
|
||||
{
|
||||
_input = null;
|
||||
_buffer = input;
|
||||
_next = _buffer[_bufferPos];
|
||||
}
|
||||
|
||||
protected override int Peek()
|
||||
{
|
||||
if (_input != null)
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
else if (_bufferPos < _buffer.Length)
|
||||
{
|
||||
return _buffer[_bufferPos];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected override int Read()
|
||||
{
|
||||
if (_input != null)
|
||||
{
|
||||
int result = _next;
|
||||
_next = _input.ReadByte();
|
||||
return result;
|
||||
}
|
||||
else if (_bufferPos < _buffer.Length)
|
||||
{
|
||||
return _buffer[_bufferPos++];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class JsonTextCursor : JsonCursor
|
||||
{
|
||||
private readonly char[] _buffer;
|
||||
private int _bufferPos;
|
||||
private readonly TextReader _input;
|
||||
|
||||
public JsonTextCursor(char[] input)
|
||||
{
|
||||
_input = null;
|
||||
_buffer = input;
|
||||
_bufferPos = 0;
|
||||
_next = Peek();
|
||||
}
|
||||
|
||||
public JsonTextCursor(TextReader input)
|
||||
{
|
||||
_input = input;
|
||||
_next = Peek();
|
||||
}
|
||||
|
||||
protected override int Peek()
|
||||
{
|
||||
if (_input != null)
|
||||
{
|
||||
return _input.Peek();
|
||||
}
|
||||
else if (_bufferPos < _buffer.Length)
|
||||
{
|
||||
return _buffer[_bufferPos];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected override int Read()
|
||||
{
|
||||
if (_input != null)
|
||||
{
|
||||
return _input.Read();
|
||||
}
|
||||
else if (_bufferPos < _buffer.Length)
|
||||
{
|
||||
return _buffer[_bufferPos++];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected int _next;
|
||||
private int _lineNo, _linePos;
|
||||
|
||||
public static JsonCursor CreateInstance(byte[] input)
|
||||
{
|
||||
return new JsonStreamCursor(input);
|
||||
}
|
||||
|
||||
public static JsonCursor CreateInstance(Stream input)
|
||||
{
|
||||
return new JsonStreamCursor(input);
|
||||
}
|
||||
|
||||
public static JsonCursor CreateInstance(string input)
|
||||
{
|
||||
return new JsonTextCursor(input.ToCharArray());
|
||||
}
|
||||
|
||||
public static JsonCursor CreateInstance(TextReader input)
|
||||
{
|
||||
return new JsonTextCursor(input);
|
||||
}
|
||||
|
||||
protected JsonCursor()
|
||||
{
|
||||
_lineNo = 1;
|
||||
_linePos = 0;
|
||||
}
|
||||
|
||||
/// <summary>Returns the next character without actually 'reading' it</summary>
|
||||
protected abstract int Peek();
|
||||
|
||||
/// <summary>Reads the next character in the input</summary>
|
||||
protected abstract int Read();
|
||||
|
||||
public Char NextChar
|
||||
{
|
||||
get
|
||||
{
|
||||
SkipWhitespace();
|
||||
return (char) _next;
|
||||
}
|
||||
}
|
||||
|
||||
#region Assert(...)
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
private string CharDisplay(int ch)
|
||||
{
|
||||
return ch == -1
|
||||
? "EOF"
|
||||
: (ch > 32 && ch < 127)
|
||||
? String.Format("'{0}'", (char) ch)
|
||||
: String.Format("'\\u{0:x4}'", ch);
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
private void Assert(bool cond, char expected)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
throw new FormatException(
|
||||
String.Format(FrameworkPortability.InvariantCulture,
|
||||
"({0}:{1}) error: Unexpected token {2}, expected: {3}.",
|
||||
_lineNo, _linePos,
|
||||
CharDisplay(_next),
|
||||
CharDisplay(expected)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
public void Assert(bool cond, string message)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
throw new FormatException(
|
||||
String.Format(FrameworkPortability.InvariantCulture,
|
||||
"({0},{1}) error: {2}", _lineNo, _linePos, message));
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
public void Assert(bool cond, string format, params object[] args)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
if (args != null && args.Length > 0)
|
||||
{
|
||||
format = String.Format(format, args);
|
||||
}
|
||||
throw new FormatException(
|
||||
String.Format(FrameworkPortability.InvariantCulture,
|
||||
"({0},{1}) error: {2}", _lineNo, _linePos, format));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private char ReadChar()
|
||||
{
|
||||
int ch = Read();
|
||||
Assert(ch != -1, "Unexpected end of file.");
|
||||
if (ch == '\n')
|
||||
{
|
||||
_lineNo++;
|
||||
_linePos = 0;
|
||||
}
|
||||
else if (ch != '\r')
|
||||
{
|
||||
_linePos++;
|
||||
}
|
||||
_next = Peek();
|
||||
return (char) ch;
|
||||
}
|
||||
|
||||
public void Consume(char ch)
|
||||
{
|
||||
Assert(TryConsume(ch), ch);
|
||||
}
|
||||
|
||||
public bool TryConsume(char ch)
|
||||
{
|
||||
SkipWhitespace();
|
||||
if (_next == ch)
|
||||
{
|
||||
ReadChar();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Consume(string sequence)
|
||||
{
|
||||
SkipWhitespace();
|
||||
|
||||
foreach (char ch in sequence)
|
||||
{
|
||||
Assert(ch == ReadChar(), "Expected token '{0}'.", sequence);
|
||||
}
|
||||
}
|
||||
|
||||
public void SkipWhitespace()
|
||||
{
|
||||
int chnext = _next;
|
||||
while (chnext != -1)
|
||||
{
|
||||
if (!Char.IsWhiteSpace((char) chnext))
|
||||
{
|
||||
break;
|
||||
}
|
||||
ReadChar();
|
||||
chnext = _next;
|
||||
}
|
||||
}
|
||||
|
||||
public string ReadString()
|
||||
{
|
||||
SkipWhitespace();
|
||||
Consume('"');
|
||||
List<Char> sb = new List<char>(100);
|
||||
while (_next != '"')
|
||||
{
|
||||
if (_next == '\\')
|
||||
{
|
||||
Consume('\\'); //skip the escape
|
||||
char ch = ReadChar();
|
||||
switch (ch)
|
||||
{
|
||||
case 'b':
|
||||
sb.Add('\b');
|
||||
break;
|
||||
case 'f':
|
||||
sb.Add('\f');
|
||||
break;
|
||||
case 'n':
|
||||
sb.Add('\n');
|
||||
break;
|
||||
case 'r':
|
||||
sb.Add('\r');
|
||||
break;
|
||||
case 't':
|
||||
sb.Add('\t');
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
string hex = new string(new char[] {ReadChar(), ReadChar(), ReadChar(), ReadChar()});
|
||||
int result;
|
||||
Assert(
|
||||
FrameworkPortability.TryParseInt32(hex, NumberStyles.AllowHexSpecifier, FrameworkPortability.InvariantCulture,
|
||||
out result),
|
||||
"Expected a 4-character hex specifier.");
|
||||
sb.Add((char) result);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sb.Add(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert(_next != '\n' && _next != '\r' && _next != '\f' && _next != -1, '"');
|
||||
sb.Add(ReadChar());
|
||||
}
|
||||
}
|
||||
Consume('"');
|
||||
return new String(sb.ToArray());
|
||||
}
|
||||
|
||||
public string ReadNumber()
|
||||
{
|
||||
SkipWhitespace();
|
||||
List<Char> sb = new List<char>(24);
|
||||
if (_next == '-')
|
||||
{
|
||||
sb.Add(ReadChar());
|
||||
}
|
||||
Assert(_next >= '0' && _next <= '9', "Expected a numeric type.");
|
||||
while ((_next >= '0' && _next <= '9') || _next == '.')
|
||||
{
|
||||
sb.Add(ReadChar());
|
||||
}
|
||||
if (_next == 'e' || _next == 'E')
|
||||
{
|
||||
sb.Add(ReadChar());
|
||||
if (_next == '-' || _next == '+')
|
||||
{
|
||||
sb.Add(ReadChar());
|
||||
}
|
||||
Assert(_next >= '0' && _next <= '9', "Expected a numeric type.");
|
||||
while (_next >= '0' && _next <= '9')
|
||||
{
|
||||
sb.Add(ReadChar());
|
||||
}
|
||||
}
|
||||
return new String(sb.ToArray());
|
||||
}
|
||||
|
||||
public JsType ReadVariant(out object value)
|
||||
{
|
||||
SkipWhitespace();
|
||||
switch (_next)
|
||||
{
|
||||
case 'n':
|
||||
Consume("null");
|
||||
value = null;
|
||||
return JsType.Null;
|
||||
case 't':
|
||||
Consume("true");
|
||||
value = true;
|
||||
return JsType.True;
|
||||
case 'f':
|
||||
Consume("false");
|
||||
value = false;
|
||||
return JsType.False;
|
||||
case '"':
|
||||
value = ReadString();
|
||||
return JsType.String;
|
||||
case '{':
|
||||
{
|
||||
Consume('{');
|
||||
while (NextChar != '}')
|
||||
{
|
||||
ReadString();
|
||||
Consume(':');
|
||||
object tmp;
|
||||
ReadVariant(out tmp);
|
||||
if (!TryConsume(','))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Consume('}');
|
||||
value = null;
|
||||
return JsType.Object;
|
||||
}
|
||||
case '[':
|
||||
{
|
||||
Consume('[');
|
||||
List<object> values = new List<object>();
|
||||
while (NextChar != ']')
|
||||
{
|
||||
object tmp;
|
||||
ReadVariant(out tmp);
|
||||
values.Add(tmp);
|
||||
if (!TryConsume(','))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Consume(']');
|
||||
value = values.ToArray();
|
||||
return JsType.Array;
|
||||
}
|
||||
default:
|
||||
if ((_next >= '0' && _next <= '9') || _next == '-')
|
||||
{
|
||||
value = ReadNumber();
|
||||
return JsType.Number;
|
||||
}
|
||||
Assert(false, "Expected a value.");
|
||||
throw new FormatException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
// 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
|
@ -1,93 +0,0 @@
|
||||
<?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>
|
@ -1,93 +0,0 @@
|
||||
<?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>
|
@ -1,18 +0,0 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,338 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Google.ProtocolBuffers.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses a proto buffer from an XML document or fragment. .NET 3.5 users may also
|
||||
/// use this class to process Json by setting the options to support Json and providing
|
||||
/// an XmlReader obtained from <see cref="System.Runtime.Serialization.Json.JsonReaderWriterFactory"/>.
|
||||
/// </summary>
|
||||
public class XmlFormatReader : AbstractTextReader
|
||||
{
|
||||
public const string DefaultRootElementName = XmlFormatWriter.DefaultRootElementName;
|
||||
private readonly XmlReader _input;
|
||||
// Tracks the message element for each nested message read
|
||||
private readonly Stack<ElementStackEntry> _elements;
|
||||
// The default element name for ReadMessageStart
|
||||
private string _rootElementName;
|
||||
|
||||
private struct ElementStackEntry
|
||||
{
|
||||
public readonly string LocalName;
|
||||
public readonly int Depth;
|
||||
public readonly bool IsEmpty;
|
||||
|
||||
public ElementStackEntry(string localName, int depth, bool isEmpty) : this()
|
||||
{
|
||||
LocalName = localName;
|
||||
IsEmpty = isEmpty;
|
||||
Depth = depth;
|
||||
}
|
||||
}
|
||||
|
||||
private static XmlReaderSettings DefaultSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return new XmlReaderSettings()
|
||||
{CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the XmlFormatReader using the stream provided as the xml
|
||||
/// </summary>
|
||||
public static XmlFormatReader CreateInstance(byte[] input)
|
||||
{
|
||||
return new XmlFormatReader(XmlReader.Create(new MemoryStream(input, false), DefaultSettings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the XmlFormatReader using the stream provided as the xml
|
||||
/// </summary>
|
||||
public static XmlFormatReader CreateInstance(Stream input)
|
||||
{
|
||||
return new XmlFormatReader(XmlReader.Create(input, DefaultSettings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the XmlFormatReader using the string provided as the xml to be read
|
||||
/// </summary>
|
||||
public static XmlFormatReader CreateInstance(String input)
|
||||
{
|
||||
return new XmlFormatReader(XmlReader.Create(new StringReader(input), DefaultSettings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the XmlFormatReader using the xml in the TextReader
|
||||
/// </summary>
|
||||
public static XmlFormatReader CreateInstance(TextReader input)
|
||||
{
|
||||
return new XmlFormatReader(XmlReader.Create(input, DefaultSettings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the XmlFormatReader with the XmlReader
|
||||
/// </summary>
|
||||
public static XmlFormatReader CreateInstance(XmlReader input)
|
||||
{
|
||||
return new XmlFormatReader(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the XmlFormatReader with the XmlReader and options
|
||||
/// </summary>
|
||||
protected XmlFormatReader(XmlReader input)
|
||||
{
|
||||
_input = input;
|
||||
_rootElementName = DefaultRootElementName;
|
||||
_elements = new Stack<ElementStackEntry>();
|
||||
Options = XmlReaderOptions.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the options to use when reading the xml
|
||||
/// </summary>
|
||||
public XmlReaderOptions Options { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the options to use while generating the XML
|
||||
/// </summary>
|
||||
public XmlFormatReader SetOptions(XmlReaderOptions options)
|
||||
{
|
||||
Options = options;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default element name to use when using the Merge<TBuilder>()
|
||||
/// </summary>
|
||||
public string RootElementName
|
||||
{
|
||||
get { return _rootElementName; }
|
||||
set
|
||||
{
|
||||
ThrowHelper.ThrowIfNull(value, "RootElementName");
|
||||
_rootElementName = value;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
private static void Assert(bool cond)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the root-message preamble specific to this formatter
|
||||
/// </summary>
|
||||
public override void ReadMessageStart()
|
||||
{
|
||||
ReadMessageStart(_rootElementName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the root-message preamble specific to this formatter
|
||||
/// </summary>
|
||||
public void ReadMessageStart(string element)
|
||||
{
|
||||
while (!_input.IsStartElement() && _input.Read())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Assert(_input.IsStartElement() && _input.LocalName == element);
|
||||
_elements.Push(new ElementStackEntry(element, _input.Depth, _input.IsEmptyElement));
|
||||
_input.Read();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the root-message close specific to this formatter, MUST be called
|
||||
/// on the reader obtained from ReadMessageStart(string element).
|
||||
/// </summary>
|
||||
public override void ReadMessageEnd()
|
||||
{
|
||||
Assert(_elements.Count > 0);
|
||||
|
||||
ElementStackEntry stop = _elements.Peek();
|
||||
while (_input.NodeType != XmlNodeType.EndElement && _input.NodeType != XmlNodeType.Element
|
||||
&& _input.Depth > stop.Depth && _input.Read())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!stop.IsEmpty)
|
||||
{
|
||||
Assert(_input.NodeType == XmlNodeType.EndElement
|
||||
&& _input.LocalName == stop.LocalName
|
||||
&& _input.Depth == stop.Depth);
|
||||
|
||||
_input.Read();
|
||||
}
|
||||
_elements.Pop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge the provided builder as an element named <see cref="RootElementName"/> in the current context
|
||||
/// </summary>
|
||||
public override TBuilder Merge<TBuilder>(TBuilder builder, ExtensionRegistry registry)
|
||||
{
|
||||
return Merge(_rootElementName, builder, registry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge the provided builder as an element of the current context
|
||||
/// </summary>
|
||||
public TBuilder Merge<TBuilder>(string element, TBuilder builder) where TBuilder : IBuilderLite
|
||||
{
|
||||
return Merge(element, builder, ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge the provided builder as an element of the current context
|
||||
/// </summary>
|
||||
public TBuilder Merge<TBuilder>(string element, TBuilder builder, ExtensionRegistry registry)
|
||||
where TBuilder : IBuilderLite
|
||||
{
|
||||
ReadMessageStart(element);
|
||||
builder.WeakMergeFrom(this, registry);
|
||||
ReadMessageEnd();
|
||||
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)
|
||||
{
|
||||
ElementStackEntry stopNode;
|
||||
if (_elements.Count == 0)
|
||||
{
|
||||
stopNode = new ElementStackEntry(null, _input.Depth - 1, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
stopNode = _elements.Peek();
|
||||
}
|
||||
|
||||
if (!stopNode.IsEmpty)
|
||||
{
|
||||
while (!_input.IsStartElement() && _input.Depth > stopNode.Depth && _input.Read())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_input.IsStartElement() && _input.Depth > stopNode.Depth)
|
||||
{
|
||||
field = _input.LocalName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
field = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Causes the reader to skip past this field
|
||||
/// </summary>
|
||||
protected override void Skip()
|
||||
{
|
||||
if (_input.IsStartElement())
|
||||
{
|
||||
if (!_input.IsEmptyElement)
|
||||
{
|
||||
int depth = _input.Depth;
|
||||
while (_input.Depth >= depth && _input.NodeType != XmlNodeType.EndElement)
|
||||
{
|
||||
Assert(_input.Read());
|
||||
}
|
||||
}
|
||||
_input.Read();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
int number;
|
||||
string temp;
|
||||
if (null != (temp = _input.GetAttribute("value")) && FrameworkPortability.TryParseInt32(temp, out number))
|
||||
{
|
||||
Skip();
|
||||
value = number;
|
||||
return true;
|
||||
}
|
||||
return base.ReadEnum(ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if it was able to read a String from the input
|
||||
/// </summary>
|
||||
protected override bool ReadAsText(ref string value, Type type)
|
||||
{
|
||||
Assert(_input.NodeType == XmlNodeType.Element);
|
||||
value = _input.ReadElementContentAsString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges the input stream into the provided IBuilderLite
|
||||
/// </summary>
|
||||
protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
|
||||
{
|
||||
Assert(_input.IsStartElement());
|
||||
ReadMessageStart(_input.LocalName);
|
||||
builder.WeakMergeFrom(this, registry);
|
||||
ReadMessageEnd();
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<string> NonNestedArrayItems(string field)
|
||||
{
|
||||
return base.ForeachArrayItem(field);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cursors through the array elements and stops at the end of the array
|
||||
/// </summary>
|
||||
protected override IEnumerable<string> ForeachArrayItem(string field)
|
||||
{
|
||||
bool isNested = (Options & XmlReaderOptions.ReadNestedArrays) != 0;
|
||||
|
||||
if (!isNested)
|
||||
{
|
||||
foreach (string item in NonNestedArrayItems(field))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string found;
|
||||
ReadMessageStart(field);
|
||||
if (PeekNext(out found) && found == "item")
|
||||
{
|
||||
foreach (string item in NonNestedArrayItems("item"))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
ReadMessageEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,280 +0,0 @@
|
||||
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<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 "<root>". 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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 <item> element </summary>
|
||||
ReadNestedArrays = 1,
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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 <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,
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
<?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>
|
@ -1,336 +0,0 @@
|
||||
#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.IO;
|
||||
using Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public class AbstractBuilderLiteTest
|
||||
{
|
||||
[Test]
|
||||
public void TestMergeFromCodedInputStream()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalUint32(uint.MaxValue).Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(msg.ToByteArray()))
|
||||
{
|
||||
CodedInputStream ci = CodedInputStream.CreateInstance(ms);
|
||||
copy = copy.ToBuilder().MergeFrom(ci).Build();
|
||||
}
|
||||
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakClear()
|
||||
{
|
||||
TestAllTypesLite copy, msg = TestAllTypesLite.DefaultInstance;
|
||||
|
||||
copy = msg.ToBuilder().SetOptionalString("Should be removed.").Build();
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
copy = (TestAllTypesLite) ((IBuilderLite) copy.ToBuilder()).WeakClear().WeakBuild();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBuilderLiteMergeFromCodedInputStream()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalString("Should be merged.").Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
copy =
|
||||
copy.ToBuilder().MergeFrom(CodedInputStream.CreateInstance(new MemoryStream(msg.ToByteArray()))).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBuilderLiteMergeDelimitedFrom()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalString("Should be merged.").Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
Stream s = new MemoryStream();
|
||||
msg.WriteDelimitedTo(s);
|
||||
s.Position = 0;
|
||||
copy = copy.ToBuilder().MergeDelimitedFrom(s).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBuilderLiteMergeDelimitedFromExtensions()
|
||||
{
|
||||
TestAllExtensionsLite copy,
|
||||
msg = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalStringExtensionLite,
|
||||
"Should be merged.").Build();
|
||||
|
||||
copy = TestAllExtensionsLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
Stream s = new MemoryStream();
|
||||
msg.WriteDelimitedTo(s);
|
||||
s.Position = 0;
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
copy = copy.ToBuilder().MergeDelimitedFrom(s, registry).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
Assert.AreEqual("Should be merged.", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBuilderLiteMergeFromStream()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalString("Should be merged.").Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
Stream s = new MemoryStream();
|
||||
msg.WriteTo(s);
|
||||
s.Position = 0;
|
||||
copy = copy.ToBuilder().MergeFrom(s).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBuilderLiteMergeFromStreamExtensions()
|
||||
{
|
||||
TestAllExtensionsLite copy,
|
||||
msg = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalStringExtensionLite,
|
||||
"Should be merged.").Build();
|
||||
|
||||
copy = TestAllExtensionsLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
Stream s = new MemoryStream();
|
||||
msg.WriteTo(s);
|
||||
s.Position = 0;
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
copy = copy.ToBuilder().MergeFrom(s, registry).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
Assert.AreEqual("Should be merged.", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakMergeFromIMessageLite()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalString("Should be merged.").Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
copy = (TestAllTypesLite) ((IBuilderLite) copy.ToBuilder()).WeakMergeFrom((IMessageLite) msg).WeakBuild();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakMergeFromByteString()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalString("Should be merged.").Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
copy = (TestAllTypesLite) ((IBuilderLite) copy.ToBuilder()).WeakMergeFrom(msg.ToByteString()).WeakBuild();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakMergeFromByteStringExtensions()
|
||||
{
|
||||
TestAllExtensionsLite copy,
|
||||
msg = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalStringExtensionLite,
|
||||
"Should be merged.").Build();
|
||||
|
||||
copy = TestAllExtensionsLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
copy =
|
||||
(TestAllExtensionsLite)
|
||||
((IBuilderLite) copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), ExtensionRegistry.Empty).WeakBuild();
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
copy =
|
||||
(TestAllExtensionsLite)
|
||||
((IBuilderLite) copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), registry).WeakBuild();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
Assert.AreEqual("Should be merged.", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakMergeFromCodedInputStream()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalUint32(uint.MaxValue).Build();
|
||||
|
||||
copy = TestAllTypesLite.DefaultInstance;
|
||||
Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(msg.ToByteArray()))
|
||||
{
|
||||
CodedInputStream ci = CodedInputStream.CreateInstance(ms);
|
||||
copy = (TestAllTypesLite) ((IBuilderLite) copy.ToBuilder()).WeakMergeFrom(ci).WeakBuild();
|
||||
}
|
||||
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakBuildPartial()
|
||||
{
|
||||
IBuilderLite builder = TestRequiredLite.CreateBuilder();
|
||||
Assert.IsFalse(builder.IsInitialized);
|
||||
|
||||
IMessageLite msg = builder.WeakBuildPartial();
|
||||
Assert.IsFalse(msg.IsInitialized);
|
||||
|
||||
Assert.AreEqual(msg.ToByteArray(), TestRequiredLite.DefaultInstance.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakBuildUninitialized()
|
||||
{
|
||||
IBuilderLite builder = TestRequiredLite.CreateBuilder();
|
||||
Assert.IsFalse(builder.IsInitialized);
|
||||
Assert.Throws<UninitializedMessageException>(() => builder.WeakBuild());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakBuild()
|
||||
{
|
||||
IBuilderLite builder = TestRequiredLite.CreateBuilder()
|
||||
.SetD(0)
|
||||
.SetEn(ExtraEnum.EXLITE_BAZ);
|
||||
Assert.IsTrue(builder.IsInitialized);
|
||||
builder.WeakBuild();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakClone()
|
||||
{
|
||||
TestRequiredLite msg = TestRequiredLite.CreateBuilder()
|
||||
.SetD(1).SetEn(ExtraEnum.EXLITE_BAR).Build();
|
||||
Assert.IsTrue(msg.IsInitialized);
|
||||
|
||||
IMessageLite copy = ((IBuilderLite) msg.ToBuilder()).WeakClone().WeakBuild();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIBuilderLiteWeakDefaultInstance()
|
||||
{
|
||||
Assert.IsTrue(ReferenceEquals(TestRequiredLite.DefaultInstance,
|
||||
((IBuilderLite) TestRequiredLite.CreateBuilder()).WeakDefaultInstanceForType));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGeneratedBuilderLiteAddRange()
|
||||
{
|
||||
TestAllTypesLite copy,
|
||||
msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalUint32(123)
|
||||
.AddRepeatedInt32(1)
|
||||
.AddRepeatedInt32(2)
|
||||
.AddRepeatedInt32(3)
|
||||
.Build();
|
||||
|
||||
copy = msg.DefaultInstanceForType.ToBuilder().MergeFrom(msg).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
// ROK 5/7/2013 Issue #54: should retire all bytes in buffer (bufferSize)
|
||||
[Test]
|
||||
public void TestBufferRefillIssue()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
BucketOfBytes.CreateBuilder()
|
||||
.SetValue(ByteString.CopyFrom(new byte[3000]))
|
||||
.Build().WriteDelimitedTo(ms);
|
||||
BucketOfBytesEx.CreateBuilder()
|
||||
.SetValue(ByteString.CopyFrom(new byte[1000]))
|
||||
.SetValue2(ByteString.CopyFrom(new byte[1100]))
|
||||
.Build().WriteDelimitedTo(ms);
|
||||
BucketOfBytes.CreateBuilder()
|
||||
.SetValue(ByteString.CopyFrom(new byte[100]))
|
||||
.Build().WriteDelimitedTo(ms);
|
||||
|
||||
ms.Position = 0;
|
||||
var input = CodedInputStream.CreateInstance(ms);
|
||||
var builder = BucketOfBytes.CreateBuilder();
|
||||
input.ReadMessage(builder, ExtensionRegistry.Empty);
|
||||
Assert.AreEqual(3005L, input.Position);
|
||||
Assert.AreEqual(3000, builder.Value.Length);
|
||||
input.ReadMessage(builder, ExtensionRegistry.Empty);
|
||||
Assert.AreEqual(5114, input.Position);
|
||||
Assert.AreEqual(1000, builder.Value.Length);
|
||||
input.ReadMessage(builder, ExtensionRegistry.Empty);
|
||||
Assert.AreEqual(5217L, input.Position);
|
||||
Assert.AreEqual(input.Position, ms.Length);
|
||||
Assert.AreEqual(100, builder.Value.Length);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
#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));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="ProtocolBuffers.SilverlightTest.App"
|
||||
>
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Microsoft.Silverlight.Testing;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
|
||||
public App()
|
||||
{
|
||||
this.Startup += this.Application_Startup;
|
||||
this.Exit += this.Application_Exit;
|
||||
this.UnhandledException += this.Application_UnhandledException;
|
||||
|
||||
//InitializeComponent();
|
||||
}
|
||||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
this.RootVisual = UnitTestSystem.CreateTestPage();
|
||||
}
|
||||
|
||||
private void Application_Exit(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
// If the app is running outside of the debugger then report the exception using
|
||||
// the browser's exception mechanism. On IE this will display it a yellow alert
|
||||
// icon in the status bar and Firefox will display a script error.
|
||||
if (!System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
|
||||
// NOTE: This will allow the application to continue running after an exception has been thrown
|
||||
// but not handled.
|
||||
// For production applications this error handling should be replaced with something that will
|
||||
// report the error to the website and stop the application.
|
||||
e.Handled = true;
|
||||
Deployment.Current.Dispatcher.BeginInvoke(
|
||||
new EventHandler<ApplicationUnhandledExceptionEventArgs>(ReportErrorToDOM),
|
||||
new object[] { sender, e } );
|
||||
}
|
||||
}
|
||||
private void ReportErrorToDOM(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
|
||||
errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
|
||||
|
||||
System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,286 +0,0 @@
|
||||
#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.Collections.Generic;
|
||||
using Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public class ExtendableBuilderLiteTest
|
||||
{
|
||||
[Test]
|
||||
public void TestHasExtensionT()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 123);
|
||||
|
||||
Assert.IsTrue(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHasExtensionTMissing()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.IsFalse(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionCountT()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 1)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 3);
|
||||
|
||||
Assert.AreEqual(3, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionCountTEmpty()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionTNull()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
string value = builder.GetExtension(UnittestLite.OptionalStringExtensionLite);
|
||||
Assert.Null(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionTValue()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 3);
|
||||
|
||||
Assert.AreEqual(3, builder.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionTEmpty()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.AreEqual(0, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite).Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionTList()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 1)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 3);
|
||||
|
||||
IList<int> values = builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite);
|
||||
Assert.AreEqual(3, values.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionTIndex()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 1)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
Assert.AreEqual(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetExtensionTIndexOutOfRange()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSetExtensionTIndex()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 1)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 2);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
Assert.AreEqual(i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
|
||||
|
||||
builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0, 5);
|
||||
builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 1, 6);
|
||||
builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 2, 7);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
Assert.AreEqual(5 + i, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, i));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSetExtensionTIndexOutOfRange()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => builder.SetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0, -1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestClearExtensionTList()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
|
||||
Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
|
||||
builder.ClearExtension(UnittestLite.RepeatedInt32ExtensionLite);
|
||||
Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestClearExtensionTValue()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 0);
|
||||
Assert.IsTrue(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
|
||||
builder.ClearExtension(UnittestLite.OptionalInt32ExtensionLite);
|
||||
Assert.IsFalse(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIndexedByDescriptor()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.IsFalse(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
|
||||
builder[UnittestLite.OptionalInt32ExtensionLite.Descriptor] = 123;
|
||||
|
||||
Assert.IsTrue(builder.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
Assert.AreEqual(123, builder.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIndexedByDescriptorAndOrdinal()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
|
||||
Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
|
||||
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
|
||||
builder[f, 0] = 123;
|
||||
|
||||
Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
Assert.AreEqual(123, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIndexedByDescriptorAndOrdinalOutOfRange()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
|
||||
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => builder[f, 0] = 123);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestClearFieldByDescriptor()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
|
||||
Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
|
||||
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
|
||||
builder.ClearField(f);
|
||||
Assert.AreEqual(0, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddRepeatedFieldByDescriptor()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 0);
|
||||
Assert.AreEqual(1, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
|
||||
IFieldDescriptorLite f = UnittestLite.RepeatedInt32ExtensionLite.Descriptor;
|
||||
builder.AddRepeatedField(f, 123);
|
||||
Assert.AreEqual(2, builder.GetExtensionCount(UnittestLite.RepeatedInt32ExtensionLite));
|
||||
Assert.AreEqual(123, builder.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMissingExtensionsLite()
|
||||
{
|
||||
const int optionalInt32 = 12345678;
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
|
||||
builder.SetExtension(UnittestLite.OptionalInt32ExtensionLite, optionalInt32);
|
||||
builder.AddExtension(UnittestLite.RepeatedDoubleExtensionLite, 1.1);
|
||||
builder.AddExtension(UnittestLite.RepeatedDoubleExtensionLite, 1.2);
|
||||
builder.AddExtension(UnittestLite.RepeatedDoubleExtensionLite, 1.3);
|
||||
TestAllExtensionsLite msg = builder.Build();
|
||||
|
||||
Assert.IsTrue(msg.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
Assert.AreEqual(3, msg.GetExtensionCount(UnittestLite.RepeatedDoubleExtensionLite));
|
||||
|
||||
byte[] bits = msg.ToByteArray();
|
||||
TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
|
||||
Assert.IsFalse(copy.HasExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
Assert.AreEqual(0, copy.GetExtensionCount(UnittestLite.RepeatedDoubleExtensionLite));
|
||||
Assert.AreNotEqual(msg, copy);
|
||||
|
||||
//The lite runtime removes all unknown fields and extensions
|
||||
byte[] copybits = copy.ToByteArray();
|
||||
Assert.AreEqual(0, copybits.Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMissingFieldsLite()
|
||||
{
|
||||
TestAllTypesLite msg = TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalInt32(123)
|
||||
.SetOptionalString("123")
|
||||
.Build();
|
||||
|
||||
byte[] bits = msg.ToByteArray();
|
||||
IMessageLite copy = TestAllExtensionsLite.ParseFrom(bits);
|
||||
Assert.AreNotEqual(msg, copy);
|
||||
|
||||
//The lite runtime removes all unknown fields and extensions
|
||||
byte[] copybits = copy.ToByteArray();
|
||||
Assert.AreEqual(0, copybits.Length);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,378 +0,0 @@
|
||||
#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.Collections.Generic;
|
||||
using System.Text;
|
||||
using Google.ProtocolBuffers;
|
||||
using Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public class ExtendableMessageLiteTest
|
||||
{
|
||||
//The lite framework does not make this assertion
|
||||
//[TestMethod, Ignore, ExpectedException(typeof(ArgumentException))]
|
||||
//public void ExtensionWriterInvalidExtension()
|
||||
//{
|
||||
// TestPackedExtensionsLite.CreateBuilder()[
|
||||
// UnittestLite.OptionalForeignMessageExtensionLite.DescriptorProtoFile] =
|
||||
// ForeignMessageLite.DefaultInstance;
|
||||
//}
|
||||
|
||||
[Test]
|
||||
public void ExtensionWriterTestMessages()
|
||||
{
|
||||
TestAllExtensionsLite.Builder b = TestAllExtensionsLite.CreateBuilder().SetExtension(
|
||||
UnittestLite.OptionalForeignMessageExtensionLite,
|
||||
ForeignMessageLite.CreateBuilder().SetC(123).Build());
|
||||
TestAllExtensionsLite copy, msg = b.Build();
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry);
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtensionWriterIsInitialized()
|
||||
{
|
||||
Assert.IsTrue(ForeignMessageLite.DefaultInstance.IsInitialized);
|
||||
Assert.IsTrue(TestPackedExtensionsLite.CreateBuilder().IsInitialized);
|
||||
Assert.IsTrue(TestAllExtensionsLite.CreateBuilder().SetExtension(
|
||||
UnittestLite.OptionalForeignMessageExtensionLite, ForeignMessageLite.DefaultInstance)
|
||||
.IsInitialized);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtensionWriterTestSetExtensionLists()
|
||||
{
|
||||
TestAllExtensionsLite msg, copy;
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.RepeatedBoolExtensionLite, new[] {true, false})
|
||||
.SetExtension(UnittestLite.RepeatedCordExtensionLite, new[] {"123", "456"})
|
||||
.SetExtension(UnittestLite.RepeatedForeignEnumExtensionLite,
|
||||
new[] {ForeignEnumLite.FOREIGN_LITE_BAZ, ForeignEnumLite.FOREIGN_LITE_FOO})
|
||||
;
|
||||
|
||||
msg = builder.Build();
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry);
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_FOO,
|
||||
copy.GetExtension(UnittestLite.RepeatedForeignEnumExtensionLite, 1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtensionWriterTest()
|
||||
{
|
||||
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.DefaultBoolExtensionLite, true)
|
||||
.SetExtension(UnittestLite.DefaultBytesExtensionLite, ByteString.CopyFromUtf8("123"))
|
||||
.SetExtension(UnittestLite.DefaultCordExtensionLite, "123")
|
||||
.SetExtension(UnittestLite.DefaultDoubleExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultFixed32ExtensionLite, 123u)
|
||||
.SetExtension(UnittestLite.DefaultFixed64ExtensionLite, 123u)
|
||||
.SetExtension(UnittestLite.DefaultFloatExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
|
||||
.SetExtension(UnittestLite.DefaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
|
||||
.SetExtension(UnittestLite.DefaultInt32ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultInt64ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultNestedEnumExtensionLite,
|
||||
TestAllTypesLite.Types.NestedEnum.FOO)
|
||||
.SetExtension(UnittestLite.DefaultSfixed32ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultSfixed64ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultSint32ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultSint64ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.DefaultStringExtensionLite, "123")
|
||||
.SetExtension(UnittestLite.DefaultStringPieceExtensionLite, "123")
|
||||
.SetExtension(UnittestLite.DefaultUint32ExtensionLite, 123u)
|
||||
.SetExtension(UnittestLite.DefaultUint64ExtensionLite, 123u)
|
||||
//Optional
|
||||
.SetExtension(UnittestLite.OptionalBoolExtensionLite, true)
|
||||
.SetExtension(UnittestLite.OptionalBytesExtensionLite, ByteString.CopyFromUtf8("123"))
|
||||
.SetExtension(UnittestLite.OptionalCordExtensionLite, "123")
|
||||
.SetExtension(UnittestLite.OptionalDoubleExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalFixed32ExtensionLite, 123u)
|
||||
.SetExtension(UnittestLite.OptionalFixed64ExtensionLite, 123u)
|
||||
.SetExtension(UnittestLite.OptionalFloatExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
|
||||
.SetExtension(UnittestLite.OptionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
|
||||
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalInt64ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalNestedEnumExtensionLite,
|
||||
TestAllTypesLite.Types.NestedEnum.FOO)
|
||||
.SetExtension(UnittestLite.OptionalSfixed32ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalSfixed64ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalSint32ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalSint64ExtensionLite, 123)
|
||||
.SetExtension(UnittestLite.OptionalStringExtensionLite, "123")
|
||||
.SetExtension(UnittestLite.OptionalStringPieceExtensionLite, "123")
|
||||
.SetExtension(UnittestLite.OptionalUint32ExtensionLite, 123u)
|
||||
.SetExtension(UnittestLite.OptionalUint64ExtensionLite, 123u)
|
||||
//Repeated
|
||||
.AddExtension(UnittestLite.RepeatedBoolExtensionLite, true)
|
||||
.AddExtension(UnittestLite.RepeatedBytesExtensionLite, ByteString.CopyFromUtf8("123"))
|
||||
.AddExtension(UnittestLite.RepeatedCordExtensionLite, "123")
|
||||
.AddExtension(UnittestLite.RepeatedDoubleExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedFixed32ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.RepeatedFixed64ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.RepeatedFloatExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
|
||||
.AddExtension(UnittestLite.RepeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
|
||||
.AddExtension(UnittestLite.RepeatedInt32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedInt64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedNestedEnumExtensionLite,
|
||||
TestAllTypesLite.Types.NestedEnum.FOO)
|
||||
.AddExtension(UnittestLite.RepeatedSfixed32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedSfixed64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedSint32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedSint64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedStringExtensionLite, "123")
|
||||
.AddExtension(UnittestLite.RepeatedStringPieceExtensionLite, "123")
|
||||
.AddExtension(UnittestLite.RepeatedUint32ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.RepeatedUint64ExtensionLite, 123u)
|
||||
;
|
||||
TestAllExtensionsLite msg = builder.Build();
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
TestAllExtensionsLite.Builder copyBuilder =
|
||||
TestAllExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
|
||||
TestAllExtensionsLite copy = copyBuilder.Build();
|
||||
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
Assert.AreEqual(true, copy.GetExtension(UnittestLite.DefaultBoolExtensionLite));
|
||||
Assert.AreEqual(ByteString.CopyFromUtf8("123"),
|
||||
copy.GetExtension(UnittestLite.DefaultBytesExtensionLite));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.DefaultCordExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultDoubleExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultFixed32ExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultFixed64ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultFloatExtensionLite));
|
||||
Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ,
|
||||
copy.GetExtension(UnittestLite.DefaultForeignEnumExtensionLite));
|
||||
Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ,
|
||||
copy.GetExtension(UnittestLite.DefaultImportEnumExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultInt32ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultInt64ExtensionLite));
|
||||
Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO,
|
||||
copy.GetExtension(UnittestLite.DefaultNestedEnumExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSfixed32ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSfixed64ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSint32ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.DefaultSint64ExtensionLite));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.DefaultStringExtensionLite));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.DefaultStringPieceExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultUint32ExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.DefaultUint64ExtensionLite));
|
||||
|
||||
Assert.AreEqual(true, copy.GetExtension(UnittestLite.OptionalBoolExtensionLite));
|
||||
Assert.AreEqual(ByteString.CopyFromUtf8("123"),
|
||||
copy.GetExtension(UnittestLite.OptionalBytesExtensionLite));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.OptionalCordExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalDoubleExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalFixed32ExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalFixed64ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalFloatExtensionLite));
|
||||
Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ,
|
||||
copy.GetExtension(UnittestLite.OptionalForeignEnumExtensionLite));
|
||||
Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ,
|
||||
copy.GetExtension(UnittestLite.OptionalImportEnumExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalInt32ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalInt64ExtensionLite));
|
||||
Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO,
|
||||
copy.GetExtension(UnittestLite.OptionalNestedEnumExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSfixed32ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSfixed64ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSint32ExtensionLite));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.OptionalSint64ExtensionLite));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.OptionalStringExtensionLite));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.OptionalStringPieceExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalUint32ExtensionLite));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.OptionalUint64ExtensionLite));
|
||||
|
||||
Assert.AreEqual(true, copy.GetExtension(UnittestLite.RepeatedBoolExtensionLite, 0));
|
||||
Assert.AreEqual(ByteString.CopyFromUtf8("123"),
|
||||
copy.GetExtension(UnittestLite.RepeatedBytesExtensionLite, 0));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.RepeatedCordExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedDoubleExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedFixed32ExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedFixed64ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedFloatExtensionLite, 0));
|
||||
Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ,
|
||||
copy.GetExtension(UnittestLite.RepeatedForeignEnumExtensionLite, 0));
|
||||
Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ,
|
||||
copy.GetExtension(UnittestLite.RepeatedImportEnumExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedInt32ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedInt64ExtensionLite, 0));
|
||||
Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO,
|
||||
copy.GetExtension(UnittestLite.RepeatedNestedEnumExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSfixed32ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSfixed64ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSint32ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.RepeatedSint64ExtensionLite, 0));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.RepeatedStringExtensionLite, 0));
|
||||
Assert.AreEqual("123", copy.GetExtension(UnittestLite.RepeatedStringPieceExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedUint32ExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.RepeatedUint64ExtensionLite, 0));
|
||||
}
|
||||
|
||||
private TestPackedExtensionsLite BuildPackedExtensions()
|
||||
{
|
||||
TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.CreateBuilder()
|
||||
.AddExtension(UnittestLite.PackedBoolExtensionLite, true)
|
||||
.AddExtension(UnittestLite.PackedDoubleExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedFixed32ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedFixed64ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedFloatExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedInt32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedInt64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSfixed32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSfixed64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSint32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSint64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedUint32ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedUint64ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedBoolExtensionLite, true)
|
||||
.AddExtension(UnittestLite.PackedDoubleExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedFixed32ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedFixed64ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedFloatExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedInt32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedInt64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSfixed32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSfixed64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSint32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedSint64ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.PackedUint32ExtensionLite, 123u)
|
||||
.AddExtension(UnittestLite.PackedUint64ExtensionLite, 123u);
|
||||
|
||||
TestPackedExtensionsLite msg = builder.Build();
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void AssertPackedExtensions(TestPackedExtensionsLite copy)
|
||||
{
|
||||
Assert.AreEqual(true, copy.GetExtension(UnittestLite.PackedBoolExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedDoubleExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedFixed32ExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedFixed64ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedFloatExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedInt32ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedInt64ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSfixed32ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSfixed64ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSint32ExtensionLite, 0));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSint64ExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedUint32ExtensionLite, 0));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedUint64ExtensionLite, 0));
|
||||
|
||||
Assert.AreEqual(true, copy.GetExtension(UnittestLite.PackedBoolExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedDoubleExtensionLite, 1));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedFixed32ExtensionLite, 1));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedFixed64ExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedFloatExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedInt32ExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedInt64ExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSfixed32ExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSfixed64ExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSint32ExtensionLite, 1));
|
||||
Assert.AreEqual(123, copy.GetExtension(UnittestLite.PackedSint64ExtensionLite, 1));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedUint32ExtensionLite, 1));
|
||||
Assert.AreEqual(123u, copy.GetExtension(UnittestLite.PackedUint64ExtensionLite, 1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtensionWriterTestPacked()
|
||||
{
|
||||
TestPackedExtensionsLite msg = BuildPackedExtensions();
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
|
||||
TestPackedExtensionsLite.Builder copyBuilder =
|
||||
TestPackedExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
|
||||
TestPackedExtensionsLite copy = copyBuilder.Build();
|
||||
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
AssertPackedExtensions(copy);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUnpackedAndPackedExtensions()
|
||||
{
|
||||
TestPackedExtensionsLite original = BuildPackedExtensions();
|
||||
AssertPackedExtensions(original);
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
UnittestExtrasLite.RegisterAllExtensions(registry);
|
||||
|
||||
TestUnpackedExtensionsLite unpacked = TestUnpackedExtensionsLite.ParseFrom(original.ToByteArray(), registry);
|
||||
|
||||
TestPackedExtensionsLite packed = TestPackedExtensionsLite.ParseFrom(unpacked.ToByteArray(), registry);
|
||||
|
||||
Assert.AreEqual(original, packed);
|
||||
Assert.AreEqual(original.ToByteArray(), packed.ToByteArray());
|
||||
AssertPackedExtensions(packed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUnpackedFromPackedInput()
|
||||
{
|
||||
byte[] packedData = BuildPackedExtensions().ToByteArray();
|
||||
|
||||
TestUnpackedTypesLite unpacked = TestUnpackedTypesLite.ParseFrom(packedData);
|
||||
TestPackedTypesLite packed = TestPackedTypesLite.ParseFrom(unpacked.ToByteArray());
|
||||
Assert.AreEqual(packedData, packed.ToByteArray());
|
||||
|
||||
unpacked = TestUnpackedTypesLite.ParseFrom(packed.ToByteArray());
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestLite.RegisterAllExtensions(registry);
|
||||
AssertPackedExtensions(TestPackedExtensionsLite.ParseFrom(unpacked.ToByteArray(), registry));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
#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 Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public class InteropLiteTest
|
||||
{
|
||||
[Test]
|
||||
public void TestConvertFromFullMinimal()
|
||||
{
|
||||
TestInteropPerson person = TestInteropPerson.CreateBuilder()
|
||||
.SetId(123)
|
||||
.SetName("abc")
|
||||
.Build();
|
||||
Assert.IsTrue(person.IsInitialized);
|
||||
|
||||
TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray());
|
||||
|
||||
Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConvertFromFullComplete()
|
||||
{
|
||||
TestInteropPerson person = TestInteropPerson.CreateBuilder()
|
||||
.SetId(123)
|
||||
.SetName("abc")
|
||||
.SetEmail("abc@123.com")
|
||||
.AddRangeCodes(new[] {1, 2, 3})
|
||||
.AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
|
||||
.AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
|
||||
.AddAddresses(
|
||||
TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").
|
||||
SetState("NA").SetZip(12345).Build())
|
||||
.SetExtension(UnittestExtrasFull.EmployeeId,
|
||||
TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
|
||||
.Build();
|
||||
Assert.IsTrue(person.IsInitialized);
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestExtrasLite.RegisterAllExtensions(registry);
|
||||
byte[] fullBytes = person.ToByteArray();
|
||||
|
||||
TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(fullBytes, registry);
|
||||
byte[] liteBytes = copy.ToByteArray();
|
||||
|
||||
Assert.AreEqual(fullBytes, liteBytes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConvertFromLiteMinimal()
|
||||
{
|
||||
TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
|
||||
.SetId(123)
|
||||
.SetName("abc")
|
||||
.Build();
|
||||
Assert.IsTrue(person.IsInitialized);
|
||||
|
||||
TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray());
|
||||
|
||||
Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConvertFromLiteComplete()
|
||||
{
|
||||
TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
|
||||
.SetId(123)
|
||||
.SetName("abc")
|
||||
.SetEmail("abc@123.com")
|
||||
.AddRangeCodes(new[] {1, 2, 3})
|
||||
.AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
|
||||
.AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
|
||||
.AddAddresses(
|
||||
TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland")
|
||||
.SetState("NA").SetZip(12345).Build())
|
||||
.SetExtension(UnittestExtrasLite.EmployeeIdLite,
|
||||
TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build())
|
||||
.Build();
|
||||
Assert.IsTrue(person.IsInitialized);
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestExtrasFull.RegisterAllExtensions(registry);
|
||||
|
||||
TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry);
|
||||
|
||||
Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
public ByteString AllBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[] bytes = new byte[256];
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
bytes[i] = (byte) i;
|
||||
return ByteString.CopyFrom(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCompareStringValues()
|
||||
{
|
||||
TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
|
||||
.SetId(123)
|
||||
.SetName("abc")
|
||||
.SetEmail("abc@123.com")
|
||||
.AddRangeCodes(new[] {1, 2, 3})
|
||||
.AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
|
||||
.AddPhone(
|
||||
TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber(
|
||||
System.Text.Encoding.UTF8.GetString(AllBytes.ToByteArray(), 0, AllBytes.Length)).Build())
|
||||
.AddAddresses(
|
||||
TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland")
|
||||
.SetState("NA").SetZip(12345).Build())
|
||||
.SetExtension(UnittestExtrasLite.EmployeeIdLite,
|
||||
TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build())
|
||||
.Build();
|
||||
Assert.IsTrue(person.IsInitialized);
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestExtrasFull.RegisterAllExtensions(registry);
|
||||
|
||||
TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry);
|
||||
|
||||
Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
TestInteropPerson.Builder copyBuilder = TestInteropPerson.CreateBuilder();
|
||||
TextFormat.Merge(
|
||||
person.ToString().Replace("[protobuf_unittest_extra.employee_id_lite]",
|
||||
"[protobuf_unittest_extra.employee_id]"), registry, copyBuilder);
|
||||
|
||||
copy = copyBuilder.Build();
|
||||
Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
|
||||
|
||||
string liteText = person.ToString().TrimEnd().Replace("\r", "");
|
||||
string fullText = copy.ToString().TrimEnd().Replace("\r", "");
|
||||
//map the extension type
|
||||
liteText = liteText.Replace("[protobuf_unittest_extra.employee_id_lite]",
|
||||
"[protobuf_unittest_extra.employee_id]");
|
||||
//lite version does not indent
|
||||
while (fullText.IndexOf("\n ", StringComparison.Ordinal) >= 0)
|
||||
fullText = fullText.Replace("\n ", "\n");
|
||||
|
||||
Assert.AreEqual(fullText, liteText);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
#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 Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// Miscellaneous tests for message operations that apply to both
|
||||
/// generated and dynamic messages.
|
||||
/// </summary>
|
||||
public class LiteTest
|
||||
{
|
||||
[Test]
|
||||
public void TestLite()
|
||||
{
|
||||
// Since lite messages are a subset of regular messages, we can mostly
|
||||
// assume that the functionality of lite messages is already thoroughly
|
||||
// tested by the regular tests. All this test really verifies is that
|
||||
// a proto with optimize_for = LITE_RUNTIME compiles correctly when
|
||||
// linked only against the lite library. That is all tested at compile
|
||||
// time, leaving not much to do in this method. Let's just do some random
|
||||
// stuff to make sure the lite message is actually here and usable.
|
||||
|
||||
TestAllTypesLite message =
|
||||
TestAllTypesLite.CreateBuilder()
|
||||
.SetOptionalInt32(123)
|
||||
.AddRepeatedString("hello")
|
||||
.SetOptionalNestedMessage(
|
||||
TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7))
|
||||
.Build();
|
||||
|
||||
ByteString data = message.ToByteString();
|
||||
|
||||
TestAllTypesLite message2 = TestAllTypesLite.ParseFrom(data);
|
||||
|
||||
Assert.AreEqual(123, message2.OptionalInt32);
|
||||
Assert.AreEqual(1, message2.RepeatedStringCount);
|
||||
Assert.AreEqual("hello", message2.RepeatedStringList[0]);
|
||||
Assert.AreEqual(7, message2.OptionalNestedMessage.Bb);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLiteExtensions()
|
||||
{
|
||||
// TODO(kenton): Unlike other features of the lite library, extensions are
|
||||
// implemented completely differently from the regular library. We
|
||||
// should probably test them more thoroughly.
|
||||
|
||||
TestAllExtensionsLite message =
|
||||
TestAllExtensionsLite.CreateBuilder()
|
||||
.SetExtension(UnittestLite.OptionalInt32ExtensionLite, 123)
|
||||
.AddExtension(UnittestLite.RepeatedStringExtensionLite, "hello")
|
||||
.SetExtension(UnittestLite.OptionalNestedEnumExtensionLite,
|
||||
TestAllTypesLite.Types.NestedEnum.BAZ)
|
||||
.SetExtension(UnittestLite.OptionalNestedMessageExtensionLite,
|
||||
TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7).Build())
|
||||
.Build();
|
||||
|
||||
// Test copying a message, since coping extensions actually does use a
|
||||
// different code path between lite and regular libraries, and as of this
|
||||
// writing, parsing hasn't been implemented yet.
|
||||
TestAllExtensionsLite message2 = message.ToBuilder().Build();
|
||||
|
||||
Assert.AreEqual(123, (int) message2.GetExtension(
|
||||
UnittestLite.OptionalInt32ExtensionLite));
|
||||
Assert.AreEqual(1, message2.GetExtensionCount(
|
||||
UnittestLite.RepeatedStringExtensionLite));
|
||||
Assert.AreEqual(1, message2.GetExtension(
|
||||
UnittestLite.RepeatedStringExtensionLite).Count);
|
||||
Assert.AreEqual("hello", message2.GetExtension(
|
||||
UnittestLite.RepeatedStringExtensionLite, 0));
|
||||
Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.BAZ, message2.GetExtension(
|
||||
UnittestLite.OptionalNestedEnumExtensionLite));
|
||||
Assert.AreEqual(7, message2.GetExtension(
|
||||
UnittestLite.OptionalNestedMessageExtensionLite).Bb);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
#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 Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public class MissingFieldAndExtensionTest
|
||||
{
|
||||
[Test]
|
||||
public void TestRecoverMissingExtensions()
|
||||
{
|
||||
const int optionalInt32 = 12345678;
|
||||
TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
|
||||
builder.SetExtension(Unittest.OptionalInt32Extension, optionalInt32);
|
||||
builder.AddExtension(Unittest.RepeatedDoubleExtension, 1.1);
|
||||
builder.AddExtension(Unittest.RepeatedDoubleExtension, 1.2);
|
||||
builder.AddExtension(Unittest.RepeatedDoubleExtension, 1.3);
|
||||
TestAllExtensions msg = builder.Build();
|
||||
|
||||
Assert.IsTrue(msg.HasExtension(Unittest.OptionalInt32Extension));
|
||||
Assert.AreEqual(3, msg.GetExtensionCount(Unittest.RepeatedDoubleExtension));
|
||||
|
||||
byte[] bits = msg.ToByteArray();
|
||||
TestAllExtensions copy = TestAllExtensions.ParseFrom(bits);
|
||||
Assert.IsFalse(copy.HasExtension(Unittest.OptionalInt32Extension));
|
||||
Assert.AreEqual(0, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
|
||||
Assert.AreNotEqual(msg, copy);
|
||||
|
||||
//Even though copy does not understand the typees they serialize correctly
|
||||
byte[] copybits = copy.ToByteArray();
|
||||
Assert.AreEqual(bits, copybits);
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
Unittest.RegisterAllExtensions(registry);
|
||||
|
||||
//Now we can take those copy bits and restore the full message with extensions
|
||||
copy = TestAllExtensions.ParseFrom(copybits, registry);
|
||||
Assert.IsTrue(copy.HasExtension(Unittest.OptionalInt32Extension));
|
||||
Assert.AreEqual(3, copy.GetExtensionCount(Unittest.RepeatedDoubleExtension));
|
||||
|
||||
Assert.AreEqual(msg, copy);
|
||||
Assert.AreEqual(bits, copy.ToByteArray());
|
||||
|
||||
//If we modify the object this should all continue to work as before
|
||||
copybits = copy.ToBuilder().Build().ToByteArray();
|
||||
Assert.AreEqual(bits, copybits);
|
||||
|
||||
//If we replace extension the object this should all continue to work as before
|
||||
copybits = copy.ToBuilder()
|
||||
.SetExtension(Unittest.OptionalInt32Extension, optionalInt32)
|
||||
.Build().ToByteArray();
|
||||
Assert.AreEqual(bits, copybits);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRecoverMissingFields()
|
||||
{
|
||||
TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder()
|
||||
.SetId(1001)
|
||||
.SetName("Name")
|
||||
.SetEmail("missing@field.value")
|
||||
.Build();
|
||||
|
||||
//serialize to type B and verify all fields exist
|
||||
TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
|
||||
Assert.AreEqual(1001, msgb.Id);
|
||||
Assert.AreEqual("Name", msgb.Name);
|
||||
Assert.IsFalse(msgb.HasWebsite);
|
||||
Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
|
||||
Assert.AreEqual("missing@field.value",
|
||||
msgb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8());
|
||||
|
||||
//serializes exactly the same (at least for this simple example)
|
||||
Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray());
|
||||
Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
|
||||
|
||||
//now re-create an exact copy of A from serialized B
|
||||
TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
|
||||
Assert.AreEqual(msga, copya);
|
||||
Assert.AreEqual(1001, copya.Id);
|
||||
Assert.AreEqual("Name", copya.Name);
|
||||
Assert.AreEqual("missing@field.value", copya.Email);
|
||||
|
||||
//Now we modify B... and try again
|
||||
msgb = msgb.ToBuilder().SetWebsite("http://new.missing.field").Build();
|
||||
//Does B still have the missing field?
|
||||
Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
|
||||
|
||||
//Convert back to A and see if all fields are there?
|
||||
copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
|
||||
Assert.AreNotEqual(msga, copya);
|
||||
Assert.AreEqual(1001, copya.Id);
|
||||
Assert.AreEqual("Name", copya.Name);
|
||||
Assert.AreEqual("missing@field.value", copya.Email);
|
||||
Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count);
|
||||
Assert.AreEqual("http://new.missing.field",
|
||||
copya.UnknownFields[TestMissingFieldsB.WebsiteFieldNumber].LengthDelimitedList[0].
|
||||
ToStringUtf8());
|
||||
|
||||
//Lastly we can even still trip back to type B and see all fields:
|
||||
TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray());
|
||||
Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
|
||||
Assert.AreEqual(1001, copyb.Id);
|
||||
Assert.AreEqual("Name", copyb.Name);
|
||||
Assert.AreEqual("http://new.missing.field", copyb.Website);
|
||||
Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count);
|
||||
Assert.AreEqual("missing@field.value",
|
||||
copyb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8
|
||||
());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRecoverMissingMessage()
|
||||
{
|
||||
TestMissingFieldsA.Types.SubA suba =
|
||||
TestMissingFieldsA.Types.SubA.CreateBuilder().SetCount(3).AddValues("a").AddValues("b").AddValues("c").
|
||||
Build();
|
||||
TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder()
|
||||
.SetId(1001)
|
||||
.SetName("Name")
|
||||
.SetTestA(suba)
|
||||
.Build();
|
||||
|
||||
//serialize to type B and verify all fields exist
|
||||
TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
|
||||
Assert.AreEqual(1001, msgb.Id);
|
||||
Assert.AreEqual("Name", msgb.Name);
|
||||
Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
|
||||
Assert.AreEqual(suba.ToString(),
|
||||
TestMissingFieldsA.Types.SubA.ParseFrom(
|
||||
msgb.UnknownFields[TestMissingFieldsA.TestAFieldNumber].LengthDelimitedList[0]).ToString
|
||||
());
|
||||
|
||||
//serializes exactly the same (at least for this simple example)
|
||||
Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray());
|
||||
Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
|
||||
|
||||
//now re-create an exact copy of A from serialized B
|
||||
TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
|
||||
Assert.AreEqual(msga, copya);
|
||||
Assert.AreEqual(1001, copya.Id);
|
||||
Assert.AreEqual("Name", copya.Name);
|
||||
Assert.AreEqual(suba, copya.TestA);
|
||||
|
||||
//Now we modify B... and try again
|
||||
TestMissingFieldsB.Types.SubB subb =
|
||||
TestMissingFieldsB.Types.SubB.CreateBuilder().AddValues("test-b").Build();
|
||||
msgb = msgb.ToBuilder().SetTestB(subb).Build();
|
||||
//Does B still have the missing field?
|
||||
Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
|
||||
|
||||
//Convert back to A and see if all fields are there?
|
||||
copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
|
||||
Assert.AreNotEqual(msga, copya);
|
||||
Assert.AreEqual(1001, copya.Id);
|
||||
Assert.AreEqual("Name", copya.Name);
|
||||
Assert.AreEqual(suba, copya.TestA);
|
||||
Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count);
|
||||
Assert.AreEqual(subb.ToByteArray(),
|
||||
copya.UnknownFields[TestMissingFieldsB.TestBFieldNumber].LengthDelimitedList[0].ToByteArray());
|
||||
|
||||
//Lastly we can even still trip back to type B and see all fields:
|
||||
TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray());
|
||||
Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
|
||||
Assert.AreEqual(1001, copyb.Id);
|
||||
Assert.AreEqual("Name", copyb.Name);
|
||||
Assert.AreEqual(subb, copyb.TestB);
|
||||
Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRestoreFromOtherType()
|
||||
{
|
||||
TestInteropPerson person = TestInteropPerson.CreateBuilder()
|
||||
.SetId(123)
|
||||
.SetName("abc")
|
||||
.SetEmail("abc@123.com")
|
||||
.AddRangeCodes(new[] {1, 2, 3})
|
||||
.AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
|
||||
.AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
|
||||
.AddAddresses(
|
||||
TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").
|
||||
SetState("NA").SetZip(12345).Build())
|
||||
.SetExtension(UnittestExtrasFull.EmployeeId,
|
||||
TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
|
||||
.Build();
|
||||
Assert.IsTrue(person.IsInitialized);
|
||||
|
||||
TestEmptyMessage temp = TestEmptyMessage.ParseFrom(person.ToByteArray());
|
||||
Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
|
||||
temp = temp.ToBuilder().Build();
|
||||
Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
|
||||
|
||||
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
|
||||
UnittestExtrasFull.RegisterAllExtensions(registry);
|
||||
|
||||
TestInteropPerson copy = TestInteropPerson.ParseFrom(temp.ToByteArray(), registry);
|
||||
Assert.AreEqual(person, copy);
|
||||
Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
>
|
||||
<Deployment.Parts>
|
||||
</Deployment.Parts>
|
||||
</Deployment>
|
@ -1,7 +0,0 @@
|
||||
<OutOfBrowserSettings ShortName="ProtocolBuffers.Test" EnableGPUAcceleration="False" ShowInstallMenuItem="False">
|
||||
<OutOfBrowserSettings.Blurb>ProtocolBuffers.Test</OutOfBrowserSettings.Blurb>
|
||||
<OutOfBrowserSettings.WindowSettings>
|
||||
<WindowSettings Title="ProtocolBuffers.Test" />
|
||||
</OutOfBrowserSettings.WindowSettings>
|
||||
<OutOfBrowserSettings.Icons />
|
||||
</OutOfBrowserSettings>
|
@ -1,113 +0,0 @@
|
||||
<?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>{EE01ED24-3750-4567-9A23-1DB676A15610}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Google.ProtocolBuffers</RootNamespace>
|
||||
<AssemblyName>Google.ProtocolBuffersLite.Test</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath>
|
||||
<DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs">
|
||||
<Link>Properties\AssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AbstractBuilderLiteTest.cs" />
|
||||
<Compile Include="AbstractMessageLiteTest.cs" />
|
||||
<Compile Include="ExtendableBuilderLiteTest.cs" />
|
||||
<Compile Include="ExtendableMessageLiteTest.cs" />
|
||||
<Compile Include="LiteTest.cs" />
|
||||
<Compile Include="TestLiteByApi.cs" />
|
||||
<Compile Include="TestProtos\UnittestExtrasLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestImportLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestImportPublicLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestLite.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProtocolBuffers.Serialization\ProtocolBuffersLite.Serialization.csproj">
|
||||
<Project>{E067A59D-9D0A-4A1F-92B1-38E4457241D1}</Project>
|
||||
<Name>ProtocolBuffersLite.Serialization</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.csproj">
|
||||
<Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
|
||||
<Name>ProtocolBuffersLite</Name>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.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>
|
@ -1,110 +0,0 @@
|
||||
<?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>{EEFFED24-3750-4567-9A23-1DB676A15610}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Google.ProtocolBuffers</RootNamespace>
|
||||
<AssemblyName>Google.ProtocolBuffersMixedLite.Test</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath>
|
||||
<DefineConstants>TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate)</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs">
|
||||
<Link>Properties\AssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AbstractBuilderLiteTest.cs" />
|
||||
<Compile Include="AbstractMessageLiteTest.cs" />
|
||||
<Compile Include="ExtendableBuilderLiteTest.cs" />
|
||||
<Compile Include="ExtendableMessageLiteTest.cs" />
|
||||
<Compile Include="InteropLiteTest.cs" />
|
||||
<Compile Include="LiteTest.cs" />
|
||||
<Compile Include="MissingFieldAndExtensionTest.cs" />
|
||||
<Compile Include="TestLiteByApi.cs" />
|
||||
<Compile Include="TestProtos\Unittest.cs" />
|
||||
<Compile Include="TestProtos\UnittestExtrasFull.cs" />
|
||||
<Compile Include="TestProtos\UnittestExtrasLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestImport.cs" />
|
||||
<Compile Include="TestProtos\UnittestImportLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestImportPublic.cs" />
|
||||
<Compile Include="TestProtos\UnittestImportPublicLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestLite.cs" />
|
||||
<Compile Include="TestProtos\UnittestLiteImportsNonlite.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
|
||||
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
|
||||
<Name>ProtocolBuffers</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.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>
|
@ -1,120 +0,0 @@
|
||||
#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 Google.ProtocolBuffers.TestProtos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Google.ProtocolBuffers
|
||||
{
|
||||
public class TestLiteByApi
|
||||
{
|
||||
[Test]
|
||||
public void TestAllTypesEquality()
|
||||
{
|
||||
TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
|
||||
TestAllTypesLite copy = msg.ToBuilder().Build();
|
||||
Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
|
||||
Assert.IsTrue(msg.Equals(copy));
|
||||
msg = msg.ToBuilder().SetOptionalString("Hi").Build();
|
||||
Assert.AreNotEqual(msg.GetHashCode(), copy.GetHashCode());
|
||||
Assert.IsFalse(msg.Equals(copy));
|
||||
copy = copy.ToBuilder().SetOptionalString("Hi").Build();
|
||||
Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
|
||||
Assert.IsTrue(msg.Equals(copy));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEqualityOnExtensions()
|
||||
{
|
||||
TestAllExtensionsLite msg = TestAllExtensionsLite.DefaultInstance;
|
||||
TestAllExtensionsLite copy = msg.ToBuilder().Build();
|
||||
Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
|
||||
Assert.IsTrue(msg.Equals(copy));
|
||||
msg = msg.ToBuilder().SetExtension(UnittestLite.OptionalStringExtensionLite, "Hi").Build();
|
||||
Assert.AreNotEqual(msg.GetHashCode(), copy.GetHashCode());
|
||||
Assert.IsFalse(msg.Equals(copy));
|
||||
copy = copy.ToBuilder().SetExtension(UnittestLite.OptionalStringExtensionLite, "Hi").Build();
|
||||
Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
|
||||
Assert.IsTrue(msg.Equals(copy));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAllTypesToString()
|
||||
{
|
||||
TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
|
||||
TestAllTypesLite copy = msg.ToBuilder().Build();
|
||||
Assert.AreEqual(msg.ToString(), copy.ToString());
|
||||
Assert.AreEqual(0, msg.ToString().Length);
|
||||
msg = msg.ToBuilder().SetOptionalInt32(-1).Build();
|
||||
Assert.AreEqual("optional_int32: -1", msg.ToString().TrimEnd());
|
||||
msg = msg.ToBuilder().SetOptionalString("abc123").Build();
|
||||
Assert.AreEqual("optional_int32: -1\noptional_string: \"abc123\"",
|
||||
msg.ToString().Replace("\r", "").TrimEnd());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAllTypesDefaultedRoundTrip()
|
||||
{
|
||||
TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
|
||||
Assert.IsTrue(msg.IsInitialized);
|
||||
TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAllTypesModifiedRoundTrip()
|
||||
{
|
||||
TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
|
||||
msg.ToBuilder()
|
||||
.SetOptionalBool(true)
|
||||
.SetOptionalCord("Hi")
|
||||
.SetOptionalDouble(1.123)
|
||||
.SetOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO)
|
||||
.SetOptionalForeignMessage(ForeignMessageLite.CreateBuilder().SetC('c').Build())
|
||||
.SetOptionalGroup(TestAllTypesLite.Types.OptionalGroup.CreateBuilder().SetA('a').Build())
|
||||
.SetOptionalImportEnum(ImportEnumLite.IMPORT_LITE_BAR)
|
||||
.SetOptionalInt32(32)
|
||||
.SetOptionalInt64(64)
|
||||
.SetOptionalNestedEnum(TestAllTypesLite.Types.NestedEnum.FOO)
|
||||
.SetOptionalString("SetOptionalString")
|
||||
.AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('a').Build())
|
||||
.AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('A').Build())
|
||||
;
|
||||
TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build();
|
||||
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,347 +0,0 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/unittest_import.proto
|
||||
#pragma warning disable 1591, 0612, 3021
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.ProtocolBuffers;
|
||||
using pbc = global::Google.ProtocolBuffers.Collections;
|
||||
using pbd = global::Google.ProtocolBuffers.Descriptors;
|
||||
using scg = global::System.Collections.Generic;
|
||||
namespace Google.ProtocolBuffers.TestProtos {
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial class UnittestImport {
|
||||
|
||||
#region Extension registration
|
||||
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
|
||||
}
|
||||
#endregion
|
||||
#region Static variables
|
||||
internal static pbd::MessageDescriptor internal__static_protobuf_unittest_import_ImportMessage__Descriptor;
|
||||
internal static pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.ImportMessage, global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder> internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable;
|
||||
#endregion
|
||||
#region Descriptor
|
||||
public static pbd::FileDescriptor Descriptor {
|
||||
get { return descriptor; }
|
||||
}
|
||||
private static pbd::FileDescriptor descriptor;
|
||||
|
||||
static UnittestImport() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"CiVnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0LnByb3RvEhhwcm90",
|
||||
"b2J1Zl91bml0dGVzdF9pbXBvcnQaLGdvb2dsZS9wcm90b2J1Zi91bml0dGVz",
|
||||
"dF9pbXBvcnRfcHVibGljLnByb3RvIhoKDUltcG9ydE1lc3NhZ2USCQoBZBgB",
|
||||
"IAEoBSo8CgpJbXBvcnRFbnVtEg4KCklNUE9SVF9GT08QBxIOCgpJTVBPUlRf",
|
||||
"QkFSEAgSDgoKSU1QT1JUX0JBWhAJQkMKGGNvbS5nb29nbGUucHJvdG9idWYu",
|
||||
"dGVzdEgB+AEBqgIhR29vZ2xlLlByb3RvY29sQnVmZmVycy5UZXN0UHJvdG9z",
|
||||
"UAA="));
|
||||
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
|
||||
descriptor = root;
|
||||
internal__static_protobuf_unittest_import_ImportMessage__Descriptor = Descriptor.MessageTypes[0];
|
||||
internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable =
|
||||
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.ImportMessage, global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder>(internal__static_protobuf_unittest_import_ImportMessage__Descriptor,
|
||||
new string[] { "D", });
|
||||
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
|
||||
RegisterAllExtensions(registry);
|
||||
global::Google.ProtocolBuffers.TestProtos.UnittestImportPublic.RegisterAllExtensions(registry);
|
||||
return registry;
|
||||
};
|
||||
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
|
||||
new pbd::FileDescriptor[] {
|
||||
global::Google.ProtocolBuffers.TestProtos.UnittestImportPublic.Descriptor,
|
||||
}, assigner);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Enums
|
||||
public enum ImportEnum {
|
||||
IMPORT_FOO = 7,
|
||||
IMPORT_BAR = 8,
|
||||
IMPORT_BAZ = 9,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class ImportMessage : pb::GeneratedMessage<ImportMessage, ImportMessage.Builder> {
|
||||
private ImportMessage() { }
|
||||
private static readonly ImportMessage defaultInstance = new ImportMessage().MakeReadOnly();
|
||||
private static readonly string[] _importMessageFieldNames = new string[] { "d" };
|
||||
private static readonly uint[] _importMessageFieldTags = new uint[] { 8 };
|
||||
public static ImportMessage DefaultInstance {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
|
||||
public override ImportMessage DefaultInstanceForType {
|
||||
get { return DefaultInstance; }
|
||||
}
|
||||
|
||||
protected override ImportMessage ThisMessage {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public static pbd::MessageDescriptor Descriptor {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.UnittestImport.internal__static_protobuf_unittest_import_ImportMessage__Descriptor; }
|
||||
}
|
||||
|
||||
protected override pb::FieldAccess.FieldAccessorTable<ImportMessage, ImportMessage.Builder> InternalFieldAccessors {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.UnittestImport.internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable; }
|
||||
}
|
||||
|
||||
public const int DFieldNumber = 1;
|
||||
private bool hasD;
|
||||
private int d_;
|
||||
public bool HasD {
|
||||
get { return hasD; }
|
||||
}
|
||||
public int D {
|
||||
get { return d_; }
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteTo(pb::ICodedOutputStream output) {
|
||||
CalcSerializedSize();
|
||||
string[] field_names = _importMessageFieldNames;
|
||||
if (hasD) {
|
||||
output.WriteInt32(1, field_names[0], D);
|
||||
}
|
||||
UnknownFields.WriteTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public override int SerializedSize {
|
||||
get {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
return CalcSerializedSize();
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (hasD) {
|
||||
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
|
||||
}
|
||||
size += UnknownFields.SerializedSize;
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
public static ImportMessage ParseFrom(pb::ByteString data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(byte[] data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(global::System.IO.Stream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseDelimitedFrom(global::System.IO.Stream input) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(pb::ICodedInputStream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static ImportMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
private ImportMessage MakeReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder CreateBuilder() { return new Builder(); }
|
||||
public override Builder ToBuilder() { return CreateBuilder(this); }
|
||||
public override Builder CreateBuilderForType() { return new Builder(); }
|
||||
public static Builder CreateBuilder(ImportMessage prototype) {
|
||||
return new Builder(prototype);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class Builder : pb::GeneratedBuilder<ImportMessage, Builder> {
|
||||
protected override Builder ThisBuilder {
|
||||
get { return this; }
|
||||
}
|
||||
public Builder() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
internal Builder(ImportMessage cloneFrom) {
|
||||
result = cloneFrom;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
|
||||
private bool resultIsReadOnly;
|
||||
private ImportMessage result;
|
||||
|
||||
private ImportMessage PrepareBuilder() {
|
||||
if (resultIsReadOnly) {
|
||||
ImportMessage original = result;
|
||||
result = new ImportMessage();
|
||||
resultIsReadOnly = false;
|
||||
MergeFrom(original);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get { return result.IsInitialized; }
|
||||
}
|
||||
|
||||
protected override ImportMessage MessageBeingBuilt {
|
||||
get { return PrepareBuilder(); }
|
||||
}
|
||||
|
||||
public override Builder Clear() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder Clone() {
|
||||
if (resultIsReadOnly) {
|
||||
return new Builder(result);
|
||||
} else {
|
||||
return new Builder().MergeFrom(result);
|
||||
}
|
||||
}
|
||||
|
||||
public override pbd::MessageDescriptor DescriptorForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.ImportMessage.Descriptor; }
|
||||
}
|
||||
|
||||
public override ImportMessage DefaultInstanceForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance; }
|
||||
}
|
||||
|
||||
public override ImportMessage BuildPartial() {
|
||||
if (resultIsReadOnly) {
|
||||
return result;
|
||||
}
|
||||
resultIsReadOnly = true;
|
||||
return result.MakeReadOnly();
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::IMessage other) {
|
||||
if (other is ImportMessage) {
|
||||
return MergeFrom((ImportMessage) other);
|
||||
} else {
|
||||
base.MergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(ImportMessage other) {
|
||||
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this;
|
||||
PrepareBuilder();
|
||||
if (other.HasD) {
|
||||
D = other.D;
|
||||
}
|
||||
this.MergeUnknownFields(other.UnknownFields);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input) {
|
||||
return MergeFrom(input, pb::ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
PrepareBuilder();
|
||||
pb::UnknownFieldSet.Builder unknownFields = null;
|
||||
uint tag;
|
||||
string field_name;
|
||||
while (input.ReadTag(out tag, out field_name)) {
|
||||
if(tag == 0 && field_name != null) {
|
||||
int field_ordinal = global::System.Array.BinarySearch(_importMessageFieldNames, field_name, global::System.StringComparer.Ordinal);
|
||||
if(field_ordinal >= 0)
|
||||
tag = _importMessageFieldTags[field_ordinal];
|
||||
else {
|
||||
if (unknownFields == null) {
|
||||
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
|
||||
}
|
||||
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (tag) {
|
||||
case 0: {
|
||||
throw pb::InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
default: {
|
||||
if (pb::WireFormat.IsEndGroupTag(tag)) {
|
||||
if (unknownFields != null) {
|
||||
this.UnknownFields = unknownFields.Build();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if (unknownFields == null) {
|
||||
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
|
||||
}
|
||||
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
result.hasD = input.ReadInt32(ref result.d_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unknownFields != null) {
|
||||
this.UnknownFields = unknownFields.Build();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public bool HasD {
|
||||
get { return result.hasD; }
|
||||
}
|
||||
public int D {
|
||||
get { return result.D; }
|
||||
set { SetD(value); }
|
||||
}
|
||||
public Builder SetD(int value) {
|
||||
PrepareBuilder();
|
||||
result.hasD = true;
|
||||
result.d_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder ClearD() {
|
||||
PrepareBuilder();
|
||||
result.hasD = false;
|
||||
result.d_ = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
static ImportMessage() {
|
||||
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnittestImport.Descriptor, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion Designer generated code
|
@ -1,311 +0,0 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/unittest_import_lite.proto
|
||||
#pragma warning disable 1591, 0612, 3021
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.ProtocolBuffers;
|
||||
using pbc = global::Google.ProtocolBuffers.Collections;
|
||||
using pbd = global::Google.ProtocolBuffers.Descriptors;
|
||||
using scg = global::System.Collections.Generic;
|
||||
namespace Google.ProtocolBuffers.TestProtos {
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial class UnittestImportLite {
|
||||
|
||||
#region Extension registration
|
||||
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
|
||||
}
|
||||
#endregion
|
||||
#region Static variables
|
||||
#endregion
|
||||
#region Extensions
|
||||
internal static readonly object Descriptor;
|
||||
static UnittestImportLite() {
|
||||
Descriptor = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Enums
|
||||
public enum ImportEnumLite {
|
||||
IMPORT_LITE_FOO = 7,
|
||||
IMPORT_LITE_BAR = 8,
|
||||
IMPORT_LITE_BAZ = 9,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class ImportMessageLite : pb::GeneratedMessageLite<ImportMessageLite, ImportMessageLite.Builder> {
|
||||
private ImportMessageLite() { }
|
||||
private static readonly ImportMessageLite defaultInstance = new ImportMessageLite().MakeReadOnly();
|
||||
private static readonly string[] _importMessageLiteFieldNames = new string[] { "d" };
|
||||
private static readonly uint[] _importMessageLiteFieldTags = new uint[] { 8 };
|
||||
public static ImportMessageLite DefaultInstance {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
|
||||
public override ImportMessageLite DefaultInstanceForType {
|
||||
get { return DefaultInstance; }
|
||||
}
|
||||
|
||||
protected override ImportMessageLite ThisMessage {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public const int DFieldNumber = 1;
|
||||
private bool hasD;
|
||||
private int d_;
|
||||
public bool HasD {
|
||||
get { return hasD; }
|
||||
}
|
||||
public int D {
|
||||
get { return d_; }
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteTo(pb::ICodedOutputStream output) {
|
||||
CalcSerializedSize();
|
||||
string[] field_names = _importMessageLiteFieldNames;
|
||||
if (hasD) {
|
||||
output.WriteInt32(1, field_names[0], D);
|
||||
}
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public override int SerializedSize {
|
||||
get {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
return CalcSerializedSize();
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (hasD) {
|
||||
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
|
||||
}
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
#region Lite runtime methods
|
||||
public override int GetHashCode() {
|
||||
int hash = GetType().GetHashCode();
|
||||
if (hasD) {
|
||||
hash ^= d_.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
ImportMessageLite other = obj as ImportMessageLite;
|
||||
if (other == null) return false;
|
||||
if (hasD != other.hasD || (hasD && !d_.Equals(other.d_))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void PrintTo(global::System.IO.TextWriter writer) {
|
||||
PrintField("d", hasD, d_, writer);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static ImportMessageLite ParseFrom(pb::ByteString data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(byte[] data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(global::System.IO.Stream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseDelimitedFrom(global::System.IO.Stream input) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(pb::ICodedInputStream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static ImportMessageLite ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
private ImportMessageLite MakeReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder CreateBuilder() { return new Builder(); }
|
||||
public override Builder ToBuilder() { return CreateBuilder(this); }
|
||||
public override Builder CreateBuilderForType() { return new Builder(); }
|
||||
public static Builder CreateBuilder(ImportMessageLite prototype) {
|
||||
return new Builder(prototype);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class Builder : pb::GeneratedBuilderLite<ImportMessageLite, Builder> {
|
||||
protected override Builder ThisBuilder {
|
||||
get { return this; }
|
||||
}
|
||||
public Builder() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
internal Builder(ImportMessageLite cloneFrom) {
|
||||
result = cloneFrom;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
|
||||
private bool resultIsReadOnly;
|
||||
private ImportMessageLite result;
|
||||
|
||||
private ImportMessageLite PrepareBuilder() {
|
||||
if (resultIsReadOnly) {
|
||||
ImportMessageLite original = result;
|
||||
result = new ImportMessageLite();
|
||||
resultIsReadOnly = false;
|
||||
MergeFrom(original);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get { return result.IsInitialized; }
|
||||
}
|
||||
|
||||
protected override ImportMessageLite MessageBeingBuilt {
|
||||
get { return PrepareBuilder(); }
|
||||
}
|
||||
|
||||
public override Builder Clear() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder Clone() {
|
||||
if (resultIsReadOnly) {
|
||||
return new Builder(result);
|
||||
} else {
|
||||
return new Builder().MergeFrom(result);
|
||||
}
|
||||
}
|
||||
|
||||
public override ImportMessageLite DefaultInstanceForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance; }
|
||||
}
|
||||
|
||||
public override ImportMessageLite BuildPartial() {
|
||||
if (resultIsReadOnly) {
|
||||
return result;
|
||||
}
|
||||
resultIsReadOnly = true;
|
||||
return result.MakeReadOnly();
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::IMessageLite other) {
|
||||
if (other is ImportMessageLite) {
|
||||
return MergeFrom((ImportMessageLite) other);
|
||||
} else {
|
||||
base.MergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(ImportMessageLite other) {
|
||||
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this;
|
||||
PrepareBuilder();
|
||||
if (other.HasD) {
|
||||
D = other.D;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input) {
|
||||
return MergeFrom(input, pb::ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
PrepareBuilder();
|
||||
uint tag;
|
||||
string field_name;
|
||||
while (input.ReadTag(out tag, out field_name)) {
|
||||
if(tag == 0 && field_name != null) {
|
||||
int field_ordinal = global::System.Array.BinarySearch(_importMessageLiteFieldNames, field_name, global::System.StringComparer.Ordinal);
|
||||
if(field_ordinal >= 0)
|
||||
tag = _importMessageLiteFieldTags[field_ordinal];
|
||||
else {
|
||||
ParseUnknownField(input, extensionRegistry, tag, field_name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (tag) {
|
||||
case 0: {
|
||||
throw pb::InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
default: {
|
||||
if (pb::WireFormat.IsEndGroupTag(tag)) {
|
||||
return this;
|
||||
}
|
||||
ParseUnknownField(input, extensionRegistry, tag, field_name);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
result.hasD = input.ReadInt32(ref result.d_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public bool HasD {
|
||||
get { return result.hasD; }
|
||||
}
|
||||
public int D {
|
||||
get { return result.D; }
|
||||
set { SetD(value); }
|
||||
}
|
||||
public Builder SetD(int value) {
|
||||
PrepareBuilder();
|
||||
result.hasD = true;
|
||||
result.d_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder ClearD() {
|
||||
PrepareBuilder();
|
||||
result.hasD = false;
|
||||
result.d_ = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
static ImportMessageLite() {
|
||||
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnittestImportLite.Descriptor, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion Designer generated code
|
@ -1,333 +0,0 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/unittest_import_public.proto
|
||||
#pragma warning disable 1591, 0612, 3021
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.ProtocolBuffers;
|
||||
using pbc = global::Google.ProtocolBuffers.Collections;
|
||||
using pbd = global::Google.ProtocolBuffers.Descriptors;
|
||||
using scg = global::System.Collections.Generic;
|
||||
namespace Google.ProtocolBuffers.TestProtos {
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial class UnittestImportPublic {
|
||||
|
||||
#region Extension registration
|
||||
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
|
||||
}
|
||||
#endregion
|
||||
#region Static variables
|
||||
internal static pbd::MessageDescriptor internal__static_protobuf_unittest_import_PublicImportMessage__Descriptor;
|
||||
internal static pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.PublicImportMessage, global::Google.ProtocolBuffers.TestProtos.PublicImportMessage.Builder> internal__static_protobuf_unittest_import_PublicImportMessage__FieldAccessorTable;
|
||||
#endregion
|
||||
#region Descriptor
|
||||
public static pbd::FileDescriptor Descriptor {
|
||||
get { return descriptor; }
|
||||
}
|
||||
private static pbd::FileDescriptor descriptor;
|
||||
|
||||
static UnittestImportPublic() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"Cixnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0X3B1YmxpYy5wcm90",
|
||||
"bxIYcHJvdG9idWZfdW5pdHRlc3RfaW1wb3J0IiAKE1B1YmxpY0ltcG9ydE1l",
|
||||
"c3NhZ2USCQoBZRgBIAEoBUI+Chhjb20uZ29vZ2xlLnByb3RvYnVmLnRlc3Sq",
|
||||
"AiFHb29nbGUuUHJvdG9jb2xCdWZmZXJzLlRlc3RQcm90b3M="));
|
||||
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
|
||||
descriptor = root;
|
||||
internal__static_protobuf_unittest_import_PublicImportMessage__Descriptor = Descriptor.MessageTypes[0];
|
||||
internal__static_protobuf_unittest_import_PublicImportMessage__FieldAccessorTable =
|
||||
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.PublicImportMessage, global::Google.ProtocolBuffers.TestProtos.PublicImportMessage.Builder>(internal__static_protobuf_unittest_import_PublicImportMessage__Descriptor,
|
||||
new string[] { "E", });
|
||||
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
|
||||
RegisterAllExtensions(registry);
|
||||
return registry;
|
||||
};
|
||||
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
|
||||
new pbd::FileDescriptor[] {
|
||||
}, assigner);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class PublicImportMessage : pb::GeneratedMessage<PublicImportMessage, PublicImportMessage.Builder> {
|
||||
private PublicImportMessage() { }
|
||||
private static readonly PublicImportMessage defaultInstance = new PublicImportMessage().MakeReadOnly();
|
||||
private static readonly string[] _publicImportMessageFieldNames = new string[] { "e" };
|
||||
private static readonly uint[] _publicImportMessageFieldTags = new uint[] { 8 };
|
||||
public static PublicImportMessage DefaultInstance {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
|
||||
public override PublicImportMessage DefaultInstanceForType {
|
||||
get { return DefaultInstance; }
|
||||
}
|
||||
|
||||
protected override PublicImportMessage ThisMessage {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public static pbd::MessageDescriptor Descriptor {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.UnittestImportPublic.internal__static_protobuf_unittest_import_PublicImportMessage__Descriptor; }
|
||||
}
|
||||
|
||||
protected override pb::FieldAccess.FieldAccessorTable<PublicImportMessage, PublicImportMessage.Builder> InternalFieldAccessors {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.UnittestImportPublic.internal__static_protobuf_unittest_import_PublicImportMessage__FieldAccessorTable; }
|
||||
}
|
||||
|
||||
public const int EFieldNumber = 1;
|
||||
private bool hasE;
|
||||
private int e_;
|
||||
public bool HasE {
|
||||
get { return hasE; }
|
||||
}
|
||||
public int E {
|
||||
get { return e_; }
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteTo(pb::ICodedOutputStream output) {
|
||||
CalcSerializedSize();
|
||||
string[] field_names = _publicImportMessageFieldNames;
|
||||
if (hasE) {
|
||||
output.WriteInt32(1, field_names[0], E);
|
||||
}
|
||||
UnknownFields.WriteTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public override int SerializedSize {
|
||||
get {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
return CalcSerializedSize();
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (hasE) {
|
||||
size += pb::CodedOutputStream.ComputeInt32Size(1, E);
|
||||
}
|
||||
size += UnknownFields.SerializedSize;
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(pb::ByteString data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(byte[] data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(global::System.IO.Stream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseDelimitedFrom(global::System.IO.Stream input) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(pb::ICodedInputStream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
private PublicImportMessage MakeReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder CreateBuilder() { return new Builder(); }
|
||||
public override Builder ToBuilder() { return CreateBuilder(this); }
|
||||
public override Builder CreateBuilderForType() { return new Builder(); }
|
||||
public static Builder CreateBuilder(PublicImportMessage prototype) {
|
||||
return new Builder(prototype);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class Builder : pb::GeneratedBuilder<PublicImportMessage, Builder> {
|
||||
protected override Builder ThisBuilder {
|
||||
get { return this; }
|
||||
}
|
||||
public Builder() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
internal Builder(PublicImportMessage cloneFrom) {
|
||||
result = cloneFrom;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
|
||||
private bool resultIsReadOnly;
|
||||
private PublicImportMessage result;
|
||||
|
||||
private PublicImportMessage PrepareBuilder() {
|
||||
if (resultIsReadOnly) {
|
||||
PublicImportMessage original = result;
|
||||
result = new PublicImportMessage();
|
||||
resultIsReadOnly = false;
|
||||
MergeFrom(original);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get { return result.IsInitialized; }
|
||||
}
|
||||
|
||||
protected override PublicImportMessage MessageBeingBuilt {
|
||||
get { return PrepareBuilder(); }
|
||||
}
|
||||
|
||||
public override Builder Clear() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder Clone() {
|
||||
if (resultIsReadOnly) {
|
||||
return new Builder(result);
|
||||
} else {
|
||||
return new Builder().MergeFrom(result);
|
||||
}
|
||||
}
|
||||
|
||||
public override pbd::MessageDescriptor DescriptorForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.PublicImportMessage.Descriptor; }
|
||||
}
|
||||
|
||||
public override PublicImportMessage DefaultInstanceForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.PublicImportMessage.DefaultInstance; }
|
||||
}
|
||||
|
||||
public override PublicImportMessage BuildPartial() {
|
||||
if (resultIsReadOnly) {
|
||||
return result;
|
||||
}
|
||||
resultIsReadOnly = true;
|
||||
return result.MakeReadOnly();
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::IMessage other) {
|
||||
if (other is PublicImportMessage) {
|
||||
return MergeFrom((PublicImportMessage) other);
|
||||
} else {
|
||||
base.MergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(PublicImportMessage other) {
|
||||
if (other == global::Google.ProtocolBuffers.TestProtos.PublicImportMessage.DefaultInstance) return this;
|
||||
PrepareBuilder();
|
||||
if (other.HasE) {
|
||||
E = other.E;
|
||||
}
|
||||
this.MergeUnknownFields(other.UnknownFields);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input) {
|
||||
return MergeFrom(input, pb::ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
PrepareBuilder();
|
||||
pb::UnknownFieldSet.Builder unknownFields = null;
|
||||
uint tag;
|
||||
string field_name;
|
||||
while (input.ReadTag(out tag, out field_name)) {
|
||||
if(tag == 0 && field_name != null) {
|
||||
int field_ordinal = global::System.Array.BinarySearch(_publicImportMessageFieldNames, field_name, global::System.StringComparer.Ordinal);
|
||||
if(field_ordinal >= 0)
|
||||
tag = _publicImportMessageFieldTags[field_ordinal];
|
||||
else {
|
||||
if (unknownFields == null) {
|
||||
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
|
||||
}
|
||||
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (tag) {
|
||||
case 0: {
|
||||
throw pb::InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
default: {
|
||||
if (pb::WireFormat.IsEndGroupTag(tag)) {
|
||||
if (unknownFields != null) {
|
||||
this.UnknownFields = unknownFields.Build();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if (unknownFields == null) {
|
||||
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
|
||||
}
|
||||
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
result.hasE = input.ReadInt32(ref result.e_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unknownFields != null) {
|
||||
this.UnknownFields = unknownFields.Build();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public bool HasE {
|
||||
get { return result.hasE; }
|
||||
}
|
||||
public int E {
|
||||
get { return result.E; }
|
||||
set { SetE(value); }
|
||||
}
|
||||
public Builder SetE(int value) {
|
||||
PrepareBuilder();
|
||||
result.hasE = true;
|
||||
result.e_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder ClearE() {
|
||||
PrepareBuilder();
|
||||
result.hasE = false;
|
||||
result.e_ = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
static PublicImportMessage() {
|
||||
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnittestImportPublic.Descriptor, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion Designer generated code
|
@ -1,302 +0,0 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/unittest_import_public_lite.proto
|
||||
#pragma warning disable 1591, 0612, 3021
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.ProtocolBuffers;
|
||||
using pbc = global::Google.ProtocolBuffers.Collections;
|
||||
using pbd = global::Google.ProtocolBuffers.Descriptors;
|
||||
using scg = global::System.Collections.Generic;
|
||||
namespace Google.ProtocolBuffers.TestProtos {
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial class UnittestImportPublicLite {
|
||||
|
||||
#region Extension registration
|
||||
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
|
||||
}
|
||||
#endregion
|
||||
#region Static variables
|
||||
#endregion
|
||||
#region Extensions
|
||||
internal static readonly object Descriptor;
|
||||
static UnittestImportPublicLite() {
|
||||
Descriptor = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class PublicImportMessageLite : pb::GeneratedMessageLite<PublicImportMessageLite, PublicImportMessageLite.Builder> {
|
||||
private PublicImportMessageLite() { }
|
||||
private static readonly PublicImportMessageLite defaultInstance = new PublicImportMessageLite().MakeReadOnly();
|
||||
private static readonly string[] _publicImportMessageLiteFieldNames = new string[] { "e" };
|
||||
private static readonly uint[] _publicImportMessageLiteFieldTags = new uint[] { 8 };
|
||||
public static PublicImportMessageLite DefaultInstance {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
|
||||
public override PublicImportMessageLite DefaultInstanceForType {
|
||||
get { return DefaultInstance; }
|
||||
}
|
||||
|
||||
protected override PublicImportMessageLite ThisMessage {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public const int EFieldNumber = 1;
|
||||
private bool hasE;
|
||||
private int e_;
|
||||
public bool HasE {
|
||||
get { return hasE; }
|
||||
}
|
||||
public int E {
|
||||
get { return e_; }
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteTo(pb::ICodedOutputStream output) {
|
||||
CalcSerializedSize();
|
||||
string[] field_names = _publicImportMessageLiteFieldNames;
|
||||
if (hasE) {
|
||||
output.WriteInt32(1, field_names[0], E);
|
||||
}
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public override int SerializedSize {
|
||||
get {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
return CalcSerializedSize();
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (hasE) {
|
||||
size += pb::CodedOutputStream.ComputeInt32Size(1, E);
|
||||
}
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
#region Lite runtime methods
|
||||
public override int GetHashCode() {
|
||||
int hash = GetType().GetHashCode();
|
||||
if (hasE) {
|
||||
hash ^= e_.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
PublicImportMessageLite other = obj as PublicImportMessageLite;
|
||||
if (other == null) return false;
|
||||
if (hasE != other.hasE || (hasE && !e_.Equals(other.e_))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void PrintTo(global::System.IO.TextWriter writer) {
|
||||
PrintField("e", hasE, e_, writer);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static PublicImportMessageLite ParseFrom(pb::ByteString data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(byte[] data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(global::System.IO.Stream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseDelimitedFrom(global::System.IO.Stream input) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(pb::ICodedInputStream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static PublicImportMessageLite ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
private PublicImportMessageLite MakeReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder CreateBuilder() { return new Builder(); }
|
||||
public override Builder ToBuilder() { return CreateBuilder(this); }
|
||||
public override Builder CreateBuilderForType() { return new Builder(); }
|
||||
public static Builder CreateBuilder(PublicImportMessageLite prototype) {
|
||||
return new Builder(prototype);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class Builder : pb::GeneratedBuilderLite<PublicImportMessageLite, Builder> {
|
||||
protected override Builder ThisBuilder {
|
||||
get { return this; }
|
||||
}
|
||||
public Builder() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
internal Builder(PublicImportMessageLite cloneFrom) {
|
||||
result = cloneFrom;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
|
||||
private bool resultIsReadOnly;
|
||||
private PublicImportMessageLite result;
|
||||
|
||||
private PublicImportMessageLite PrepareBuilder() {
|
||||
if (resultIsReadOnly) {
|
||||
PublicImportMessageLite original = result;
|
||||
result = new PublicImportMessageLite();
|
||||
resultIsReadOnly = false;
|
||||
MergeFrom(original);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get { return result.IsInitialized; }
|
||||
}
|
||||
|
||||
protected override PublicImportMessageLite MessageBeingBuilt {
|
||||
get { return PrepareBuilder(); }
|
||||
}
|
||||
|
||||
public override Builder Clear() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder Clone() {
|
||||
if (resultIsReadOnly) {
|
||||
return new Builder(result);
|
||||
} else {
|
||||
return new Builder().MergeFrom(result);
|
||||
}
|
||||
}
|
||||
|
||||
public override PublicImportMessageLite DefaultInstanceForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.PublicImportMessageLite.DefaultInstance; }
|
||||
}
|
||||
|
||||
public override PublicImportMessageLite BuildPartial() {
|
||||
if (resultIsReadOnly) {
|
||||
return result;
|
||||
}
|
||||
resultIsReadOnly = true;
|
||||
return result.MakeReadOnly();
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::IMessageLite other) {
|
||||
if (other is PublicImportMessageLite) {
|
||||
return MergeFrom((PublicImportMessageLite) other);
|
||||
} else {
|
||||
base.MergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(PublicImportMessageLite other) {
|
||||
if (other == global::Google.ProtocolBuffers.TestProtos.PublicImportMessageLite.DefaultInstance) return this;
|
||||
PrepareBuilder();
|
||||
if (other.HasE) {
|
||||
E = other.E;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input) {
|
||||
return MergeFrom(input, pb::ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
PrepareBuilder();
|
||||
uint tag;
|
||||
string field_name;
|
||||
while (input.ReadTag(out tag, out field_name)) {
|
||||
if(tag == 0 && field_name != null) {
|
||||
int field_ordinal = global::System.Array.BinarySearch(_publicImportMessageLiteFieldNames, field_name, global::System.StringComparer.Ordinal);
|
||||
if(field_ordinal >= 0)
|
||||
tag = _publicImportMessageLiteFieldTags[field_ordinal];
|
||||
else {
|
||||
ParseUnknownField(input, extensionRegistry, tag, field_name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (tag) {
|
||||
case 0: {
|
||||
throw pb::InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
default: {
|
||||
if (pb::WireFormat.IsEndGroupTag(tag)) {
|
||||
return this;
|
||||
}
|
||||
ParseUnknownField(input, extensionRegistry, tag, field_name);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
result.hasE = input.ReadInt32(ref result.e_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public bool HasE {
|
||||
get { return result.hasE; }
|
||||
}
|
||||
public int E {
|
||||
get { return result.E; }
|
||||
set { SetE(value); }
|
||||
}
|
||||
public Builder SetE(int value) {
|
||||
PrepareBuilder();
|
||||
result.hasE = true;
|
||||
result.e_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder ClearE() {
|
||||
PrepareBuilder();
|
||||
result.hasE = false;
|
||||
result.e_ = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
static PublicImportMessageLite() {
|
||||
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnittestImportPublicLite.Descriptor, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion Designer generated code
|
File diff suppressed because it is too large
Load Diff
@ -1,325 +0,0 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/unittest_lite_imports_nonlite.proto
|
||||
#pragma warning disable 1591, 0612, 3021
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.ProtocolBuffers;
|
||||
using pbc = global::Google.ProtocolBuffers.Collections;
|
||||
using pbd = global::Google.ProtocolBuffers.Descriptors;
|
||||
using scg = global::System.Collections.Generic;
|
||||
namespace Google.ProtocolBuffers.TestProtos {
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial class UnittestLiteImportsNonlite {
|
||||
|
||||
#region Extension registration
|
||||
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
|
||||
}
|
||||
#endregion
|
||||
#region Static variables
|
||||
#endregion
|
||||
#region Extensions
|
||||
internal static readonly object Descriptor;
|
||||
static UnittestLiteImportsNonlite() {
|
||||
Descriptor = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessageLite<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> {
|
||||
private TestLiteImportsNonlite() { }
|
||||
private static readonly TestLiteImportsNonlite defaultInstance = new TestLiteImportsNonlite().MakeReadOnly();
|
||||
private static readonly string[] _testLiteImportsNonliteFieldNames = new string[] { "message" };
|
||||
private static readonly uint[] _testLiteImportsNonliteFieldTags = new uint[] { 10 };
|
||||
public static TestLiteImportsNonlite DefaultInstance {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
|
||||
public override TestLiteImportsNonlite DefaultInstanceForType {
|
||||
get { return DefaultInstance; }
|
||||
}
|
||||
|
||||
protected override TestLiteImportsNonlite ThisMessage {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public const int MessageFieldNumber = 1;
|
||||
private bool hasMessage;
|
||||
private global::Google.ProtocolBuffers.TestProtos.TestAllTypes message_;
|
||||
public bool HasMessage {
|
||||
get { return hasMessage; }
|
||||
}
|
||||
public global::Google.ProtocolBuffers.TestProtos.TestAllTypes Message {
|
||||
get { return message_ ?? global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance; }
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteTo(pb::ICodedOutputStream output) {
|
||||
CalcSerializedSize();
|
||||
string[] field_names = _testLiteImportsNonliteFieldNames;
|
||||
if (hasMessage) {
|
||||
output.WriteMessage(1, field_names[0], Message);
|
||||
}
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public override int SerializedSize {
|
||||
get {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
return CalcSerializedSize();
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (hasMessage) {
|
||||
size += pb::CodedOutputStream.ComputeMessageSize(1, Message);
|
||||
}
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
#region Lite runtime methods
|
||||
public override int GetHashCode() {
|
||||
int hash = GetType().GetHashCode();
|
||||
if (hasMessage) hash ^= message_.GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
TestLiteImportsNonlite other = obj as TestLiteImportsNonlite;
|
||||
if (other == null) return false;
|
||||
if (hasMessage != other.hasMessage || (hasMessage && !message_.Equals(other.message_))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void PrintTo(global::System.IO.TextWriter writer) {
|
||||
PrintField("message", hasMessage, message_, writer);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static TestLiteImportsNonlite ParseFrom(pb::ByteString data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(byte[] data) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(global::System.IO.Stream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseDelimitedFrom(global::System.IO.Stream input) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(pb::ICodedInputStream input) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
|
||||
}
|
||||
public static TestLiteImportsNonlite ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
|
||||
}
|
||||
private TestLiteImportsNonlite MakeReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder CreateBuilder() { return new Builder(); }
|
||||
public override Builder ToBuilder() { return CreateBuilder(this); }
|
||||
public override Builder CreateBuilderForType() { return new Builder(); }
|
||||
public static Builder CreateBuilder(TestLiteImportsNonlite prototype) {
|
||||
return new Builder(prototype);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public sealed partial class Builder : pb::GeneratedBuilderLite<TestLiteImportsNonlite, Builder> {
|
||||
protected override Builder ThisBuilder {
|
||||
get { return this; }
|
||||
}
|
||||
public Builder() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
internal Builder(TestLiteImportsNonlite cloneFrom) {
|
||||
result = cloneFrom;
|
||||
resultIsReadOnly = true;
|
||||
}
|
||||
|
||||
private bool resultIsReadOnly;
|
||||
private TestLiteImportsNonlite result;
|
||||
|
||||
private TestLiteImportsNonlite PrepareBuilder() {
|
||||
if (resultIsReadOnly) {
|
||||
TestLiteImportsNonlite original = result;
|
||||
result = new TestLiteImportsNonlite();
|
||||
resultIsReadOnly = false;
|
||||
MergeFrom(original);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool IsInitialized {
|
||||
get { return result.IsInitialized; }
|
||||
}
|
||||
|
||||
protected override TestLiteImportsNonlite MessageBeingBuilt {
|
||||
get { return PrepareBuilder(); }
|
||||
}
|
||||
|
||||
public override Builder Clear() {
|
||||
result = DefaultInstance;
|
||||
resultIsReadOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder Clone() {
|
||||
if (resultIsReadOnly) {
|
||||
return new Builder(result);
|
||||
} else {
|
||||
return new Builder().MergeFrom(result);
|
||||
}
|
||||
}
|
||||
|
||||
public override TestLiteImportsNonlite DefaultInstanceForType {
|
||||
get { return global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance; }
|
||||
}
|
||||
|
||||
public override TestLiteImportsNonlite BuildPartial() {
|
||||
if (resultIsReadOnly) {
|
||||
return result;
|
||||
}
|
||||
resultIsReadOnly = true;
|
||||
return result.MakeReadOnly();
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::IMessageLite other) {
|
||||
if (other is TestLiteImportsNonlite) {
|
||||
return MergeFrom((TestLiteImportsNonlite) other);
|
||||
} else {
|
||||
base.MergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(TestLiteImportsNonlite other) {
|
||||
if (other == global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance) return this;
|
||||
PrepareBuilder();
|
||||
if (other.HasMessage) {
|
||||
MergeMessage(other.Message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input) {
|
||||
return MergeFrom(input, pb::ExtensionRegistry.Empty);
|
||||
}
|
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
|
||||
PrepareBuilder();
|
||||
uint tag;
|
||||
string field_name;
|
||||
while (input.ReadTag(out tag, out field_name)) {
|
||||
if(tag == 0 && field_name != null) {
|
||||
int field_ordinal = global::System.Array.BinarySearch(_testLiteImportsNonliteFieldNames, field_name, global::System.StringComparer.Ordinal);
|
||||
if(field_ordinal >= 0)
|
||||
tag = _testLiteImportsNonliteFieldTags[field_ordinal];
|
||||
else {
|
||||
ParseUnknownField(input, extensionRegistry, tag, field_name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (tag) {
|
||||
case 0: {
|
||||
throw pb::InvalidProtocolBufferException.InvalidTag();
|
||||
}
|
||||
default: {
|
||||
if (pb::WireFormat.IsEndGroupTag(tag)) {
|
||||
return this;
|
||||
}
|
||||
ParseUnknownField(input, extensionRegistry, tag, field_name);
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder();
|
||||
if (result.hasMessage) {
|
||||
subBuilder.MergeFrom(Message);
|
||||
}
|
||||
input.ReadMessage(subBuilder, extensionRegistry);
|
||||
Message = subBuilder.BuildPartial();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public bool HasMessage {
|
||||
get { return result.hasMessage; }
|
||||
}
|
||||
public global::Google.ProtocolBuffers.TestProtos.TestAllTypes Message {
|
||||
get { return result.Message; }
|
||||
set { SetMessage(value); }
|
||||
}
|
||||
public Builder SetMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) {
|
||||
pb::ThrowHelper.ThrowIfNull(value, "value");
|
||||
PrepareBuilder();
|
||||
result.hasMessage = true;
|
||||
result.message_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder SetMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder builderForValue) {
|
||||
pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
|
||||
PrepareBuilder();
|
||||
result.hasMessage = true;
|
||||
result.message_ = builderForValue.Build();
|
||||
return this;
|
||||
}
|
||||
public Builder MergeMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) {
|
||||
pb::ThrowHelper.ThrowIfNull(value, "value");
|
||||
PrepareBuilder();
|
||||
if (result.hasMessage &&
|
||||
result.message_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance) {
|
||||
result.message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder(result.message_).MergeFrom(value).BuildPartial();
|
||||
} else {
|
||||
result.message_ = value;
|
||||
}
|
||||
result.hasMessage = true;
|
||||
return this;
|
||||
}
|
||||
public Builder ClearMessage() {
|
||||
PrepareBuilder();
|
||||
result.hasMessage = false;
|
||||
result.message_ = null;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
static TestLiteImportsNonlite() {
|
||||
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnittestLiteImportsNonlite.Descriptor, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion Designer generated code
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="2.6.4" targetFramework="net45" userInstalled="true" />
|
||||
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" userInstalled="true" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user