Split off the Serialization namespace into a new assembly.

pull/288/head
csharptest 14 years ago committed by rogerk
parent 304ff3a838
commit 0f3540e24b
  1. 1
      build/Common.targets
  2. 1
      build/build.csproj
  3. 7
      lib/System.Core/ExtensionAttribute.cs
  4. BIN
      lib/System.Core/System.Core.dll
  5. 1
      lib/System.Core/build.bat
  6. 5
      src/ProtoBench/ProtoBench.csproj
  7. 40
      src/ProtocolBuffers.Serialization/AbstractReader.cs
  8. 7
      src/ProtocolBuffers.Serialization/AbstractTextReader.cs
  9. 0
      src/ProtocolBuffers.Serialization/AbstractTextWriter.cs
  10. 0
      src/ProtocolBuffers.Serialization/AbstractWriter.cs
  11. 2
      src/ProtocolBuffers.Serialization/DictionaryReader.cs
  12. 0
      src/ProtocolBuffers.Serialization/DictionaryWriter.cs
  13. 100
      src/ProtocolBuffers.Serialization/Extensions.cs
  14. 0
      src/ProtocolBuffers.Serialization/JsonFormatReader.cs
  15. 0
      src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
  16. 0
      src/ProtocolBuffers.Serialization/JsonTextCursor.cs
  17. 76
      src/ProtocolBuffers.Serialization/Properties/AssemblyInfo.cs
  18. 152
      src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj
  19. 28
      src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs
  20. 15
      src/ProtocolBuffers.Serialization/XmlFormatReader.cs
  21. 0
      src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
  22. 0
      src/ProtocolBuffers.Serialization/XmlReaderOptions.cs
  23. 0
      src/ProtocolBuffers.Serialization/XmlWriterOptions.cs
  24. 4
      src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
  25. 8
      src/ProtocolBuffers.Test/TestWriterFormatJson.cs
  26. 8
      src/ProtocolBuffers.Test/TestWriterFormatXml.cs
  27. 13
      src/ProtocolBuffers.sln
  28. 22
      src/ProtocolBuffers/AbstractMessage.cs
  29. 38
      src/ProtocolBuffers/GeneratedMessage.cs
  30. 18
      src/ProtocolBuffers/IMessage.cs
  31. 14
      src/ProtocolBuffers/ProtocolBuffers.csproj
  32. 10
      src/ProtocolBuffers2008.sln

@ -84,6 +84,7 @@
<BenchmarkResources Include="$(BenchmarkProtosDirectory)\google_message1.dat" /> <BenchmarkResources Include="$(BenchmarkProtosDirectory)\google_message1.dat" />
<BenchmarkResources Include="$(BenchmarkProtosDirectory)\google_message2.dat" /> <BenchmarkResources Include="$(BenchmarkProtosDirectory)\google_message2.dat" />
<BenchmarkResources Include="$(SourceDirectory)\ProtocolBuffers\bin\$(BuildConfiguration)\Google.ProtocolBuffers.dll" /> <BenchmarkResources Include="$(SourceDirectory)\ProtocolBuffers\bin\$(BuildConfiguration)\Google.ProtocolBuffers.dll" />
<BenchmarkResources Include="$(SourceDirectory)\ProtocolBuffers.Serialization\bin\$(BuildConfiguration)\Google.ProtocolBuffers.Serialization.dll" />
<BenchmarkResources Include="$(SourceDirectory)\ProtoBench\bin\$(BuildConfiguration)\ProtoBench.exe" /> <BenchmarkResources Include="$(SourceDirectory)\ProtoBench\bin\$(BuildConfiguration)\ProtoBench.exe" />
</ItemGroup> </ItemGroup>

@ -145,6 +145,7 @@
<TestContainer Include="$(SourceDirectory)\ProtoGen.Test\bin\$(BuildConfiguration)\Google.ProtocolBuffers.ProtoGen.Test.dll" /> <TestContainer Include="$(SourceDirectory)\ProtoGen.Test\bin\$(BuildConfiguration)\Google.ProtocolBuffers.ProtoGen.Test.dll" />
<DynamicPackageItem Include="$(SourceDirectory)\ProtocolBuffers\bin\$(BuildConfiguration)\Google.ProtocolBuffers.*" /> <DynamicPackageItem Include="$(SourceDirectory)\ProtocolBuffers\bin\$(BuildConfiguration)\Google.ProtocolBuffers.*" />
<DynamicPackageItem Include="$(SourceDirectory)\ProtocolBuffers.Serialization\bin\$(BuildConfiguration)\Google.ProtocolBuffers.Serialization.*" />
<DynamicPackageItem Include="$(SourceDirectory)\ProtocolBuffers\bin\$(BuildConfiguration)\Google.ProtocolBuffersLite.*" /> <DynamicPackageItem Include="$(SourceDirectory)\ProtocolBuffers\bin\$(BuildConfiguration)\Google.ProtocolBuffersLite.*" />
<DynamicPackageItem Include="$(SourceDirectory)\ProtoGen\bin\$(BuildConfiguration)\ProtoGen.*" /> <DynamicPackageItem Include="$(SourceDirectory)\ProtoGen\bin\$(BuildConfiguration)\ProtoGen.*" />
<DynamicPackageItem Include="$(SourceDirectory)\ProtoMunge\bin\$(BuildConfiguration)\ProtoMunge.*" /> <DynamicPackageItem Include="$(SourceDirectory)\ProtoMunge\bin\$(BuildConfiguration)\ProtoMunge.*" />

@ -0,0 +1,7 @@
namespace System.Runtime.CompilerServices
{
/// <summary> Used for 2.0 compatibility </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}

Binary file not shown.

@ -0,0 +1 @@
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc /target:library /out:System.Core.dll /keyfile:..\..\keys\Google.ProtocolBuffers.snk ExtensionAttribute.cs

@ -72,6 +72,11 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj">
<Project>{231391AF-449C-4a39-986C-AD7F270F4750}</Project>
<Name>ProtocolBuffers.Serialization</Name>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj"> <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project> <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffers</Name> <Name>ProtocolBuffers</Name>

@ -12,8 +12,20 @@ namespace Google.ProtocolBuffers.Serialization
/// </summary> /// </summary>
public abstract class AbstractReader : ICodedInputStream public abstract class AbstractReader : ICodedInputStream
{ {
private const int MaxDepth = CodedInputStream.DefaultRecursionLimit; private const int DefaultMaxDepth = 64;
protected int Depth; private int _depth;
/// <summary> Constructs a new reader </summary>
protected AbstractReader() { MaxDepth = DefaultMaxDepth; }
/// <summary> Constructs a new child reader </summary>
protected AbstractReader(AbstractReader copyFrom)
{
_depth = copyFrom._depth + 1;
MaxDepth = copyFrom.MaxDepth;
}
/// <summary> Gets or sets the maximum recursion depth allowed </summary>
public int MaxDepth { get; set; }
/// <summary> /// <summary>
/// Merges the contents of stream into the provided message builder /// Merges the contents of stream into the provided message builder
@ -395,12 +407,12 @@ namespace Google.ProtocolBuffers.Serialization
void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry) void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
{ {
if (Depth++ > MaxDepth) if (_depth++ > MaxDepth)
{ {
throw InvalidProtocolBufferException.RecursionLimitExceeded(); throw new RecursionLimitExceededException();
} }
ReadGroup(builder, extensionRegistry); ReadGroup(builder, extensionRegistry);
Depth--; _depth--;
} }
void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder) void ICodedInputStream.ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
@ -410,12 +422,12 @@ namespace Google.ProtocolBuffers.Serialization
void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry) void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
{ {
if (Depth++ > MaxDepth) if (_depth++ > MaxDepth)
{ {
throw InvalidProtocolBufferException.RecursionLimitExceeded(); throw new RecursionLimitExceededException();
} }
ReadMessage(builder, extensionRegistry); ReadMessage(builder, extensionRegistry);
Depth--; _depth--;
} }
bool ICodedInputStream.ReadBytes(ref ByteString value) bool ICodedInputStream.ReadBytes(ref ByteString value)
@ -566,23 +578,23 @@ namespace Google.ProtocolBuffers.Serialization
void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType, void ICodedInputStream.ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
ExtensionRegistry registry) ExtensionRegistry registry)
{ {
if (Depth++ > MaxDepth) if (_depth++ > MaxDepth)
{ {
throw InvalidProtocolBufferException.RecursionLimitExceeded(); throw new RecursionLimitExceededException();
} }
ReadMessageArray(fieldName, list, messageType, registry); ReadMessageArray(fieldName, list, messageType, registry);
Depth--; _depth--;
} }
void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType, void ICodedInputStream.ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType,
ExtensionRegistry registry) ExtensionRegistry registry)
{ {
if (Depth++ > MaxDepth) if (_depth++ > MaxDepth)
{ {
throw InvalidProtocolBufferException.RecursionLimitExceeded(); throw new RecursionLimitExceededException();
} }
ReadGroupArray(fieldName, list, messageType, registry); ReadGroupArray(fieldName, list, messageType, registry);
Depth--; _depth--;
} }
bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value) bool ICodedInputStream.ReadPrimitiveField(FieldType fieldType, ref object value)

@ -9,6 +9,13 @@ namespace Google.ProtocolBuffers.Serialization
/// </summary> /// </summary>
public abstract class AbstractTextReader : AbstractReader public abstract class AbstractTextReader : AbstractReader
{ {
/// <summary> Constructs a new reader </summary>
protected AbstractTextReader() { }
/// <summary> Constructs a new child reader </summary>
protected AbstractTextReader(AbstractTextReader copyFrom)
: base(copyFrom)
{ }
/// <summary> /// <summary>
/// Reads a typed field as a string /// Reads a typed field as a string
/// </summary> /// </summary>

@ -161,7 +161,7 @@ namespace Google.ProtocolBuffers.Serialization
byte[] rawbytes = null; byte[] rawbytes = null;
if (GetValue(ref rawbytes)) if (GetValue(ref rawbytes))
{ {
value = ByteString.AttachBytes(rawbytes); value = ByteString.CopyFrom(rawbytes);
return true; return true;
} }
return false; return false;

@ -0,0 +1,100 @@
using System;
using System.Text;
using System.IO;
using System.Xml;
using Google.ProtocolBuffers.Serialization;
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(this 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(this 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(this IMessageLite message, string rootElementName)
{
StringWriter w = new StringWriter(new StringBuilder(4096));
XmlFormatWriter.CreateInstance(w).WriteMessage(rootElementName, message);
return w.ToString();
}
#endregion
#region IBuilderLite Extensions
/// <summary>
/// Merges a JSON object into this builder and returns
/// </summary>
public static TBuilder MergeFromJson<TBuilder>(this 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>(this 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>(this 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>(this 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>(this 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>(this TBuilder builder, string rootElementName, XmlReader reader,
ExtensionRegistry extensionRegistry) where TBuilder : IBuilderLite
{
return XmlFormatReader.CreateInstance(reader)
.Merge(rootElementName, builder, extensionRegistry);
}
#endregion
}
}

@ -0,0 +1,76 @@
// 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("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("279b643d-70e8-47ae-9eb1-500d1c48bab6")]
// 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.3.0.277")]
[assembly: AssemblyVersion("2.3.0.277")]
#if !COMPACT_FRAMEWORK_35
[assembly: AssemblyFileVersion("2.3.0.277")]
#endif
[assembly: CLSCompliant(true)]

@ -0,0 +1,152 @@
<?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>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_Silverlight2|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug_Silverlight2\</OutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT2</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_Silverlight2|AnyCPU'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release_Silverlight2\</OutputPath>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591, 1570, 1571, 1572, 1573, 1574</NoWarn>
<DefineConstants>TRACE;SILVERLIGHT2</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
<!-- Only for 2.x compatibility of extension methods -->
<Reference Include="System.Core">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\System.Core\System.Core.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions.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>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffers</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(Configuration)' == 'Debug' " />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(Configuration)' == 'Release' " />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" Condition=" '$(Configuration)' == 'Debug_Silverlight2' " />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" Condition=" '$(Configuration)' == 'Release_Silverlight2' " />
<!-- 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>

@ -0,0 +1,28 @@
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>
#if !SILVERLIGHT2
[Serializable]
#endif
public sealed class RecursionLimitExceededException : FormatException
{
const string message = "Possible malicious message had too many levels of nesting.";
internal RecursionLimitExceededException() : base(message)
{
}
#if !SILVERLIGHT2
private RecursionLimitExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
}
}

@ -75,6 +75,17 @@ namespace Google.ProtocolBuffers.Serialization
Options = XmlReaderOptions.None; Options = XmlReaderOptions.None;
} }
/// <summary>
/// Constructs the XmlFormatReader with the XmlReader and options
/// </summary>
protected XmlFormatReader(XmlFormatReader copyFrom, XmlReader input)
: base(copyFrom)
{
_input = input;
_rootElementName = copyFrom._rootElementName;
Options = copyFrom.Options;
}
/// <summary> /// <summary>
/// Gets or sets the options to use when reading the xml /// Gets or sets the options to use when reading the xml
/// </summary> /// </summary>
@ -104,9 +115,7 @@ namespace Google.ProtocolBuffers.Serialization
private XmlFormatReader CloneWith(XmlReader rdr) private XmlFormatReader CloneWith(XmlReader rdr)
{ {
XmlFormatReader copy = new XmlFormatReader(rdr).SetOptions(Options); XmlFormatReader copy = new XmlFormatReader(this, rdr);
copy._rootElementName = _rootElementName;
copy.Depth = Depth;
return copy; return copy;
} }

@ -124,6 +124,10 @@
<Compile Include="WireFormatTest.cs" /> <Compile Include="WireFormatTest.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj">
<Project>{231391AF-449C-4a39-986C-AD7F270F4750}</Project>
<Name>ProtocolBuffers.Serialization</Name>
</ProjectReference>
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj"> <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project> <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffers</Name> <Name>ProtocolBuffers</Name>

@ -38,7 +38,7 @@ namespace Google.ProtocolBuffers
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build(); TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string json = msg.ToJson(); string json = msg.ToJson();
Assert.AreEqual("{\"default_bool\":true}", json); Assert.AreEqual("{\"default_bool\":true}", json);
TestAllTypes copy = TestAllTypes.ParseFromJson(json); TestAllTypes copy = new TestAllTypes.Builder().MergeFromJson(json).Build();
Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool); Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
Assert.AreEqual(msg, copy); Assert.AreEqual(msg, copy);
} }
@ -49,7 +49,7 @@ namespace Google.ProtocolBuffers
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build(); TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string json = msg.ToJson(); string json = msg.ToJson();
Assert.AreEqual("{\"default_bool\":true}", json); Assert.AreEqual("{\"default_bool\":true}", json);
TestAllTypes copy = TestAllTypes.ParseFromJson(new StringReader(json)); TestAllTypes copy = new TestAllTypes.Builder().MergeFromJson(new StringReader(json)).Build();
Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool); Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
Assert.AreEqual(msg, copy); Assert.AreEqual(msg, copy);
} }
@ -337,13 +337,13 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(3, ordinal); Assert.AreEqual(3, ordinal);
Assert.AreEqual(3, builder.TextlinesCount); Assert.AreEqual(3, builder.TextlinesCount);
} }
[Test,ExpectedException(typeof(InvalidProtocolBufferException))] [Test,ExpectedException(typeof(RecursionLimitExceededException))]
public void TestRecursiveLimit() public void TestRecursiveLimit()
{ {
StringBuilder sb = new StringBuilder(8192); StringBuilder sb = new StringBuilder(8192);
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
sb.Append("{\"child\":"); sb.Append("{\"child\":");
TestXmlRescursive msg = TestXmlRescursive.ParseFromJson(sb.ToString()); TestXmlRescursive msg = new TestXmlRescursive.Builder().MergeFromJson(sb.ToString()).Build();
} }
[Test, ExpectedException(typeof(FormatException))] [Test, ExpectedException(typeof(FormatException))]
public void FailWithEmptyText() public void FailWithEmptyText()

@ -18,7 +18,7 @@ namespace Google.ProtocolBuffers
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build(); TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string xml = msg.ToXml(); string xml = msg.ToXml();
Assert.AreEqual("<root><default_bool>true</default_bool></root>", xml); Assert.AreEqual("<root><default_bool>true</default_bool></root>", xml);
TestAllTypes copy = TestAllTypes.ParseFromXml(XmlReader.Create(new StringReader(xml))); TestAllTypes copy = new TestAllTypes.Builder().MergeFromXml(XmlReader.Create(new StringReader(xml))).Build();
Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool); Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
Assert.AreEqual(msg, copy); Assert.AreEqual(msg, copy);
} }
@ -29,7 +29,7 @@ namespace Google.ProtocolBuffers
TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build(); TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
string xml = msg.ToXml("message"); string xml = msg.ToXml("message");
Assert.AreEqual("<message><default_bool>true</default_bool></message>", xml); Assert.AreEqual("<message><default_bool>true</default_bool></message>", xml);
TestAllTypes copy = TestAllTypes.ParseFromXml("message", XmlReader.Create(new StringReader(xml))); TestAllTypes copy = new TestAllTypes.Builder().MergeFromXml("message", XmlReader.Create(new StringReader(xml))).Build();
Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool); Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
Assert.AreEqual(msg, copy); Assert.AreEqual(msg, copy);
} }
@ -324,13 +324,13 @@ namespace Google.ProtocolBuffers
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
Assert.AreEqual(message, copy); Assert.AreEqual(message, copy);
} }
[Test, ExpectedException(typeof(InvalidProtocolBufferException))] [Test, ExpectedException(typeof(RecursionLimitExceededException))]
public void TestRecursiveLimit() public void TestRecursiveLimit()
{ {
StringBuilder sb = new StringBuilder(8192); StringBuilder sb = new StringBuilder(8192);
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
sb.Append("<child>"); sb.Append("<child>");
TestXmlRescursive msg = TestXmlRescursive.ParseFromXml("child", XmlReader.Create(new StringReader(sb.ToString()))); TestXmlRescursive msg = new TestXmlRescursive.Builder().MergeFromXml("child", XmlReader.Create(new StringReader(sb.ToString()))).Build();
} }
} }
} }

@ -1,5 +1,4 @@
 Microsoft Visual Studio Solution File, Format Version 11.00
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C-5FC2-4671-9216-781CB8187EC7}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C-5FC2-4671-9216-781CB8187EC7}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
@ -67,6 +66,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{66ED1950
..\build\RunBenchmarks.bat = ..\build\RunBenchmarks.bat ..\build\RunBenchmarks.bat = ..\build\RunBenchmarks.bat
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocolBuffers.Serialization", "ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj", "{231391AF-449C-4a39-986C-AD7F270F4750}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Silverlight2|Any CPU = Debug_Silverlight2|Any CPU Debug_Silverlight2|Any CPU = Debug_Silverlight2|Any CPU
@ -145,6 +146,14 @@ Global
{EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.Build.0 = Debug_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.Build.0 = Debug|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.ActiveCfg = Release_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.ActiveCfg = Release|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -40,7 +40,6 @@ using System.IO;
using System.Text; using System.Text;
using Google.ProtocolBuffers.Collections; using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.Serialization;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
@ -123,27 +122,6 @@ namespace Google.ProtocolBuffers
return TextFormat.PrintToString(this); return TextFormat.PrintToString(this);
} }
public string ToJson()
{
JsonFormatWriter w = JsonFormatWriter.CreateInstance();
w.WriteMessage(this);
return w.ToString();
}
public string ToXml()
{
StringWriter w = new StringWriter(new StringBuilder(4096));
XmlFormatWriter.CreateInstance(w).WriteMessage(this);
return w.ToString();
}
public string ToXml(string rootElementName)
{
StringWriter w = new StringWriter(new StringBuilder(4096));
XmlFormatWriter.CreateInstance(w).WriteMessage(rootElementName, this);
return w.ToString();
}
public override sealed void PrintTo(TextWriter writer) public override sealed void PrintTo(TextWriter writer)
{ {
TextFormat.Print(this, writer); TextFormat.Print(this, writer);

@ -42,7 +42,6 @@ using System.Xml;
using Google.ProtocolBuffers.Collections; using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.FieldAccess; using Google.ProtocolBuffers.FieldAccess;
using Google.ProtocolBuffers.Serialization;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
@ -178,42 +177,5 @@ namespace Google.ProtocolBuffers
{ {
unknownFields = fieldSet; unknownFields = fieldSet;
} }
public static TMessage ParseFromJson(string jsonText)
{
return JsonFormatReader.CreateInstance(jsonText)
.Merge(new TBuilder())
.Build();
}
public static TMessage ParseFromJson(TextReader reader)
{
return ParseFromJson(reader, ExtensionRegistry.Empty);
}
public static TMessage ParseFromJson(TextReader reader, ExtensionRegistry extensionRegistry)
{
return JsonFormatReader.CreateInstance(reader)
.Merge(new TBuilder(), extensionRegistry)
.Build();
}
public static TMessage ParseFromXml(XmlReader reader)
{
return ParseFromXml(XmlFormatReader.DefaultRootElementName, reader, ExtensionRegistry.Empty);
}
public static TMessage ParseFromXml(string rootElementName, XmlReader reader)
{
return ParseFromXml(rootElementName, reader, ExtensionRegistry.Empty);
}
public static TMessage ParseFromXml(string rootElementName, XmlReader reader,
ExtensionRegistry extensionRegistry)
{
return XmlFormatReader.CreateInstance(reader)
.Merge(rootElementName, new TBuilder(), extensionRegistry)
.Build();
}
} }
} }

@ -184,24 +184,6 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
new byte[] ToByteArray(); new byte[] ToByteArray();
/// <summary>
/// Serializes the message to JSON text. This is a trivial wrapper
/// around Serialization.JsonFormatWriter.WriteMessage.
/// </summary>
string ToJson();
/// <summary>
/// Serializes the message to XML text. This is a trivial wrapper
/// around Serialization.XmlFormatWriter.WriteMessage.
/// </summary>
string ToXml();
/// <summary>
/// Serializes the message to XML text using the element name provided.
/// This is a trivial wrapper around Serialization.XmlFormatWriter.WriteMessage.
/// </summary>
string ToXml(string rootElementName);
/// <summary> /// <summary>
/// Serializes the message and writes it to the given stream. /// Serializes the message and writes it to the given stream.
/// This is just a wrapper around WriteTo(ICodedOutputStream). This /// This is just a wrapper around WriteTo(ICodedOutputStream). This

@ -88,7 +88,6 @@
<ItemGroup> <ItemGroup>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -181,19 +180,6 @@
<Compile Include="NameHelpers.cs" /> <Compile Include="NameHelpers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RpcUtil.cs" /> <Compile Include="RpcUtil.cs" />
<Compile Include="Serialization\AbstractReader.cs" />
<Compile Include="Serialization\AbstractTextReader.cs" />
<Compile Include="Serialization\AbstractTextWriter.cs" />
<Compile Include="Serialization\AbstractWriter.cs" />
<Compile Include="Serialization\DictionaryReader.cs" />
<Compile Include="Serialization\DictionaryWriter.cs" />
<Compile Include="Serialization\JsonFormatReader.cs" />
<Compile Include="Serialization\JsonFormatWriter.cs" />
<Compile Include="Serialization\JsonTextCursor.cs" />
<Compile Include="Serialization\XmlFormatReader.cs" />
<Compile Include="Serialization\XmlFormatWriter.cs" />
<Compile Include="Serialization\XmlReaderOptions.cs" />
<Compile Include="Serialization\XmlWriterOptions.cs" />
<Compile Include="SilverlightCompatibility.cs" /> <Compile Include="SilverlightCompatibility.cs" />
<Compile Include="SortedList.cs" /> <Compile Include="SortedList.cs" />
<Compile Include="TextFormat.cs" /> <Compile Include="TextFormat.cs" />

@ -67,6 +67,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{66ED1950
..\build\RunBenchmarks.bat = ..\build\RunBenchmarks.bat ..\build\RunBenchmarks.bat = ..\build\RunBenchmarks.bat
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocolBuffers.Serialization", "ProtocolBuffers.Serialization\ProtocolBuffers.Serialization.csproj", "{231391AF-449C-4a39-986C-AD7F270F4750}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Silverlight2|Any CPU = Debug_Silverlight2|Any CPU Debug_Silverlight2|Any CPU = Debug_Silverlight2|Any CPU
@ -145,6 +147,14 @@ Global
{EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU
{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug_Silverlight2|Any CPU.Build.0 = Debug_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Debug|Any CPU.Build.0 = Debug|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.ActiveCfg = Release_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.ActiveCfg = Release|Any CPU
{231391AF-449C-4a39-986C-AD7F270F4750}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save