Commit c4d1d9df authored by csharptest's avatar csharptest Committed by rogerk

reintegration with tip

parents 2cf6e1b0 b6a14572
===============================================================================
Welcome to the C# port of Google Protocol Buffers, written by Jon Skeet
(skeet@pobox.com) based on the work of many talented people.
For more information about this port, visit its homepage:
http://protobuf-csharp-port.googlecode.com
For more information about Protocol Buffers in general, visit the project page
for the C++, Java and Python project:
http://protobuf.googlecode.com
===============================================================================
RELEASE NOTES - Version TBD
===============================================================================
(PENDING MERGE)
- Issue 20: Support for decorating classes [Serializable]
- Issue 22: Reusable Builder classes
- Issue 24: Support for using Json/Xml formats with ICodedInputStream
Features:
- Added option service_generator_type to control service generation with
NONE, GENERIC, INTERFACE, or IRPCDISPATCH
- Added interfaces IRpcDispatch and IRpcServerStub to provide for blocking
services and implementations.
- Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the
location of protoc.exe.
- Extracted interfaces for ICodedInputStream and ICodedOutputStream to allow
custom implementation of writers with both speed and size optimizations.
- Addition of the "Google.ProtoBuffers.Serialization" assembly to support
reading and writing messages to/from XML, JSON, IDictionary<,> and others.
- Several performance related fixes and tweeks
- Issue 3: Add option to mark generated code with attribute
- Issue 21: Decorate fields with [deprecated=true] as [System.Obsolete]
Fixes:
- Issue 13: Message with Field same name as message causes uncompilable .cs
- Issue 16: Does not integrate well with other tooling
- Issue 19: Support for negative enum values
- Issue 26: AddRange in GeneratedBuilder iterates twice.
- Issue 27: Remove XML documentation output from test projects to clear
warnings/errors.
- Big-endian support for float, and double on Silverlight
- Packed and Unpacked parsing allow for all repeated, as per version 2.3
- Fix for leaving Builder a public ctor on internal classes for use with
generic "where T: new()" constraints.
Other:
- Reformatted all code and line-endings to C# defaults
- Reworking of performance benchmarks to produce reliable results, option /v2
===============================================================================
RELEASE NOTES - Version 2.3.0.277
===============================================================================
Features:
- Added cls_compliance option to generate attributes indicating
non-CLS-compliance.
- Added file_extension option to control the generated output file's extension.
- Added umbrella_namespace option to place the umbrella class into a nested
namespace to address issues with proto files having the same name as a
message it contains.
- Added output_directory option to set the output path for the source file(s).
- Added ignore_google_protobuf option to avoid generating code for includes
from the google.protobuf package.
- Added the LITE framework (Google.ProtoBuffersLite.dll) and the ability to
generate code with "option optimize_for = LITE_RUNTIME;".
- Added ability to invoke protoc.exe from within ProtoGen.exe.
- Upgraded to protoc.exe (2.3) compiler.
Fixes:
- Issue 9: Class cannot be static and sealed error
- Issue 12: default value for enumerate fields must be filled out
Other:
- Rewrite of build using MSBbuild instead of NAnt
- Moved to NUnit Version 2.2.8.0
- Changed to using secure .snk for releases
===============================================================================
RELEASE NOTES - Version 0.9.1
===============================================================================
Fixes:
- issue 10: Incorrect encoding of packed fields when serialized
===============================================================================
RELEASE NOTES - Version 0.9.0
===============================================================================
- Initial release
===============================================================================
\ No newline at end of file
@echo off @echo off
SET BUILD_TARGET=%1 SET BUILD_TARGET=%1
SET BUILD_CONFIG=%2 SET BUILD_CONFIG=%2
IF "%BUILD_TARGET%"=="" SET BUILD_TARGET=Rebuild IF "%BUILD_TARGET%"=="" SET BUILD_TARGET=Rebuild
IF "%BUILD_CONFIG%"=="" SET BUILD_CONFIG=Debug IF "%BUILD_CONFIG%"=="" SET BUILD_CONFIG=Debug
CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.csproj %3 %4 %5 %6 /t:%BUILD_TARGET% /p:BuildConfiguration=%BUILD_CONFIG% /p:Platform="Any CPU" /p:BuildTools=4.0 /toolsversion:4.0" CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.csproj %3 %4 %5 %6 /t:%BUILD_TARGET% /p:BuildConfiguration=%BUILD_CONFIG% /p:Platform="Any CPU" /p:BuildTools=4.0 /toolsversion:4.0"
pause pause
\ No newline at end of file
@ECHO OFF @ECHO OFF
SET PREV_WORKING_DIR=%CD% SET PREV_WORKING_DIR=%CD%
CD %~dp0 CD %~dp0
REM -- 3.5 Debug build, ensure this continues to work REM -- 3.5 Debug build, ensure this continues to work
%WINDIR%\Microsoft.NET\Framework\v3.5\MSBuild.exe build.csproj /t:Rebuild /p:BuildConfiguration=Debug /p:Platform="Any CPU" /p:BuildTools=3.5 /toolsversion:3.5" %WINDIR%\Microsoft.NET\Framework\v3.5\MSBuild.exe build.csproj /t:Rebuild /p:BuildConfiguration=Debug /p:Platform="Any CPU" /p:BuildTools=3.5 /toolsversion:3.5"
IF ERRORLEVEL 1 GOTO ERROR IF ERRORLEVEL 1 GOTO ERROR
REM -- 4.0 Debug build REM -- 4.0 Debug build
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Debug /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Debug /p:Platform="Any CPU"
IF ERRORLEVEL 1 GOTO ERROR IF ERRORLEVEL 1 GOTO ERROR
REM -- 4.0 Release build REM -- 4.0 Release build
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Release /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Release /p:Platform="Any CPU"
IF ERRORLEVEL 1 GOTO ERROR IF ERRORLEVEL 1 GOTO ERROR
IF EXIST "%ProgramFiles%\MSBuild\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" GOTO SILVERLIGHT IF EXIST "%ProgramFiles%\MSBuild\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" GOTO SILVERLIGHT
IF EXIST "%ProgramFiles(x86)%\MSBuild\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" GOTO SILVERLIGHT IF EXIST "%ProgramFiles(x86)%\MSBuild\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" GOTO SILVERLIGHT
ECHO Unable to locate %ProgramFiles(x86)%\MSBuild\Microsoft\Silverlight\v2.0 ECHO Unable to locate %ProgramFiles(x86)%\MSBuild\Microsoft\Silverlight\v2.0
GOTO ERROR GOTO ERROR
:SILVERLIGHT :SILVERLIGHT
REM -- 4.0 Debug_Silverlight2 build REM -- 4.0 Debug_Silverlight2 build
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Debug_Silverlight2 /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Debug_Silverlight2 /p:Platform="Any CPU"
IF ERRORLEVEL 1 GOTO ERROR IF ERRORLEVEL 1 GOTO ERROR
REM -- 4.0 Release_Silverlight2 build REM -- 4.0 Release_Silverlight2 build
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Release_Silverlight2 /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild /p:BuildConfiguration=Release_Silverlight2 /p:Platform="Any CPU"
IF ERRORLEVEL 1 GOTO ERROR IF ERRORLEVEL 1 GOTO ERROR
GOTO END GOTO END
:ERROR :ERROR
CD %PREV_WORKING_DIR% CD %PREV_WORKING_DIR%
PAUSE PAUSE
:END :END
CD %PREV_WORKING_DIR% CD %PREV_WORKING_DIR%
SET PREV_WORKING_DIR= SET PREV_WORKING_DIR=
\ No newline at end of file
@echo off @echo off
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Build /p:BuildConfiguration=Debug_Silverlight2 /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Build /p:BuildConfiguration=Debug_Silverlight2 /p:Platform="Any CPU"
pause pause
\ No newline at end of file
@ECHO OFF @ECHO OFF
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:PrepareOutputDirectory %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:PrepareOutputDirectory
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Debug /p:Platform="Any CPU" %PROTOBUF_KEY_FILE% %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Debug /p:Platform="Any CPU" %PROTOBUF_KEY_FILE%
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Debug_Silverlight2 /p:Platform="Any CPU" %PROTOBUF_KEY_FILE% %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Debug_Silverlight2 /p:Platform="Any CPU" %PROTOBUF_KEY_FILE%
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release /p:Platform="Any CPU" %PROTOBUF_KEY_FILE% %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release /p:Platform="Any CPU" %PROTOBUF_KEY_FILE%
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release_Silverlight2 /p:Platform="Any CPU" %PROTOBUF_KEY_FILE% %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release_Silverlight2 /p:Platform="Any CPU" %PROTOBUF_KEY_FILE%
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:GeneratePackage /p:PackageName=AllBinariesAndSource.zip /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:GeneratePackage /p:PackageName=AllBinariesAndSource.zip /p:Platform="Any CPU"
:END :END
\ No newline at end of file
@ECHO OFF @ECHO OFF
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:PrepareOutputDirectory %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:PrepareOutputDirectory
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release /p:Platform="Any CPU" %PROTOBUF_KEY_FILE% %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release /p:Platform="Any CPU" %PROTOBUF_KEY_FILE%
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release_Silverlight2 /p:Platform="Any CPU" %PROTOBUF_KEY_FILE% %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:Rebuild;PreparePackageComponent /p:BuildConfiguration=Release_Silverlight2 /p:Platform="Any CPU" %PROTOBUF_KEY_FILE%
IF ERRORLEVEL 1 GOTO END IF ERRORLEVEL 1 GOTO END
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:GeneratePackage /p:PackageName=ReleaseBinaries.zip /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:GeneratePackage /p:PackageName=ReleaseBinaries.zip /p:Platform="Any CPU"
:END :END
\ No newline at end of file
@echo off @echo off
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild %~dp0\build.csproj /m /t:RunBenchmarks /p:BuildConfiguration=Release /p:Platform="Any CPU" %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild %~dp0\build.csproj /m /t:RunBenchmarks /p:BuildConfiguration=Release /p:Platform="Any CPU"
pause pause
\ No newline at end of file
@echo off @echo off
SET BUILD_TARGET=%1 SET BUILD_TARGET=%1
SET BUILD_CONFIG=%2 SET BUILD_CONFIG=%2
IF "%BUILD_TARGET%"=="" SET BUILD_TARGET=Rebuild IF "%BUILD_TARGET%"=="" SET BUILD_TARGET=Rebuild
IF "%BUILD_CONFIG%"=="" SET BUILD_CONFIG=Debug IF "%BUILD_CONFIG%"=="" SET BUILD_CONFIG=Debug
CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v3.5\MSBuild.exe build.csproj %3 %4 %5 %6 /t:%BUILD_TARGET% /p:BuildConfiguration=%BUILD_CONFIG% /p:Platform="Any CPU" /p:BuildTools=3.5 /toolsversion:3.5" CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v3.5\MSBuild.exe build.csproj %3 %4 %5 %6 /t:%BUILD_TARGET% /p:BuildConfiguration=%BUILD_CONFIG% /p:Platform="Any CPU" /p:BuildTools=3.5 /toolsversion:3.5"
Protocol Buffers - Google's data interchange format Protocol Buffers - Google's data interchange format
Copyright 2008-2010 Google Inc. All rights reserved. Copyright 2008-2010 Google Inc. All rights reserved.
http://github.com/jskeet/dotnet-protobufs/ http://github.com/jskeet/dotnet-protobufs/
Original C++/Java/Python code: Original C++/Java/Python code:
http://code.google.com/p/protobuf/ http://code.google.com/p/protobuf/
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
met: met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the in the documentation and/or other materials provided with the
distribution. distribution.
* Neither the name of Google Inc. nor the names of its * Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from contributors may be used to endorse or promote products derived from
this software without specific prior written permission. this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Additional options required for C# generation. File from copyright // Additional options required for C# generation. File from copyright
// line onwards is as per original distribution. // line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto"; import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos"; option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasLiteProtoFile"; option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasLiteProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra;
package protobuf_unittest_extra;
option optimize_for = LITE_RUNTIME;
option optimize_for = LITE_RUNTIME;
option java_package = "com.google.protobuf";
option java_package = "com.google.protobuf";
message TestRequiredLite {
required int32 d = 1; message TestRequiredLite {
required ExtraEnum en = 2 [default = DEFAULT]; required int32 d = 1;
} required ExtraEnum en = 2 [default = DEFAULT];
}
enum ExtraEnum {
DEFAULT = 10; enum ExtraEnum {
EXLITE_FOO = 7; DEFAULT = 10;
EXLITE_BAR = 8; EXLITE_FOO = 7;
EXLITE_BAZ = 9; EXLITE_BAR = 8;
} EXLITE_BAZ = 9;
}
message TestInteropPersonLite {
required string name = 1; message TestInteropPersonLite {
required int32 id = 2; required string name = 1;
optional string email = 3; required int32 id = 2;
repeated int32 codes = 10 [packed=true]; optional string email = 3;
repeated int32 codes = 10 [packed=true];
enum PhoneType {
MOBILE = 0; enum PhoneType {
HOME = 1; MOBILE = 0;
WORK = 2; HOME = 1;
} WORK = 2;
}
message PhoneNumber {
required string number = 1; message PhoneNumber {
optional PhoneType type = 2 [default = HOME]; required string number = 1;
} optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
repeated PhoneNumber phone = 4;
repeated group Addresses = 5 {
required string address = 1; repeated group Addresses = 5 {
optional string address2 = 2; required string address = 1;
required string city = 3; optional string address2 = 2;
required string state = 4; required string city = 3;
required fixed32 zip = 5; required string state = 4;
} required fixed32 zip = 5;
}
extensions 100 to 199;
} extensions 100 to 199;
}
message TestInteropEmployeeIdLite {
required string number = 1; message TestInteropEmployeeIdLite {
} required string number = 1;
}
extend TestInteropPersonLite {
required TestInteropEmployeeIdLite employee_id_lite = 126; extend TestInteropPersonLite {
} required TestInteropEmployeeIdLite employee_id_lite = 126;
}
import "google/protobuf/csharp_options.proto"; import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos"; option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile"; option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra; package protobuf_unittest_extra;
option optimize_for = SPEED; option optimize_for = SPEED;
enum EnumOptions { enum EnumOptions {
ONE = 0; ONE = 0;
TWO = 1; TWO = 1;
THREE = 2; THREE = 2;
} }
message TestXmlChild message TestXmlChild {
{ repeated EnumOptions options = 3;
repeated EnumOptions options = 3; optional bytes binary = 4;
optional bytes binary = 4;
} }
message TestXmlNoFields { message TestXmlNoFields {
} }
message TestXmlRescursive { message TestXmlRescursive {
optional TestXmlRescursive child = 1; optional TestXmlRescursive child = 1;
} }
message TestXmlMessage { message TestXmlMessage {
optional int64 number = 6; optional int64 number = 6;
repeated int32 numbers = 2; repeated int32 numbers = 2;
optional string text = 3; optional string text = 3;
repeated string textlines = 700; repeated string textlines = 700;
optional bool valid = 5; optional bool valid = 5;
optional TestXmlChild child = 1; optional TestXmlChild child = 1;
repeated group Children = 401 repeated group Children = 401 {
{ repeated EnumOptions options = 3;
repeated EnumOptions options = 3; optional bytes binary = 4;
optional bytes binary = 4; }
}
extensions 100 to 199;
extensions 100 to 199;
} }
message TestXmlExtension { message TestXmlExtension {
required int32 number = 1; required int32 number = 1;
} }
extend TestXmlMessage { extend TestXmlMessage {
optional EnumOptions extension_enum = 101; optional EnumOptions extension_enum = 101;
optional string extension_text = 102; optional string extension_text = 102;
......
...@@ -86,3 +86,47 @@ message NumberField { ...@@ -86,3 +86,47 @@ message NumberField {
optional int32 _01 = 1; optional int32 _01 = 1;
} }
// Issue 28: Circular message dependencies result in null defaults for DefaultInstance
message MyMessageAReferenceB {
required MyMessageBReferenceA value = 1;
}
message MyMessageBReferenceA {
required MyMessageAReferenceB value = 1;
}
// issue 19 - negative enum values
enum NegativeEnum {
FiveBelow = -5;
MinusOne = -1;
Zero = 0;
}
message NegativeEnumMessage {
optional NegativeEnum value = 1;
repeated NegativeEnum values = 2;
repeated NegativeEnum packed_values = 3 [packed=true];
}
// Issue 21: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=21
// Decorate fields with [deprecated=true] as [System.Obsolete]
message DeprecatedChild {
}
enum DeprecatedEnum {
one = 1;
}
message DeprecatedFieldsMessage {
optional int32 PrimitiveValue = 1 [deprecated = true];
repeated int32 PrimitiveArray = 2 [deprecated = true];
optional DeprecatedChild MessageValue = 3 [deprecated = true];
repeated DeprecatedChild MessageArray = 4 [deprecated = true];
optional DeprecatedEnum EnumValue = 5 [deprecated = true];
repeated DeprecatedEnum EnumArray = 6 [deprecated = true];
}
\ No newline at end of file
...@@ -38,6 +38,9 @@ message CSharpFileOptions { ...@@ -38,6 +38,9 @@ message CSharpFileOptions {
// Generate attributes indicating non-CLS-compliance // Generate attributes indicating non-CLS-compliance
optional bool cls_compliance = 8 [default = true]; optional bool cls_compliance = 8 [default = true];
// Generate messages/builders with the [Serializable] attribute
optional bool add_serializable = 9 [default = false];
// The extension that should be appended to the umbrella_classname when creating files. // The extension that should be appended to the umbrella_classname when creating files.
optional string file_extension = 221 [default = ".cs"]; optional string file_extension = 221 [default = ".cs"];
......
<NotepadPlus>
<!--
Defines syntax highlighting for Notepad++.
1. Install Notepad++ from http://notepad-plus-plus.org
2. Open Notepad++, from the View menu, select "User-Defined Dialog..."
3. Click the "Import..." button and select this file
4. Restart Notepad++
5. Open and edit any *.proto file
-->
<UserLang name="Proto Buffer" ext="proto">
<Settings>
<Global caseIgnored="no" />
<TreatAsSymbol comment="no" commentLine="yes" />
<Prefix words1="no" words2="no" words3="no" words4="yes" />
</Settings>
<KeywordLists>
<Keywords name="Delimiters">[00]00</Keywords>
<Keywords name="Folder+">{</Keywords>
<Keywords name="Folder-">}</Keywords>
<Keywords name="Operators">=</Keywords>
<Keywords name="Comment"> 1option 1package 1import 2; 0//</Keywords>
<Keywords name="Words1">message enum service extend</Keywords>
<Keywords name="Words2">required optional repeated extensions to rpc returns</Keywords>
<Keywords name="Words3">double float int32 int64 uint32 uint64 sint32 sint64 fixed32 fixed64 sfixed32 sfixed64 bool string bytes</Keywords>
<Keywords name="Words4"></Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="FOLDEROPEN" styleID="12" fgColor="000000" bgColor="FFFFFF" fontStyle="1" />
<WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="000000" bgColor="FFFFFF" fontStyle="1" />
<WordsStyle name="KEYWORD1" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="KEYWORD2" styleID="6" fgColor="0080C0" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="KEYWORD3" styleID="7" fgColor="0000FF" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="KEYWORD4" styleID="8" fgColor="008040" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="COMMENT LINE" styleID="2" fgColor="949494" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="NUMBER" styleID="4" fgColor="FF0000" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="OPERATOR" styleID="10" fgColor="000000" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="DELIMINER1" styleID="14" fgColor="800080" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="DELIMINER2" styleID="15" fgColor="808080" bgColor="FFFFFF" fontStyle="0" />
<WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontStyle="0" />
</Styles>
</UserLang>
</NotepadPlus>
Welcome to the C# port of Google Protocol Buffers, written by Jon Skeet
(skeet@pobox.com) based on the work of many talented people.
For more information about this port, visit its homepage:
http://protobuf-csharp-port.googlecode.com
For more information about Protocol Buffers in general, visit the
project page for the C++, Java and Python project:
http://protobuf.googlecode.com
Release 0.9.1
-------------
Fix to release 0.9:
- Include protos in binary download
- Fix issue 10: incorrect encoding of packed fields when serialized
size wasn't fetched first
Release 0.9
-----------
Due to popular demand, I have built a version of the binaries to put
on the web site. Currently these are set at assembly version 0.9,
and an assembly file version of 0.9. This should be seen as a mark
of the readiness of the release process more than the stability of
the code. As far as I'm aware, the code itself is perfectly fine: I
certainly have plans for more features particularly around making
code generation simpler, but you should feel confident about the
parsing and serialization of messages produced with this version of
the library. Of course, if you do find any problems, *please* report
them at the web site.
Currently the downloadable release is built with the snk file which
is in the open source library. I am considering having a privately
held key so that you can check that you're building against a
"blessed" release - feedback on this (and any other aspect of the
release process) is very welcome.
This diff is collapsed.
...@@ -52,7 +52,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -52,7 +52,7 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
FileDescriptorProto first = new FileDescriptorProto.Builder {Name = "First"}.Build(); FileDescriptorProto first = new FileDescriptorProto.Builder {Name = "First"}.Build();
FileDescriptorProto second = new FileDescriptorProto.Builder {Name = "Second"}.Build(); FileDescriptorProto second = new FileDescriptorProto.Builder {Name = "Second"}.Build();
FileDescriptorSet set = new FileDescriptorSet {FileList = {first, second}}; FileDescriptorSet set = new FileDescriptorSet.Builder { FileList = { first, second } }.Build();
IList<FileDescriptor> converted = Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set); IList<FileDescriptor> converted = Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set);
Assert.AreEqual(2, converted.Count); Assert.AreEqual(2, converted.Count);
...@@ -68,7 +68,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -68,7 +68,7 @@ namespace Google.ProtocolBuffers.ProtoGen
FileDescriptorProto first = FileDescriptorProto first =
new FileDescriptorProto.Builder {Name = "First", DependencyList = {"Second"}}.Build(); new FileDescriptorProto.Builder {Name = "First", DependencyList = {"Second"}}.Build();
FileDescriptorProto second = new FileDescriptorProto.Builder {Name = "Second"}.Build(); FileDescriptorProto second = new FileDescriptorProto.Builder {Name = "Second"}.Build();
FileDescriptorSet set = new FileDescriptorSet {FileList = {first, second}}; FileDescriptorSet set = new FileDescriptorSet.Builder { FileList = { first, second } }.Build();
IList<FileDescriptor> converted = Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set); IList<FileDescriptor> converted = Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set);
Assert.AreEqual(2, converted.Count); Assert.AreEqual(2, converted.Count);
Assert.AreEqual("First", converted[0].Name); Assert.AreEqual("First", converted[0].Name);
...@@ -84,7 +84,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -84,7 +84,7 @@ namespace Google.ProtocolBuffers.ProtoGen
FileDescriptorProto first = new FileDescriptorProto.Builder {Name = "First"}.Build(); FileDescriptorProto first = new FileDescriptorProto.Builder {Name = "First"}.Build();
FileDescriptorProto second = FileDescriptorProto second =
new FileDescriptorProto.Builder {Name = "Second", DependencyList = {"First"}}.Build(); new FileDescriptorProto.Builder {Name = "Second", DependencyList = {"First"}}.Build();
FileDescriptorSet set = new FileDescriptorSet {FileList = {first, second}}; FileDescriptorSet set = new FileDescriptorSet.Builder { FileList = { first, second } }.Build();
IList<FileDescriptor> converted = Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set); IList<FileDescriptor> converted = Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set);
Assert.AreEqual(2, converted.Count); Assert.AreEqual(2, converted.Count);
Assert.AreEqual("First", converted[0].Name); Assert.AreEqual("First", converted[0].Name);
...@@ -101,7 +101,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -101,7 +101,7 @@ namespace Google.ProtocolBuffers.ProtoGen
new FileDescriptorProto.Builder {Name = "First", DependencyList = {"Second"}}.Build(); new FileDescriptorProto.Builder {Name = "First", DependencyList = {"Second"}}.Build();
FileDescriptorProto second = FileDescriptorProto second =
new FileDescriptorProto.Builder {Name = "Second", DependencyList = {"First"}}.Build(); new FileDescriptorProto.Builder {Name = "Second", DependencyList = {"First"}}.Build();
FileDescriptorSet set = new FileDescriptorSet {FileList = {first, second}}; FileDescriptorSet set = new FileDescriptorSet.Builder { FileList = { first, second } }.Build();
try try
{ {
Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set); Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set);
...@@ -118,7 +118,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -118,7 +118,7 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
FileDescriptorProto first = FileDescriptorProto first =
new FileDescriptorProto.Builder {Name = "First", DependencyList = {"Second"}}.Build(); new FileDescriptorProto.Builder {Name = "First", DependencyList = {"Second"}}.Build();
FileDescriptorSet set = new FileDescriptorSet {FileList = {first}}; FileDescriptorSet set = new FileDescriptorSet.Builder { FileList = { first } }.Build();
try try
{ {
Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set); Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set);
...@@ -135,7 +135,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -135,7 +135,7 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
FileDescriptorProto first = FileDescriptorProto first =
new FileDescriptorProto.Builder {Name = "First", DependencyList = {"First"}}.Build(); new FileDescriptorProto.Builder {Name = "First", DependencyList = {"First"}}.Build();
FileDescriptorSet set = new FileDescriptorSet {FileList = {first}}; FileDescriptorSet set = new FileDescriptorSet.Builder { FileList = { first } }.Build();
try try
{ {
Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set); Generator.ConvertDescriptors(CSharpFileOptions.DefaultInstance, set);
......
...@@ -49,10 +49,11 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -49,10 +49,11 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
writer.WriteLine("private bool has{0};", PropertyName); writer.WriteLine("private bool has{0};", PropertyName);
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue); writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue);
AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName); writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return has{0}; }}", PropertyName); writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName); writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name); writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -60,21 +61,25 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -60,21 +61,25 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateBuilderMembers(TextGenerator writer) public void GenerateBuilderMembers(TextGenerator writer)
{ {
AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName); writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName); writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName); writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName); writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName); writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
......
...@@ -251,6 +251,12 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -251,6 +251,12 @@ namespace Google.ProtocolBuffers.ProtoGen
} }
} }
protected void AddPublicMemberAttributes(TextGenerator writer)
{
AddDeprecatedFlag(writer);
AddClsComplianceCheck(writer);
}
protected void AddClsComplianceCheck(TextGenerator writer) protected void AddClsComplianceCheck(TextGenerator writer)
{ {
if (!Descriptor.IsCLSCompliant && Descriptor.File.CSharpOptions.ClsCompliance) if (!Descriptor.IsCLSCompliant && Descriptor.File.CSharpOptions.ClsCompliance)
...@@ -259,6 +265,19 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -259,6 +265,19 @@ namespace Google.ProtocolBuffers.ProtoGen
} }
} }
protected bool IsObsolete { get { return Descriptor.Options.Deprecated; } }
/// <summary>
/// Writes [global::System.ObsoleteAttribute()] if the member is obsolete
/// </summary>
protected void AddDeprecatedFlag(TextGenerator writer)
{
if (IsObsolete)
{
writer.WriteLine("[global::System.ObsoleteAttribute()]");
}
}
/// <summary> /// <summary>
/// For encodings with fixed sizes, returns that size in bytes. Otherwise /// For encodings with fixed sizes, returns that size in bytes. Otherwise
/// returns -1. TODO(jonskeet): Make this less ugly. /// returns -1. TODO(jonskeet): Make this less ugly.
......
...@@ -48,38 +48,48 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -48,38 +48,48 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateMembers(TextGenerator writer) public void GenerateMembers(TextGenerator writer)
{ {
writer.WriteLine("private bool has{0};", PropertyName); writer.WriteLine("private bool has{0};", PropertyName);
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue); writer.WriteLine("private {0} {1}_;", TypeName, Name);
AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName); writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return has{0}; }}", PropertyName); writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName); writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name); writer.WriteLine(" get {{ return {0}_ ?? {1}; }}", Name, DefaultValue);
writer.WriteLine("}"); writer.WriteLine("}");
} }
public void GenerateBuilderMembers(TextGenerator writer) public void GenerateBuilderMembers(TextGenerator writer)
{ {
AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName); writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName); writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName); writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName); writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName); writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue"); AddNullCheck(writer, "builderForValue");
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name); writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" if (result.has{0} &&", PropertyName); writer.WriteLine(" if (result.has{0} &&", PropertyName);
writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue); writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue);
writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name, writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name,
...@@ -90,9 +100,11 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -90,9 +100,11 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" result.{0}_ = null;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
...@@ -165,9 +165,13 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -165,9 +165,13 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
return SourceGenerators.CreateFieldGenerator(fieldDescriptor, FieldOrdinal(fieldDescriptor)); return SourceGenerators.CreateFieldGenerator(fieldDescriptor, FieldOrdinal(fieldDescriptor));
} }
public void Generate(TextGenerator writer) public void Generate(TextGenerator writer)
{ {
if (Descriptor.File.CSharpOptions.AddSerializable)
{
writer.WriteLine("[global::System.SerializableAttribute()]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]"); writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]", writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
...@@ -177,8 +181,9 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -177,8 +181,9 @@ namespace Google.ProtocolBuffers.ProtoGen
Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated", Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated",
RuntimeSuffix); RuntimeSuffix);
writer.Indent(); writer.Indent();
writer.WriteLine("private {0}() {{ }}", ClassName);
// Must call BuildPartial() to make sure all lists are made read-only // Must call BuildPartial() to make sure all lists are made read-only
writer.WriteLine("private static readonly {0} defaultInstance = new Builder().BuildPartial();", ClassName); writer.WriteLine("private static readonly {0} defaultInstance = new {0}().MakeReadOnly();", ClassName);
if (OptimizeSpeed) if (OptimizeSpeed)
{ {
...@@ -199,7 +204,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -199,7 +204,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("public override {0} DefaultInstanceForType {{", ClassName); writer.WriteLine("public override {0} DefaultInstanceForType {{", ClassName);
writer.WriteLine(" get { return defaultInstance; }"); writer.WriteLine(" get { return DefaultInstance; }");
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("protected override {0} ThisMessage {{", ClassName); writer.WriteLine("protected override {0} ThisMessage {{", ClassName);
...@@ -547,13 +552,28 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -547,13 +552,28 @@ namespace Google.ProtocolBuffers.ProtoGen
private void GenerateBuilder(TextGenerator writer) private void GenerateBuilder(TextGenerator writer)
{ {
writer.WriteLine("private {0} MakeReadOnly() {{", ClassName);
writer.Indent();
foreach (FieldDescriptor field in Descriptor.Fields)
{
CreateFieldGenerator(field).GenerateBuildingCode(writer);
}
writer.WriteLine("return this;");
writer.Outdent();
writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("public static Builder CreateBuilder() { return new Builder(); }"); writer.WriteLine("public static Builder CreateBuilder() { return new Builder(); }");
writer.WriteLine("public override Builder ToBuilder() { return CreateBuilder(this); }"); writer.WriteLine("public override Builder ToBuilder() { return CreateBuilder(this); }");
writer.WriteLine("public override Builder CreateBuilderForType() { return new Builder(); }"); writer.WriteLine("public override Builder CreateBuilderForType() { return new Builder(); }");
writer.WriteLine("public static Builder CreateBuilder({0} prototype) {{", ClassName); writer.WriteLine("public static Builder CreateBuilder({0} prototype) {{", ClassName);
writer.WriteLine(" return (Builder) new Builder().MergeFrom(prototype);"); writer.WriteLine(" return new Builder(prototype);");
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
if (Descriptor.File.CSharpOptions.AddSerializable)
{
writer.WriteLine("[global::System.SerializableAttribute()]");
}
writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]"); writer.WriteLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]", writer.WriteLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
...@@ -582,21 +602,52 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -582,21 +602,52 @@ namespace Google.ProtocolBuffers.ProtoGen
private void GenerateCommonBuilderMethods(TextGenerator writer) private void GenerateCommonBuilderMethods(TextGenerator writer)
{ {
writer.WriteLine("public Builder() {{}}", ClassAccessLevel); //default constructor
writer.WriteLine("public Builder() {");
//Durring static initialization of message, DefaultInstance is expected to return null.
writer.WriteLine(" result = DefaultInstance;");
writer.WriteLine(" resultIsReadOnly = true;");
writer.WriteLine("}");
//clone constructor
writer.WriteLine("internal Builder({0} cloneFrom) {{", ClassName);
writer.WriteLine(" result = cloneFrom;");
writer.WriteLine(" resultIsReadOnly = true;");
writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("private bool resultIsReadOnly;");
writer.WriteLine("private {0} result;", ClassName);
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("{0} result = new {0}();", ClassName); writer.WriteLine("private {0} PrepareBuilder() {{", ClassName);
writer.WriteLine(" if (resultIsReadOnly) {");
writer.WriteLine(" {0} original = result;", ClassName);
writer.WriteLine(" result = new {0}();", ClassName);
writer.WriteLine(" resultIsReadOnly = false;");
writer.WriteLine(" MergeFrom(original);");
writer.WriteLine(" }");
writer.WriteLine(" return result;");
writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("public override bool IsInitialized {");
writer.WriteLine(" get { return result.IsInitialized; }");
writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("protected override {0} MessageBeingBuilt {{", ClassName); writer.WriteLine("protected override {0} MessageBeingBuilt {{", ClassName);
writer.WriteLine(" get { return result; }"); writer.WriteLine(" get { return PrepareBuilder(); }");
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
//Not actually expecting that DefaultInstance would ever be null here; however, we will ensure it does not break
writer.WriteLine("public override Builder Clear() {"); writer.WriteLine("public override Builder Clear() {");
writer.WriteLine(" result = new {0}();", ClassName); writer.WriteLine(" result = DefaultInstance;", ClassName);
writer.WriteLine(" resultIsReadOnly = true;");
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("public override Builder Clone() {"); writer.WriteLine("public override Builder Clone() {");
writer.WriteLine(" return new Builder().MergeFrom(result);"); writer.WriteLine(" if (resultIsReadOnly) {");
writer.WriteLine(" return new Builder(result);");
writer.WriteLine(" } else {");
writer.WriteLine(" return new Builder().MergeFrom(result);");
writer.WriteLine(" }");
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
if (!UseLiteRuntime) if (!UseLiteRuntime)
...@@ -613,17 +664,11 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -613,17 +664,11 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("public override {0} BuildPartial() {{", ClassName); writer.WriteLine("public override {0} BuildPartial() {{", ClassName);
writer.Indent(); writer.Indent();
writer.WriteLine("if (result == null) {"); writer.WriteLine("if (resultIsReadOnly) {");
writer.WriteLine( writer.WriteLine(" return result;");
" throw new global::System.InvalidOperationException(\"build() has already been called on this Builder\");");
writer.WriteLine("}"); writer.WriteLine("}");
foreach (FieldDescriptor field in Descriptor.Fields) writer.WriteLine("resultIsReadOnly = true;");
{ writer.WriteLine("return result.MakeReadOnly();");
CreateFieldGenerator(field).GenerateBuildingCode(writer);
}
writer.WriteLine("{0} returnMe = result;", ClassName);
writer.WriteLine("result = null;");
writer.WriteLine("return returnMe;");
writer.Outdent(); writer.Outdent();
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
...@@ -644,6 +689,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -644,6 +689,7 @@ namespace Google.ProtocolBuffers.ProtoGen
// fields are set so we can skip the merge. // fields are set so we can skip the merge.
writer.Indent(); writer.Indent();
writer.WriteLine("if (other == {0}.DefaultInstance) return this;", FullClassName); writer.WriteLine("if (other == {0}.DefaultInstance) return this;", FullClassName);
writer.WriteLine("PrepareBuilder();");
foreach (FieldDescriptor field in Descriptor.Fields) foreach (FieldDescriptor field in Descriptor.Fields)
{ {
CreateFieldGenerator(field).GenerateMergingCode(writer); CreateFieldGenerator(field).GenerateMergingCode(writer);
...@@ -676,6 +722,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -676,6 +722,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine( writer.WriteLine(
"public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {"); "public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {");
writer.Indent(); writer.Indent();
writer.WriteLine("PrepareBuilder();");
if (!UseLiteRuntime) if (!UseLiteRuntime)
{ {
writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;"); writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;");
......
...@@ -50,10 +50,11 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -50,10 +50,11 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
writer.WriteLine("private bool has{0};", PropertyName); writer.WriteLine("private bool has{0};", PropertyName);
writer.WriteLine("private {0} {1}_{2};", TypeName, Name, HasDefaultValue ? " = " + DefaultValue : ""); writer.WriteLine("private {0} {1}_{2};", TypeName, Name, HasDefaultValue ? " = " + DefaultValue : "");
AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName); writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return has{0}; }}", PropertyName); writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName); writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name); writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -61,22 +62,26 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -61,22 +62,26 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateBuilderMembers(TextGenerator writer) public void GenerateBuilderMembers(TextGenerator writer)
{ {
AddDeprecatedFlag(writer);
writer.WriteLine("public bool Has{0} {{", PropertyName); writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName); writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName); writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName); writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName); writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
......
...@@ -52,15 +52,18 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -52,15 +52,18 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("private int {0}MemoizedSerializedSize;", Name); writer.WriteLine("private int {0}MemoizedSerializedSize;", Name);
} }
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name); writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
AddDeprecatedFlag(writer);
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName); writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name); writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option. // TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return {0}_.Count; }}", Name); writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName); writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return {0}_[index];", Name); writer.WriteLine(" return {0}_[index];", Name);
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -70,28 +73,39 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -70,28 +73,39 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
// Note: We can return the original list here, because we make it unmodifiable when we build // Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly. // We return it via IPopsicleList so that collection initializers work more pleasantly.
AddDeprecatedFlag(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}_; }}", Name); writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName); writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName); writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return result.Get{0}(index);", PropertyName); writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name); writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(values);", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -100,13 +114,13 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -100,13 +114,13 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateMergingCode(TextGenerator writer) public void GenerateMergingCode(TextGenerator writer)
{ {
writer.WriteLine("if (other.{0}_.Count != 0) {{", Name); writer.WriteLine("if (other.{0}_.Count != 0) {{", Name);
writer.WriteLine(" base.AddRange(other.{0}_, result.{0}_);", Name); writer.WriteLine(" result.{0}_.Add(other.{0}_);", Name);
writer.WriteLine("}"); writer.WriteLine("}");
} }
public void GenerateBuildingCode(TextGenerator writer) public void GenerateBuildingCode(TextGenerator writer)
{ {
writer.WriteLine("result.{0}_.MakeReadOnly();", Name); writer.WriteLine("{0}_.MakeReadOnly();", Name);
} }
public void GenerateParsingCode(TextGenerator writer) public void GenerateParsingCode(TextGenerator writer)
......
...@@ -48,15 +48,18 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -48,15 +48,18 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateMembers(TextGenerator writer) public void GenerateMembers(TextGenerator writer)
{ {
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name); writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
AddDeprecatedFlag(writer);
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName); writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return {0}_; }}", Name); writer.WriteLine(" get {{ return {0}_; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option. // TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return {0}_.Count; }}", Name); writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName); writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return {0}_[index];", Name); writer.WriteLine(" return {0}_[index];", Name);
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -66,42 +69,57 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -66,42 +69,57 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
// Note: We can return the original list here, because we make it unmodifiable when we build // Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly. // We return it via IPopsicleList so that collection initializers work more pleasantly.
AddDeprecatedFlag(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}_; }}", Name); writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName); writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName); writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return result.Get{0}(index);", PropertyName); writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
// Extra overload for builder (just on messages) // Extra overload for builder (just on messages)
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue"); AddNullCheck(writer, "builderForValue");
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name); writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
// Extra overload for builder (just on messages) // Extra overload for builder (just on messages)
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue"); AddNullCheck(writer, "builderForValue");
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name); writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name); writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(values);", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -110,13 +128,13 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -110,13 +128,13 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateMergingCode(TextGenerator writer) public void GenerateMergingCode(TextGenerator writer)
{ {
writer.WriteLine("if (other.{0}_.Count != 0) {{", Name); writer.WriteLine("if (other.{0}_.Count != 0) {{", Name);
writer.WriteLine(" base.AddRange(other.{0}_, result.{0}_);", Name); writer.WriteLine(" result.{0}_.Add(other.{0}_);", Name);
writer.WriteLine("}"); writer.WriteLine("}");
} }
public void GenerateBuildingCode(TextGenerator writer) public void GenerateBuildingCode(TextGenerator writer)
{ {
writer.WriteLine("result.{0}_.MakeReadOnly();", Name); writer.WriteLine("{0}_.MakeReadOnly();", Name);
} }
public void GenerateParsingCode(TextGenerator writer) public void GenerateParsingCode(TextGenerator writer)
......
...@@ -52,17 +52,18 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -52,17 +52,18 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("private int {0}MemoizedSerializedSize;", Name); writer.WriteLine("private int {0}MemoizedSerializedSize;", Name);
} }
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name); writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName); writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name); writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option. // TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return {0}_.Count; }}", Name); writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName); writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return {0}_[index];", Name); writer.WriteLine(" return {0}_[index];", Name);
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -72,35 +73,41 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -72,35 +73,41 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
// Note: We can return the original list here, because we make it unmodifiable when we build // Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly. // We return it via IPopsicleList so that collection initializers work more pleasantly.
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}_; }}", Name); writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name);
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName); writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName); writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
writer.WriteLine(" return result.Get{0}(index);", PropertyName); writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddClsComplianceCheck(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name); writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(values);", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -109,13 +116,13 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -109,13 +116,13 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateMergingCode(TextGenerator writer) public void GenerateMergingCode(TextGenerator writer)
{ {
writer.WriteLine("if (other.{0}_.Count != 0) {{", Name); writer.WriteLine("if (other.{0}_.Count != 0) {{", Name);
writer.WriteLine(" base.AddRange(other.{0}_, result.{0}_);", Name); writer.WriteLine(" result.{0}_.Add(other.{0}_);", Name);
writer.WriteLine("}"); writer.WriteLine("}");
} }
public void GenerateBuildingCode(TextGenerator writer) public void GenerateBuildingCode(TextGenerator writer)
{ {
writer.WriteLine("result.{0}_.MakeReadOnly();", Name); writer.WriteLine("{0}_.MakeReadOnly();", Name);
} }
public void GenerateParsingCode(TextGenerator writer) public void GenerateParsingCode(TextGenerator writer)
......
...@@ -138,8 +138,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -138,8 +138,8 @@ namespace Google.ProtocolBuffers.ProtoGen
private void WriteIntroduction(TextGenerator writer) private void WriteIntroduction(TextGenerator writer)
{ {
writer.WriteLine("// Generated by {0}. DO NOT EDIT!", this.GetType().Assembly.FullName); writer.WriteLine("// Generated by {0}. DO NOT EDIT!", this.GetType().Assembly.FullName);
writer.WriteLine("#pragma warning disable 1591"); writer.WriteLine("#pragma warning disable 1591, 0612");
writer.WriteLine("#region Designer generated code"); writer.WriteLine("#region Designer generated code");
writer.WriteLine(); writer.WriteLine();
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework; using NUnit.Framework;
...@@ -532,5 +533,77 @@ namespace Google.ProtocolBuffers ...@@ -532,5 +533,77 @@ namespace Google.ProtocolBuffers
return base.Read(buffer, offset, Math.Min(count, blockSize)); return base.Read(buffer, offset, Math.Min(count, blockSize));
} }
} }
enum TestNegEnum { None = 0, Value = -2 }
[Test]
public void TestNegativeEnum()
{
byte[] bytes = new byte[10] { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 };
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
object unk;
TestNegEnum val = TestNegEnum.None;
Assert.IsTrue(input.ReadEnum(ref val, out unk));
Assert.IsTrue(input.IsAtEnd);
Assert.AreEqual(TestNegEnum.Value, val);
}
[Test]
public void TestNegativeEnumPackedArray()
{
int arraySize = 1 + (10 * 5);
int msgSize = 1 + 1 + arraySize;
byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WritePackedInt32Array(8, "", arraySize, new int[] { 0, -1, -2, -3, -4, -5 });
Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
Assert.IsTrue(input.ReadTag(out tag, out name));
List<TestNegEnum> values = new List<TestNegEnum>();
ICollection<object> unk;
input.ReadEnumArray(tag, name, values, out unk);
Assert.AreEqual(2, values.Count);
Assert.AreEqual(TestNegEnum.None, values[0]);
Assert.AreEqual(TestNegEnum.Value, values[1]);
Assert.IsNotNull(unk);
Assert.AreEqual(4, unk.Count);
}
[Test]
public void TestNegativeEnumArray()
{
int arraySize = 1 + 1 + (11 * 5);
int msgSize = arraySize;
byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteInt32Array(8, "", new int[] { 0, -1, -2, -3, -4, -5 });
Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
Assert.IsTrue(input.ReadTag(out tag, out name));
List<TestNegEnum> values = new List<TestNegEnum>();
ICollection<object> unk;
input.ReadEnumArray(tag, name, values, out unk);
Assert.AreEqual(2, values.Count);
Assert.AreEqual(TestNegEnum.None, values[0]);
Assert.AreEqual(TestNegEnum.Value, values[1]);
Assert.IsNotNull(unk);
Assert.AreEqual(4, unk.Count);
}
} }
} }
\ No newline at end of file
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#endregion #endregion
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework; using NUnit.Framework;
...@@ -288,5 +290,82 @@ namespace Google.ProtocolBuffers ...@@ -288,5 +290,82 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(-75123905439571256L, Assert.AreEqual(-75123905439571256L,
CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L))); CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
} }
[Test]
public void TestNegativeEnumNoTag()
{
Assert.AreEqual(10, CodedOutputStream.ComputeInt32SizeNoTag(-2));
Assert.AreEqual(10, CodedOutputStream.ComputeEnumSizeNoTag(-2));
byte[] bytes = new byte[10];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnumNoTag(-2);
Assert.AreEqual(0, output.SpaceLeft);
Assert.AreEqual("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
}
[Test]
public void TestNegativeEnumWithTag()
{
Assert.AreEqual(11, CodedOutputStream.ComputeInt32Size(8, -2));
Assert.AreEqual(11, CodedOutputStream.ComputeEnumSize(8, -2));
byte[] bytes = new byte[11];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnum(8, "", -2, -2);
Assert.AreEqual(0, output.SpaceLeft);
//fyi, 0x40 == 0x08 << 3 + 0, field num + wire format shift
Assert.AreEqual("40-FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
}
[Test]
public void TestNegativeEnumArrayPacked()
{
int arraySize = 1 + (10 * 5);
int msgSize = 1 + 1 + arraySize;
byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WritePackedEnumArray(8, "", arraySize, new int[] { 0, -1, -2, -3, -4, -5 });
Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
Assert.IsTrue(input.ReadTag(out tag, out name));
List<int> values = new List<int>();
input.ReadInt32Array(tag, name, values);
Assert.AreEqual(6, values.Count);
for (int i = 0; i > -6; i--)
Assert.AreEqual(i, values[Math.Abs(i)]);
}
[Test]
public void TestNegativeEnumArray()
{
int arraySize = 1 + 1 + (11 * 5);
int msgSize = arraySize;
byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnumArray(8, "", new int[] { 0, -1, -2, -3, -4, -5 });
Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag;
string name;
Assert.IsTrue(input.ReadTag(out tag, out name));
List<int> values = new List<int>();
input.ReadInt32Array(tag, name, values);
Assert.AreEqual(6, values.Count);
for (int i = 0; i > -6; i--)
Assert.AreEqual(i, values[Math.Abs(i)]);
}
} }
} }
\ No newline at end of file
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
internal delegate void Action(); internal delegate void Action();
...@@ -94,6 +95,64 @@ namespace Google.ProtocolBuffers.Collections ...@@ -94,6 +95,64 @@ namespace Google.ProtocolBuffers.Collections
Assert.IsFalse(list.IsReadOnly); Assert.IsFalse(list.IsReadOnly);
} }
[Test]
public void DoesNotAddNullEnumerable()
{
PopsicleList<string> list = new PopsicleList<string>();
try
{
list.Add((IEnumerable<string>)null);
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
}
[Test]
public void DoesNotAddRangeWithNull()
{
PopsicleList<string> list = new PopsicleList<string>();
try
{
list.Add(new[] { "a", "b", null });
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
}
[Test]
public void DoesNotAddNull()
{
PopsicleList<string> list = new PopsicleList<string>();
try
{
list.Add((string)null);
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
}
[Test]
public void DoesNotSetNull()
{
PopsicleList<string> list = new PopsicleList<string>();
list.Add("a");
try
{
list[0] = null;
}
catch (ArgumentNullException)
{ return; }
Assert.Fail("List should not allow nulls.");
}
private static void AssertNotSupported(Action action) private static void AssertNotSupported(Action action)
{ {
try try
......
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using NUnit.Framework;
using UnitTest.Issues.TestProtos;
namespace Google.ProtocolBuffers
{
[TestFixture]
public class DeprecatedMemberTest
{
private static void AssertIsDeprecated(ICustomAttributeProvider member)
{
Assert.IsNotNull(member);
Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
}
[Test]
public void TestDepreatedPrimitiveValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasPrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("HasPrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("PrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetPrimitiveValue"));
}
[Test]
public void TestDepreatedPrimitiveArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveArrayList"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("PrimitiveArrayCount"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetMethod("GetPrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("PrimitiveArrayList"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("PrimitiveArrayCount"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("GetPrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetPrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddPrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangePrimitiveArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearPrimitiveArray"));
}
[Test]
public void TestDepreatedMessageValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasMessageValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("HasMessageValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("MessageValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("MergeMessageValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearMessageValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageValue", new[] { typeof(DeprecatedChild.Builder) }));
}
[Test]
public void TestDepreatedMessageArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageArrayList"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("MessageArrayCount"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetMethod("GetMessageArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("MessageArrayList"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("MessageArrayCount"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("GetMessageArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageArray", new[] { typeof(int), typeof(DeprecatedChild) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetMessageArray", new[] { typeof(int), typeof(DeprecatedChild.Builder) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddMessageArray", new[] { typeof(DeprecatedChild) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddMessageArray", new[] { typeof(DeprecatedChild.Builder) }));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangeMessageArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearMessageArray"));
}
[Test]
public void TestDepreatedEnumValue()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("HasEnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("HasEnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("EnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearEnumValue"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetEnumValue"));
}
[Test]
public void TestDepreatedEnumArray()
{
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumArrayList"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetProperty("EnumArrayCount"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage).GetMethod("GetEnumArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("EnumArrayList"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetProperty("EnumArrayCount"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("GetEnumArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("SetEnumArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddEnumArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("AddRangeEnumArray"));
AssertIsDeprecated(typeof(DeprecatedFieldsMessage.Builder).GetMethod("ClearEnumArray"));
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
[TestFixture]
public class GeneratedBuilderTest
{
class OneTimeEnumerator<T> : IEnumerable<T>
{
readonly T _item;
bool _enumerated;
public OneTimeEnumerator(T item)
{
_item = item;
}
public IEnumerator<T> GetEnumerator()
{
Assert.IsFalse(_enumerated, "The collection {0} has already been enumerated", GetType());
_enumerated = true;
yield return _item;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{ return GetEnumerator(); }
}
[Test]
public void DoesNotEnumerateTwiceForMessageList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignMessage(
new OneTimeEnumerator<ForeignMessage>(
ForeignMessage.DefaultInstance));
}
[Test]
public void DoesNotEnumerateTwiceForPrimitiveList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedInt32(new OneTimeEnumerator<int>(1));
}
[Test]
public void DoesNotEnumerateTwiceForStringList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedString(new OneTimeEnumerator<string>("test"));
}
[Test]
public void DoesNotEnumerateTwiceForEnumList()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator<ForeignEnum>(ForeignEnum.FOREIGN_BAR));
}
private static void AssertThrows<T>(System.Threading.ThreadStart method) where T : Exception
{
try
{
method();
}
catch (Exception error)
{
if (error is T)
return;
throw;
}
Assert.Fail("Expected exception of type " + typeof(T));
}
[Test]
public void DoesNotAddNullToMessageListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>(
() => b.AddRangeRepeatedForeignMessage(new ForeignMessage[] { null })
);
}
[Test]
public void DoesNotAddNullToMessageListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>(
() => b.AddRepeatedForeignMessage((ForeignMessage)null)
);
}
[Test]
public void DoesNotAddNullToMessageListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance);
AssertThrows<ArgumentNullException>(
() => b.SetRepeatedForeignMessage(0, (ForeignMessage)null)
);
}
[Test]
public void DoesNotAddNullToStringListByAddRange()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>(
() => b.AddRangeRepeatedString(new String[] { null })
);
}
[Test]
public void DoesNotAddNullToStringListByAdd()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
AssertThrows<ArgumentNullException>(
() => b.AddRepeatedString(null)
);
}
[Test]
public void DoesNotAddNullToStringListBySet()
{
TestAllTypes.Builder b = new TestAllTypes.Builder();
b.AddRepeatedString("one");
AssertThrows<ArgumentNullException>(
() => b.SetRepeatedString(0, null)
);
}
}
}
...@@ -111,22 +111,6 @@ namespace Google.ProtocolBuffers ...@@ -111,22 +111,6 @@ namespace Google.ProtocolBuffers
} }
} }
[Test]
public void DoubleBuildError()
{
TestAllTypes.Builder builder = new TestAllTypes.Builder();
builder.Build();
try
{
builder.Build();
Assert.Fail("Should have thrown exception.");
}
catch (InvalidOperationException)
{
// Success.
}
}
[Test] [Test]
public void DefaultInstance() public void DefaultInstance()
{ {
......
...@@ -45,9 +45,7 @@ ...@@ -45,9 +45,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\Google.ProtocolBuffers.Test.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
...@@ -57,9 +55,7 @@ ...@@ -57,9 +55,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release\Google.ProtocolBuffers.Test.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
...@@ -94,10 +90,12 @@ ...@@ -94,10 +90,12 @@
<Compile Include="Compatibility\XmlCompatibilityTests.cs" /> <Compile Include="Compatibility\XmlCompatibilityTests.cs" />
<Compile Include="TestReaderForUrlEncoded.cs" /> <Compile Include="TestReaderForUrlEncoded.cs" />
<Compile Include="CSharpOptionsTest.cs" /> <Compile Include="CSharpOptionsTest.cs" />
<Compile Include="DeprecatedMemberTest.cs" />
<Compile Include="DescriptorsTest.cs" /> <Compile Include="DescriptorsTest.cs" />
<Compile Include="Descriptors\MessageDescriptorTest.cs" /> <Compile Include="Descriptors\MessageDescriptorTest.cs" />
<Compile Include="DynamicMessageTest.cs" /> <Compile Include="DynamicMessageTest.cs" />
<Compile Include="ExtendableMessageTest.cs" /> <Compile Include="ExtendableMessageTest.cs" />
<Compile Include="GeneratedBuilderTest.cs" />
<Compile Include="GeneratedMessageTest.cs" /> <Compile Include="GeneratedMessageTest.cs" />
<Compile Include="MessageStreamIteratorTest.cs" /> <Compile Include="MessageStreamIteratorTest.cs" />
<Compile Include="MessageStreamWriterTest.cs" /> <Compile Include="MessageStreamWriterTest.cs" />
...@@ -106,7 +104,10 @@ ...@@ -106,7 +104,10 @@
<Compile Include="NameHelpersTest.cs" /> <Compile Include="NameHelpersTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReflectionTester.cs" /> <Compile Include="ReflectionTester.cs" />
<Compile Include="ReusableBuilderTest.cs" />
<Compile Include="SerializableTest.cs" />
<Compile Include="ServiceTest.cs" /> <Compile Include="ServiceTest.cs" />
<Compile Include="TestCornerCases.cs" />
<Compile Include="TestMimeMessageFormats.cs" /> <Compile Include="TestMimeMessageFormats.cs" />
<Compile Include="TestProtos\UnitTestCSharpOptionsProtoFile.cs" /> <Compile Include="TestProtos\UnitTestCSharpOptionsProtoFile.cs" />
<Compile Include="TestProtos\UnitTestCustomOptionsProtoFile.cs" /> <Compile Include="TestProtos\UnitTestCustomOptionsProtoFile.cs" />
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Google.ProtocolBuffers.Collections;
using NUnit.Framework;
using Google.ProtocolBuffers.TestProtos;
using Google.ProtocolBuffers.Serialization;
using UnitTest.Issues.TestProtos;
namespace Google.ProtocolBuffers
{
[TestFixture]
public class ReusableBuilderTest
{
[Test, Description("Issue 28: Circular message dependencies result in null defaults for DefaultInstance")]
public void EnsureStaticCicularReference()
{
MyMessageAReferenceB ab = MyMessageAReferenceB.DefaultInstance;
Assert.IsNotNull(ab);
Assert.IsNotNull(ab.Value);
MyMessageBReferenceA ba = MyMessageBReferenceA.DefaultInstance;
Assert.IsNotNull(ba);
Assert.IsNotNull(ba.Value);
}
[Test]
public void TestModifyDefaultInstance()
{
//verify that the default instance has correctly been marked as read-only
Assert.AreEqual(typeof(PopsicleList<bool>), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType());
PopsicleList<bool> list = (PopsicleList<bool>)TestAllTypes.DefaultInstance.RepeatedBoolList;
Assert.IsTrue(list.IsReadOnly);
}
[Test]
public void TestUnmodifiedDefaultInstance()
{
//Simply calling ToBuilder().Build() no longer creates a copy of the message
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void BuildMultipleWithoutChange()
{
//Calling Build() or BuildPartial() does not require a copy of the message
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
builder.SetDefaultBool(true);
TestAllTypes first = builder.BuildPartial();
//Still the same instance?
Assert.IsTrue(ReferenceEquals(first, builder.Build()));
//Still the same instance?
Assert.IsTrue(ReferenceEquals(first, builder.BuildPartial().ToBuilder().Build()));
}
[Test]
public void MergeFromDefaultInstance()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.MergeFrom(TestAllTypes.DefaultInstance);
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void BuildNewBuilderIsDefaultInstance()
{
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, new TestAllTypes.Builder().Build()));
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().Build()));
//last test, if you clear a builder it reverts to default instance
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance,
TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build()));
}
[Test]
public void BuildModifyAndRebuild()
{
TestAllTypes.Builder b1 = new TestAllTypes.Builder();
b1.SetDefaultInt32(1);
b1.AddRepeatedInt32(2);
b1.SetOptionalForeignMessage(ForeignMessage.DefaultInstance);
TestAllTypes m1 = b1.Build();
b1.SetDefaultInt32(5);
b1.AddRepeatedInt32(6);
b1.SetOptionalForeignMessage(b1.OptionalForeignMessage.ToBuilder().SetC(7));
TestAllTypes m2 = b1.Build();
Assert.AreEqual("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", m1.ToJson());
Assert.AreEqual("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", m2.ToJson());
}
[Test]
public void CloneOnChangePrimitive()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetDefaultBool(true);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnAddRepeatedBool()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.AddRepeatedBool(true);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnGetRepeatedBoolList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedBoolList);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnChangeMessage()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetOptionalForeignMessage(new ForeignMessage.Builder());
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnClearMessage()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.ClearOptionalForeignMessage();
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnGetRepeatedForeignMessageList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignMessageList);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnChangeEnumValue()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
builder.SetOptionalForeignEnum(ForeignEnum.FOREIGN_BAR);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
[Test]
public void CloneOnGetRepeatedForeignEnumList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignEnumList);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework;
namespace Google.ProtocolBuffers
{
[TestFixture]
public class SerializableTest
{
/// <summary>
/// Just keep it from even compiling if we these objects don't implement the expected interface.
/// </summary>
public static readonly ISerializable CompileTimeCheckSerializableMessage = TestXmlMessage.DefaultInstance;
public static readonly ISerializable CompileTimeCheckSerializableBuilder = new TestXmlMessage.Builder();
[Test]
public void TestPlainMessage()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetValid(true)
.SetText("text")
.AddTextlines("a")
.AddTextlines("b")
.AddTextlines("c")
.SetNumber(0x1010101010)
.AddNumbers(1)
.AddNumbers(2)
.AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder()
.AddOptions(EnumOptions.ONE)
.SetBinary(ByteString.CopyFrom(new byte[1])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.TWO)
.SetBinary(ByteString.CopyFrom(new byte[2])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3])))
.Build();
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, message);
ms.Position = 0;
TestXmlMessage copy = (TestXmlMessage)new BinaryFormatter().Deserialize(ms);
Assert.AreEqual(message, copy);
}
[Test]
public void TestMessageWithExtensions()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetValid(true)
.SetText("text")
.AddTextlines("a")
.AddTextlines("b")
.AddTextlines("c")
.SetNumber(0x1010101010)
.AddNumbers(1)
.AddNumbers(2)
.AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder()
.AddOptions(EnumOptions.ONE)
.SetBinary(ByteString.CopyFrom(new byte[1])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.TWO)
.SetBinary(ByteString.CopyFrom(new byte[2])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE)
.Build();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, message);
ms.Position = 0;
//you need to provide the extension registry as context to the serializer
BinaryFormatter bff = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All, registry));
TestXmlMessage copy = (TestXmlMessage)bff.Deserialize(ms);
// And all extensions will be defined.
Assert.AreEqual(message, copy);
}
[Test]
public void TestPlainBuilder()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
.SetValid(true)
.SetText("text")
.AddTextlines("a")
.AddTextlines("b")
.AddTextlines("c")
.SetNumber(0x1010101010)
.AddNumbers(1)
.AddNumbers(2)
.AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder()
.AddOptions(EnumOptions.ONE)
.SetBinary(ByteString.CopyFrom(new byte[1])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.TWO)
.SetBinary(ByteString.CopyFrom(new byte[2])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3])))
;
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, builder);
ms.Position = 0;
TestXmlMessage.Builder copy = (TestXmlMessage.Builder)new BinaryFormatter().Deserialize(ms);
Assert.AreEqual(builder.Build(), copy.Build());
}
[Test]
public void TestBuilderWithExtensions()
{
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
.SetValid(true)
.SetText("text")
.AddTextlines("a")
.AddTextlines("b")
.AddTextlines("c")
.SetNumber(0x1010101010)
.AddNumbers(1)
.AddNumbers(2)
.AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder()
.AddOptions(EnumOptions.ONE)
.SetBinary(ByteString.CopyFrom(new byte[1])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.TWO)
.SetBinary(ByteString.CopyFrom(new byte[2])))
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE)
;
ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, builder);
ms.Position = 0;
//you need to provide the extension registry as context to the serializer
BinaryFormatter bff = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All, registry));
TestXmlMessage.Builder copy = (TestXmlMessage.Builder)bff.Deserialize(ms);
// And all extensions will be defined.
Assert.AreEqual(builder.Build(), copy.Build());
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using UnitTest.Issues.TestProtos;
namespace Google.ProtocolBuffers
{
[TestFixture]
public class TestCornerCases
{
[Test]
public void TestRoundTripNegativeEnums()
{
NegativeEnumMessage msg = NegativeEnumMessage.CreateBuilder()
.SetValue(NegativeEnum.MinusOne) //11
.AddValues(NegativeEnum.Zero) //2
.AddValues(NegativeEnum.MinusOne) //11
.AddValues(NegativeEnum.FiveBelow) //11
//2
.AddPackedValues(NegativeEnum.Zero) //1
.AddPackedValues(NegativeEnum.MinusOne) //10
.AddPackedValues(NegativeEnum.FiveBelow) //10
.Build();
Assert.AreEqual(58, msg.SerializedSize);
byte[] bytes = new byte[58];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
msg.WriteTo(output);
Assert.AreEqual(0, output.SpaceLeft);
NegativeEnumMessage copy = NegativeEnumMessage.ParseFrom(bytes);
Assert.AreEqual(msg, copy);
}
}
}
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! // Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT!
#pragma warning disable 1591 #pragma warning disable 1591, 0612
#region Designer generated code #region Designer generated code
using pb = global::Google.ProtocolBuffers; using pb = global::Google.ProtocolBuffers;
...@@ -60,7 +60,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -60,7 +60,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class OptionsMessage : pb::GeneratedMessage<OptionsMessage, OptionsMessage.Builder> { public sealed partial class OptionsMessage : pb::GeneratedMessage<OptionsMessage, OptionsMessage.Builder> {
private static readonly OptionsMessage defaultInstance = new Builder().BuildPartial(); private OptionsMessage() { }
private static readonly OptionsMessage defaultInstance = new OptionsMessage().MakeReadOnly();
private static readonly string[] _optionsMessageFieldNames = new string[] { "customized", "normal", "options_message" }; private static readonly string[] _optionsMessageFieldNames = new string[] { "customized", "normal", "options_message" };
private static readonly uint[] _optionsMessageFieldTags = new uint[] { 26, 10, 18 }; private static readonly uint[] _optionsMessageFieldTags = new uint[] { 26, 10, 18 };
public static OptionsMessage DefaultInstance { public static OptionsMessage DefaultInstance {
...@@ -68,7 +69,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -68,7 +69,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override OptionsMessage DefaultInstanceForType { public override OptionsMessage DefaultInstanceForType {
get { return defaultInstance; } get { return DefaultInstance; }
} }
protected override OptionsMessage ThisMessage { protected override OptionsMessage ThisMessage {
...@@ -186,11 +187,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -186,11 +187,15 @@ namespace Google.ProtocolBuffers.TestProtos {
public static OptionsMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public static OptionsMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
} }
private OptionsMessage MakeReadOnly() {
return this;
}
public static Builder CreateBuilder() { return new Builder(); } public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(OptionsMessage prototype) { public static Builder CreateBuilder(OptionsMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -200,21 +205,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -200,21 +205,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } get { return this; }
} }
public Builder() {} public Builder() {
result = DefaultInstance;
resultIsReadOnly = true;
}
internal Builder(OptionsMessage cloneFrom) {
result = cloneFrom;
resultIsReadOnly = true;
}
private bool resultIsReadOnly;
private OptionsMessage result;
private OptionsMessage PrepareBuilder() {
if (resultIsReadOnly) {
OptionsMessage original = result;
result = new OptionsMessage();
resultIsReadOnly = false;
MergeFrom(original);
}
return result;
}
OptionsMessage result = new OptionsMessage(); public override bool IsInitialized {
get { return result.IsInitialized; }
}
protected override OptionsMessage MessageBeingBuilt { protected override OptionsMessage MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new OptionsMessage(); result = DefaultInstance;
resultIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { public override Builder Clone() {
return new Builder().MergeFrom(result); if (resultIsReadOnly) {
return new Builder(result);
} else {
return new Builder().MergeFrom(result);
}
} }
public override pbd::MessageDescriptor DescriptorForType { public override pbd::MessageDescriptor DescriptorForType {
...@@ -226,12 +258,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -226,12 +258,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override OptionsMessage BuildPartial() { public override OptionsMessage BuildPartial() {
if (result == null) { if (resultIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
OptionsMessage returnMe = result; resultIsReadOnly = true;
result = null; return result.MakeReadOnly();
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -245,6 +276,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -245,6 +276,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(OptionsMessage other) { public override Builder MergeFrom(OptionsMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.OptionsMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.OptionsMessage.DefaultInstance) return this;
PrepareBuilder();
if (other.HasNormal) { if (other.HasNormal) {
Normal = other.Normal; Normal = other.Normal;
} }
...@@ -263,6 +295,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -263,6 +295,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -327,11 +360,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -327,11 +360,13 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetNormal(string value) { public Builder SetNormal(string value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasNormal = true; result.hasNormal = true;
result.normal_ = value; result.normal_ = value;
return this; return this;
} }
public Builder ClearNormal() { public Builder ClearNormal() {
PrepareBuilder();
result.hasNormal = false; result.hasNormal = false;
result.normal_ = ""; result.normal_ = "";
return this; return this;
...@@ -346,11 +381,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -346,11 +381,13 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetOptionsMessage_(string value) { public Builder SetOptionsMessage_(string value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasOptionsMessage_ = true; result.hasOptionsMessage_ = true;
result.optionsMessage_ = value; result.optionsMessage_ = value;
return this; return this;
} }
public Builder ClearOptionsMessage_() { public Builder ClearOptionsMessage_() {
PrepareBuilder();
result.hasOptionsMessage_ = false; result.hasOptionsMessage_ = false;
result.optionsMessage_ = ""; result.optionsMessage_ = "";
return this; return this;
...@@ -365,11 +402,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -365,11 +402,13 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetCustomName(string value) { public Builder SetCustomName(string value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasCustomName = true; result.hasCustomName = true;
result.customized_ = value; result.customized_ = value;
return this; return this;
} }
public Builder ClearCustomName() { public Builder ClearCustomName() {
PrepareBuilder();
result.hasCustomName = false; result.hasCustomName = false;
result.customized_ = ""; result.customized_ = "";
return this; return this;
......
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! // Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT!
#pragma warning disable 1591 #pragma warning disable 1591, 0612
#region Designer generated code #region Designer generated code
using pb = global::Google.ProtocolBuffers; using pb = global::Google.ProtocolBuffers;
......
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! // Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT!
#pragma warning disable 1591 #pragma warning disable 1591, 0612
#region Designer generated code #region Designer generated code
using pb = global::Google.ProtocolBuffers; using pb = global::Google.ProtocolBuffers;
......
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! // Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT!
#pragma warning disable 1591 #pragma warning disable 1591, 0612
#region Designer generated code #region Designer generated code
using pb = global::Google.ProtocolBuffers; using pb = global::Google.ProtocolBuffers;
...@@ -43,7 +43,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -43,7 +43,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class ImportMessageLite : pb::GeneratedMessageLite<ImportMessageLite, ImportMessageLite.Builder> { public sealed partial class ImportMessageLite : pb::GeneratedMessageLite<ImportMessageLite, ImportMessageLite.Builder> {
private static readonly ImportMessageLite defaultInstance = new Builder().BuildPartial(); private ImportMessageLite() { }
private static readonly ImportMessageLite defaultInstance = new ImportMessageLite().MakeReadOnly();
private static readonly string[] _importMessageLiteFieldNames = new string[] { "d" }; private static readonly string[] _importMessageLiteFieldNames = new string[] { "d" };
private static readonly uint[] _importMessageLiteFieldTags = new uint[] { 8 }; private static readonly uint[] _importMessageLiteFieldTags = new uint[] { 8 };
public static ImportMessageLite DefaultInstance { public static ImportMessageLite DefaultInstance {
...@@ -51,7 +52,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -51,7 +52,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessageLite DefaultInstanceForType { public override ImportMessageLite DefaultInstanceForType {
get { return defaultInstance; } get { return DefaultInstance; }
} }
protected override ImportMessageLite ThisMessage { protected override ImportMessageLite ThisMessage {
...@@ -146,11 +147,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -146,11 +147,15 @@ namespace Google.ProtocolBuffers.TestProtos {
public static ImportMessageLite ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public static ImportMessageLite ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
} }
private ImportMessageLite MakeReadOnly() {
return this;
}
public static Builder CreateBuilder() { return new Builder(); } public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ImportMessageLite prototype) { public static Builder CreateBuilder(ImportMessageLite prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -160,21 +165,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -160,21 +165,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } get { return this; }
} }
public Builder() {} 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;
}
ImportMessageLite result = new ImportMessageLite(); public override bool IsInitialized {
get { return result.IsInitialized; }
}
protected override ImportMessageLite MessageBeingBuilt { protected override ImportMessageLite MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new ImportMessageLite(); result = DefaultInstance;
resultIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { public override Builder Clone() {
return new Builder().MergeFrom(result); if (resultIsReadOnly) {
return new Builder(result);
} else {
return new Builder().MergeFrom(result);
}
} }
public override ImportMessageLite DefaultInstanceForType { public override ImportMessageLite DefaultInstanceForType {
...@@ -182,12 +214,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -182,12 +214,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessageLite BuildPartial() { public override ImportMessageLite BuildPartial() {
if (result == null) { if (resultIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
ImportMessageLite returnMe = result; resultIsReadOnly = true;
result = null; return result.MakeReadOnly();
return returnMe;
} }
public override Builder MergeFrom(pb::IMessageLite other) { public override Builder MergeFrom(pb::IMessageLite other) {
...@@ -201,6 +232,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -201,6 +232,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(ImportMessageLite other) { public override Builder MergeFrom(ImportMessageLite other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this;
PrepareBuilder();
if (other.HasD) { if (other.HasD) {
D = other.D; D = other.D;
} }
...@@ -212,6 +244,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -212,6 +244,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
...@@ -254,11 +287,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -254,11 +287,13 @@ namespace Google.ProtocolBuffers.TestProtos {
set { SetD(value); } set { SetD(value); }
} }
public Builder SetD(int value) { public Builder SetD(int value) {
PrepareBuilder();
result.hasD = true; result.hasD = true;
result.d_ = value; result.d_ = value;
return this; return this;
} }
public Builder ClearD() { public Builder ClearD() {
PrepareBuilder();
result.hasD = false; result.hasD = false;
result.d_ = 0; result.d_ = 0;
return this; return this;
......
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! // Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT!
#pragma warning disable 1591 #pragma warning disable 1591, 0612
#region Designer generated code #region Designer generated code
using pb = global::Google.ProtocolBuffers; using pb = global::Google.ProtocolBuffers;
...@@ -71,7 +71,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -71,7 +71,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class ImportMessage : pb::GeneratedMessage<ImportMessage, ImportMessage.Builder> { public sealed partial class ImportMessage : pb::GeneratedMessage<ImportMessage, ImportMessage.Builder> {
private static readonly ImportMessage defaultInstance = new Builder().BuildPartial(); private ImportMessage() { }
private static readonly ImportMessage defaultInstance = new ImportMessage().MakeReadOnly();
private static readonly string[] _importMessageFieldNames = new string[] { "d" }; private static readonly string[] _importMessageFieldNames = new string[] { "d" };
private static readonly uint[] _importMessageFieldTags = new uint[] { 8 }; private static readonly uint[] _importMessageFieldTags = new uint[] { 8 };
public static ImportMessage DefaultInstance { public static ImportMessage DefaultInstance {
...@@ -79,7 +80,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -79,7 +80,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessage DefaultInstanceForType { public override ImportMessage DefaultInstanceForType {
get { return defaultInstance; } get { return DefaultInstance; }
} }
protected override ImportMessage ThisMessage { protected override ImportMessage ThisMessage {
...@@ -165,11 +166,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -165,11 +166,15 @@ namespace Google.ProtocolBuffers.TestProtos {
public static ImportMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public static ImportMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
} }
private ImportMessage MakeReadOnly() {
return this;
}
public static Builder CreateBuilder() { return new Builder(); } public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ImportMessage prototype) { public static Builder CreateBuilder(ImportMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -179,21 +184,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -179,21 +184,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } get { return this; }
} }
public Builder() {} 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;
}
ImportMessage result = new ImportMessage(); public override bool IsInitialized {
get { return result.IsInitialized; }
}
protected override ImportMessage MessageBeingBuilt { protected override ImportMessage MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new ImportMessage(); result = DefaultInstance;
resultIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { public override Builder Clone() {
return new Builder().MergeFrom(result); if (resultIsReadOnly) {
return new Builder(result);
} else {
return new Builder().MergeFrom(result);
}
} }
public override pbd::MessageDescriptor DescriptorForType { public override pbd::MessageDescriptor DescriptorForType {
...@@ -205,12 +237,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -205,12 +237,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessage BuildPartial() { public override ImportMessage BuildPartial() {
if (result == null) { if (resultIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
ImportMessage returnMe = result; resultIsReadOnly = true;
result = null; return result.MakeReadOnly();
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -224,6 +255,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -224,6 +255,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(ImportMessage other) { public override Builder MergeFrom(ImportMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this;
PrepareBuilder();
if (other.HasD) { if (other.HasD) {
D = other.D; D = other.D;
} }
...@@ -236,6 +268,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -236,6 +268,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -291,11 +324,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -291,11 +324,13 @@ namespace Google.ProtocolBuffers.TestProtos {
set { SetD(value); } set { SetD(value); }
} }
public Builder SetD(int value) { public Builder SetD(int value) {
PrepareBuilder();
result.hasD = true; result.hasD = true;
result.d_ = value; result.d_ = value;
return this; return this;
} }
public Builder ClearD() { public Builder ClearD() {
PrepareBuilder();
result.hasD = false; result.hasD = false;
result.d_ = 0; result.d_ = 0;
return this; return this;
......
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! // Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT!
#pragma warning disable 1591 #pragma warning disable 1591, 0612
#region Designer generated code #region Designer generated code
using pb = global::Google.ProtocolBuffers; using pb = global::Google.ProtocolBuffers;
...@@ -81,7 +81,8 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -81,7 +81,8 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class TestMessage : pb::ExtendableMessage<TestMessage, TestMessage.Builder> { public sealed partial class TestMessage : pb::ExtendableMessage<TestMessage, TestMessage.Builder> {
private static readonly TestMessage defaultInstance = new Builder().BuildPartial(); private TestMessage() { }
private static readonly TestMessage defaultInstance = new TestMessage().MakeReadOnly();
private static readonly string[] _testMessageFieldNames = new string[] { "a" }; private static readonly string[] _testMessageFieldNames = new string[] { "a" };
private static readonly uint[] _testMessageFieldTags = new uint[] { 8 }; private static readonly uint[] _testMessageFieldTags = new uint[] { 8 };
public static TestMessage DefaultInstance { public static TestMessage DefaultInstance {
...@@ -89,7 +90,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -89,7 +90,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
} }
public override TestMessage DefaultInstanceForType { public override TestMessage DefaultInstanceForType {
get { return defaultInstance; } get { return DefaultInstance; }
} }
protected override TestMessage ThisMessage { protected override TestMessage ThisMessage {
...@@ -179,11 +180,15 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -179,11 +180,15 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public static TestMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public static TestMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
} }
private TestMessage MakeReadOnly() {
return this;
}
public static Builder CreateBuilder() { return new Builder(); } public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(TestMessage prototype) { public static Builder CreateBuilder(TestMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -193,21 +198,48 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -193,21 +198,48 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } get { return this; }
} }
public Builder() {} public Builder() {
result = DefaultInstance;
resultIsReadOnly = true;
}
internal Builder(TestMessage cloneFrom) {
result = cloneFrom;
resultIsReadOnly = true;
}
private bool resultIsReadOnly;
private TestMessage result;
private TestMessage PrepareBuilder() {
if (resultIsReadOnly) {
TestMessage original = result;
result = new TestMessage();
resultIsReadOnly = false;
MergeFrom(original);
}
return result;
}
TestMessage result = new TestMessage(); public override bool IsInitialized {
get { return result.IsInitialized; }
}
protected override TestMessage MessageBeingBuilt { protected override TestMessage MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new TestMessage(); result = DefaultInstance;
resultIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { public override Builder Clone() {
return new Builder().MergeFrom(result); if (resultIsReadOnly) {
return new Builder(result);
} else {
return new Builder().MergeFrom(result);
}
} }
public override pbd::MessageDescriptor DescriptorForType { public override pbd::MessageDescriptor DescriptorForType {
...@@ -219,12 +251,11 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -219,12 +251,11 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
} }
public override TestMessage BuildPartial() { public override TestMessage BuildPartial() {
if (result == null) { if (resultIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
TestMessage returnMe = result; resultIsReadOnly = true;
result = null; return result.MakeReadOnly();
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -238,6 +269,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -238,6 +269,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public override Builder MergeFrom(TestMessage other) { public override Builder MergeFrom(TestMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.NoGenericService.TestMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.NoGenericService.TestMessage.DefaultInstance) return this;
PrepareBuilder();
if (other.HasA) { if (other.HasA) {
A = other.A; A = other.A;
} }
...@@ -251,6 +283,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -251,6 +283,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -306,11 +339,13 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -306,11 +339,13 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
set { SetA(value); } set { SetA(value); }
} }
public Builder SetA(int value) { public Builder SetA(int value) {
PrepareBuilder();
result.hasA = true; result.hasA = true;
result.a_ = value; result.a_ = value;
return this; return this;
} }
public Builder ClearA() { public Builder ClearA() {
PrepareBuilder();
result.hasA = false; result.hasA = false;
result.a_ = 0; result.a_ = 0;
return this; return this;
......
...@@ -44,7 +44,7 @@ namespace Google.ProtocolBuffers ...@@ -44,7 +44,7 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// Implementation of the non-generic IMessage interface as far as possible. /// Implementation of the non-generic IMessage interface as far as possible.
/// </summary> /// </summary>
public abstract class AbstractBuilder<TMessage, TBuilder> : AbstractBuilderLite<TMessage, TBuilder>, public abstract partial class AbstractBuilder<TMessage, TBuilder> : AbstractBuilderLite<TMessage, TBuilder>,
IBuilder<TMessage, TBuilder> IBuilder<TMessage, TBuilder>
where TMessage : AbstractMessage<TMessage, TBuilder> where TMessage : AbstractMessage<TMessage, TBuilder>
where TBuilder : AbstractBuilder<TMessage, TBuilder> where TBuilder : AbstractBuilder<TMessage, TBuilder>
......
...@@ -42,7 +42,7 @@ namespace Google.ProtocolBuffers ...@@ -42,7 +42,7 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// Implementation of the non-generic IMessage interface as far as possible. /// Implementation of the non-generic IMessage interface as far as possible.
/// </summary> /// </summary>
public abstract class AbstractBuilderLite<TMessage, TBuilder> : IBuilderLite<TMessage, TBuilder> public abstract partial class AbstractBuilderLite<TMessage, TBuilder> : IBuilderLite<TMessage, TBuilder>
where TMessage : AbstractMessageLite<TMessage, TBuilder> where TMessage : AbstractMessageLite<TMessage, TBuilder>
where TBuilder : AbstractBuilderLite<TMessage, TBuilder> where TBuilder : AbstractBuilderLite<TMessage, TBuilder>
{ {
......
...@@ -46,7 +46,7 @@ namespace Google.ProtocolBuffers ...@@ -46,7 +46,7 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// Implementation of the non-generic IMessage interface as far as possible. /// Implementation of the non-generic IMessage interface as far as possible.
/// </summary> /// </summary>
public abstract class AbstractMessage<TMessage, TBuilder> : AbstractMessageLite<TMessage, TBuilder>, public abstract partial class AbstractMessage<TMessage, TBuilder> : AbstractMessageLite<TMessage, TBuilder>,
IMessage<TMessage, TBuilder> IMessage<TMessage, TBuilder>
where TMessage : AbstractMessage<TMessage, TBuilder> where TMessage : AbstractMessage<TMessage, TBuilder>
where TBuilder : AbstractBuilder<TMessage, TBuilder> where TBuilder : AbstractBuilder<TMessage, TBuilder>
......
...@@ -41,7 +41,7 @@ namespace Google.ProtocolBuffers ...@@ -41,7 +41,7 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// Implementation of the non-generic IMessage interface as far as possible. /// Implementation of the non-generic IMessage interface as far as possible.
/// </summary> /// </summary>
public abstract class AbstractMessageLite<TMessage, TBuilder> : IMessageLite<TMessage, TBuilder> public abstract partial class AbstractMessageLite<TMessage, TBuilder> : IMessageLite<TMessage, TBuilder>
where TMessage : AbstractMessageLite<TMessage, TBuilder> where TMessage : AbstractMessageLite<TMessage, TBuilder>
where TBuilder : AbstractBuilderLite<TMessage, TBuilder> where TBuilder : AbstractBuilderLite<TMessage, TBuilder>
{ {
......
...@@ -202,7 +202,7 @@ namespace Google.ProtocolBuffers ...@@ -202,7 +202,7 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
public static int ComputeEnumSize(int fieldNumber, int value) public static int ComputeEnumSize(int fieldNumber, int value)
{ {
return ComputeTagSize(fieldNumber) + ComputeRawVarint32Size((uint) value); return ComputeTagSize(fieldNumber) + ComputeEnumSizeNoTag(value);
} }
/// <summary> /// <summary>
...@@ -391,7 +391,7 @@ namespace Google.ProtocolBuffers ...@@ -391,7 +391,7 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
public static int ComputeEnumSizeNoTag(int value) public static int ComputeEnumSizeNoTag(int value)
{ {
return ComputeRawVarint32Size((uint) value); return ComputeInt32SizeNoTag(value);
} }
/// <summary> /// <summary>
......
...@@ -388,7 +388,7 @@ namespace Google.ProtocolBuffers ...@@ -388,7 +388,7 @@ namespace Google.ProtocolBuffers
public void WriteEnum(int fieldNumber, string fieldName, int value, object rawValue) public void WriteEnum(int fieldNumber, string fieldName, int value, object rawValue)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawVarint32((uint) value); WriteInt32NoTag(value);
} }
public void WriteSFixed32(int fieldNumber, string fieldName, int value) public void WriteSFixed32(int fieldNumber, string fieldName, int value)
...@@ -663,7 +663,7 @@ namespace Google.ProtocolBuffers ...@@ -663,7 +663,7 @@ namespace Google.ProtocolBuffers
public void WriteEnumNoTag(int value) public void WriteEnumNoTag(int value)
{ {
WriteRawVarint32((uint) value); WriteInt32NoTag(value);
} }
public void WriteSFixed32NoTag(int value) public void WriteSFixed32NoTag(int value)
......
...@@ -42,6 +42,7 @@ namespace Google.ProtocolBuffers.Collections ...@@ -42,6 +42,7 @@ namespace Google.ProtocolBuffers.Collections
/// </summary> /// </summary>
public sealed class PopsicleList<T> : IPopsicleList<T>, ICastArray public sealed class PopsicleList<T> : IPopsicleList<T>, ICastArray
{ {
private static readonly bool CheckForNull = default(T) == null;
private static readonly T[] EmptySet = new T[0]; private static readonly T[] EmptySet = new T[0];
private List<T> items; private List<T> items;
...@@ -65,6 +66,10 @@ namespace Google.ProtocolBuffers.Collections ...@@ -65,6 +66,10 @@ namespace Google.ProtocolBuffers.Collections
public void Insert(int index, T item) public void Insert(int index, T item)
{ {
ValidateModification(); ValidateModification();
if (CheckForNull)
{
ThrowHelper.ThrowIfNull(item);
}
items.Insert(index, item); items.Insert(index, item);
} }
...@@ -87,6 +92,10 @@ namespace Google.ProtocolBuffers.Collections ...@@ -87,6 +92,10 @@ namespace Google.ProtocolBuffers.Collections
set set
{ {
ValidateModification(); ValidateModification();
if (CheckForNull)
{
ThrowHelper.ThrowIfNull(value);
}
items[index] = value; items[index] = value;
} }
} }
...@@ -94,6 +103,10 @@ namespace Google.ProtocolBuffers.Collections ...@@ -94,6 +103,10 @@ namespace Google.ProtocolBuffers.Collections
public void Add(T item) public void Add(T item)
{ {
ValidateModification(); ValidateModification();
if (CheckForNull)
{
ThrowHelper.ThrowIfNull(item);
}
items.Add(item); items.Add(item);
} }
...@@ -145,15 +158,30 @@ namespace Google.ProtocolBuffers.Collections ...@@ -145,15 +158,30 @@ namespace Google.ProtocolBuffers.Collections
public void Add(IEnumerable<T> collection) public void Add(IEnumerable<T> collection)
{ {
if (readOnly) ValidateModification();
ThrowHelper.ThrowIfNull(collection);
if (!CheckForNull || collection is PopsicleList<T>)
{ {
throw new NotSupportedException("List is read-only"); items.AddRange(collection);
} }
if (items == null) else
{ {
items = new List<T>(); // Assumption, it's ok to enumerate collections more than once.
if (collection is ICollection<T>)
{
ThrowHelper.ThrowIfAnyNull(collection);
items.AddRange(collection);
}
else
{
foreach (T item in collection)
{
ThrowHelper.ThrowIfNull(item);
items.Add(item);
}
}
} }
items.AddRange(collection);
} }
private void ValidateModification() private void ValidateModification()
......
This diff is collapsed.
...@@ -44,7 +44,7 @@ namespace Google.ProtocolBuffers ...@@ -44,7 +44,7 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// An implementation of IMessage that can represent arbitrary types, given a MessageaDescriptor. /// An implementation of IMessage that can represent arbitrary types, given a MessageaDescriptor.
/// </summary> /// </summary>
public sealed class DynamicMessage : AbstractMessage<DynamicMessage, DynamicMessage.Builder> public sealed partial class DynamicMessage : AbstractMessage<DynamicMessage, DynamicMessage.Builder>
{ {
private readonly MessageDescriptor type; private readonly MessageDescriptor type;
private readonly FieldSet fields; private readonly FieldSet fields;
...@@ -308,7 +308,7 @@ namespace Google.ProtocolBuffers ...@@ -308,7 +308,7 @@ namespace Google.ProtocolBuffers
/// <summary> /// <summary>
/// Builder for dynamic messages. Instances are created with DynamicMessage.CreateBuilder. /// Builder for dynamic messages. Instances are created with DynamicMessage.CreateBuilder.
/// </summary> /// </summary>
public sealed class Builder : AbstractBuilder<DynamicMessage, Builder> public sealed partial class Builder : AbstractBuilder<DynamicMessage, Builder>
{ {
private readonly MessageDescriptor type; private readonly MessageDescriptor type;
private FieldSet fields; private FieldSet fields;
......
...@@ -40,7 +40,7 @@ using Google.ProtocolBuffers.Descriptors; ...@@ -40,7 +40,7 @@ using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
public abstract class ExtendableBuilder<TMessage, TBuilder> : GeneratedBuilder<TMessage, TBuilder> public abstract partial class ExtendableBuilder<TMessage, TBuilder> : GeneratedBuilder<TMessage, TBuilder>
where TMessage : ExtendableMessage<TMessage, TBuilder> where TMessage : ExtendableMessage<TMessage, TBuilder>
where TBuilder : GeneratedBuilder<TMessage, TBuilder>, new() where TBuilder : GeneratedBuilder<TMessage, TBuilder>, new()
{ {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment