diff --git a/.gitignore b/.gitignore
index b359dea3b91b65df3c03c22f197f86429051b5a3..e17724693c5fb08d95a8188ca739945687e1b3ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -79,8 +79,7 @@ java/target
javanano/target
# Windows native output.
-vsprojects/Debug
-vsprojects/Release
+cmake/build
# NuGet packages: we want the repository configuration, but not the
# packages themselves.
diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake
index 8caa9e9e83ba92ef735ed29003de131df0d50ae3..e9e88af5182c9ca6d61e6203158915a660c5f6b4 100644
--- a/cmake/libprotoc.cmake
+++ b/cmake/libprotoc.cmake
@@ -16,7 +16,6 @@ set(libprotoc_files
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_string_field.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
- ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_extension.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_field_base.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -28,7 +27,6 @@ set(libprotoc_files
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
- ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_writer.cc
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_context.cc
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment.cc
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum.cc
diff --git a/csharp/README.md b/csharp/README.md
index d694828010b188d5e8caf99a70746de4d5562bb4..72f5552168990c5951d27e0c3dd6c8b49070b244 100644
--- a/csharp/README.md
+++ b/csharp/README.md
@@ -1,13 +1,25 @@
-
This directory contains the C# Protocol Buffers runtime library.
+Warning: experimental!
+======================
+
+This code is still under significant churn. Unlike the original port,
+it only supports proto3 (but not *all* of proto3 yet) - there are no
+unknown fields or extensions, for example. protoc will (eventually)
+deliberately fail if it is asked to generate C# code for proto2
+messages other than descriptor.proto, which is still required for
+reflection. (It's currently exposed publicly, but won't be
+eventually.)
+
+Also unlike the original port, the new version embraces mutability -
+there are no builder types. We plan to add "freezing" operations as
+well as cloning, however.
+
Usage
=====
The easiest way to use C# protocol buffers in your project is to use the [Google.ProtocolBuffers NuGet package](http://www.nuget.org/packages/Google.ProtocolBuffers/). This package is the legacy package for C# protocol buffers, but it will work fine with C# code generated by `protoc` if you use proto2 syntax (The API of the runtime library haven't changed so far).
-*WARNING: If you specify `syntax = "proto3";` in your .proto files, the generated code won't necessarily work with the legacy NuGet package. So before we officially add proto3 support, always use `syntax = "proto2";` (the default) in your protos.*
-
We will definitely release a new NuGet package for the runtime library in the future. The new runtime library WILL contain significant semantic, backwardly-incompatible changes in proto handling (mostly because we will be adding proto3 support and we will be using that oportunity to make some design changes). So keep in mind that you will need to regenerate your proto files and switch to a new NuGet package once the new version of runtime library becomes available.
Building
@@ -17,17 +29,6 @@ Open the `src/ProtocolBuffers.sln` solution in Visual Studio. Click "Build solut
Supported Visual Studio versions are VS2013 (update 4) and VS2015. On Linux, you can also use Monodevelop 5.9 (older versions might work fine).
-Proto2 & Proto3
-===============
-
-*WARNING: Only proto2 is supported for now, proto3 is under construction.*
-
-C# protocol buffers are currently under development and you should expect semantic, backward-incompatible changes in the future.
-
-Also, as of now, only proto2 is supported. Proto3 support for C# is currently in progress
-(both design & implementation) and you should not expect any of the proto3 features to work.
-In fact, always use `syntax = "proto2";` in your .proto files for now, unless you are feeling like experimenting.
-
History of C# protobufs
=======================
diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh
index 9e89bf26a9f54a7dcbf83052c276947d55e169a7..60bc28130fc04e6e1567fd862793e082f4b86f58 100755
--- a/csharp/generate_protos.sh
+++ b/csharp/generate_protos.sh
@@ -23,10 +23,10 @@ cd $(dirname $0)/..
# Windows and Unix.
if [ -z "$PROTOC" ]; then
# TODO(jonskeet): Use an array and a for loop instead?
- if [ -x vsprojects/Debug/protoc.exe ]; then
- PROTOC=vsprojects/Debug/protoc.exe
- elif [ -x vsprojects/Release/protoc.exe ]; then
- PROTOC=vsprojects/Release/protoc.exe
+ if [ -x cmake/build/Debug/protoc.exe ]; then
+ PROTOC=cmake/build/Debug/protoc.exe
+ elif [ -x cmake/build/Release/protoc.exe ]; then
+ PROTOC=cmake/build/Release/protoc.exe
elif [ -x src/protoc ]; then
PROTOC=src/protoc
else
@@ -42,52 +42,14 @@ $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers/DescriptorProtos \
src/google/protobuf/descriptor_proto_file.proto
rm src/google/protobuf/descriptor_proto_file.proto
-
-# ProtocolBuffers.Test protos
$PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \
- src/google/protobuf/unittest.proto \
- src/google/protobuf/unittest_custom_options.proto \
- src/google/protobuf/unittest_drop_unknown_fields.proto \
- src/google/protobuf/unittest_enormous_descriptor.proto \
- src/google/protobuf/unittest_import.proto \
- src/google/protobuf/unittest_import_public.proto \
- src/google/protobuf/unittest_mset.proto \
- src/google/protobuf/unittest_optimize_for.proto \
- src/google/protobuf/unittest_no_field_presence.proto \
- src/google/protobuf/unknown_enum_test.proto
+ src/google/protobuf/unittest_proto3.proto \
+ src/google/protobuf/unittest_import_proto3.proto \
+ src/google/protobuf/unittest_import_public_proto3.proto
$PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \
- csharp/protos/extest/unittest_extras_xmltest.proto \
csharp/protos/extest/unittest_issues.proto
-$PROTOC -Ibenchmarks --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \
- benchmarks/google_size.proto \
- benchmarks/google_speed.proto
-
-# ProtocolBuffersLite.Test protos
-$PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffersLite.Test/TestProtos \
- src/google/protobuf/unittest.proto \
- src/google/protobuf/unittest_import.proto \
- src/google/protobuf/unittest_import_lite.proto \
- src/google/protobuf/unittest_import_public.proto \
- src/google/protobuf/unittest_import_public_lite.proto \
- src/google/protobuf/unittest_lite.proto \
- src/google/protobuf/unittest_lite_imports_nonlite.proto
-
-$PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffersLite.Test/TestProtos \
- csharp/protos/extest/unittest_extras_full.proto \
- csharp/protos/extest/unittest_extras_lite.proto
-
-# TODO(jonskeet): Remove fixup; see issue #307
-sed -i -e 's/RepeatedFieldsGenerator\.Group/RepeatedFieldsGenerator.Types.Group/g' \
- csharp/src/ProtocolBuffers.Test/TestProtos/Unittest.cs \
- csharp/src/ProtocolBuffersLite.Test/TestProtos/Unittest.cs \
- csharp/src/ProtocolBuffersLite.Test/TestProtos/UnittestLite.cs
-
-# TODO(jonskeet): Remove fixup
-sed -i -e 's/DescriptorProtos\.Descriptor\./DescriptorProtos.DescriptorProtoFile./g' \
- csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs
-
# AddressBook sample protos
$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
examples/addressbook.proto
diff --git a/csharp/protos/extest/unittest_issues.proto b/csharp/protos/extest/unittest_issues.proto
index 97249dff71c104a996bee06ed325de1d1d867e72..c123acf17a9851668ae30ccc5a0acfe17c1d7cab 100644
--- a/csharp/protos/extest/unittest_issues.proto
+++ b/csharp/protos/extest/unittest_issues.proto
@@ -1,4 +1,4 @@
-syntax = "proto2";
+syntax = "proto3";
// These proto descriptors have at one time been reported as an issue or defect.
// They are kept here to replicate the issue, and continue to verify the fix.
@@ -9,65 +9,6 @@ option csharp_namespace = "UnitTest.Issues.TestProtos";
package unittest_issues;
option optimize_for = SPEED;
-// The following is a representative set of features
-/*
-enum EnumOptions {
- ONE = 0;
- TWO = 1;
- THREE = 2;
-}
-
-message TestBasicChild
-{
- repeated EnumOptions options = 3;
- optional bytes binary = 4;
-}
-
-message TestBasicNoFields {
-}
-
-message TestBasicRescursive {
- optional TestBasicRescursive child = 1;
-}
-
-message TestBasicMessage {
-
- optional int64 number = 6;
- repeated int32 numbers = 2;
- optional string text = 3;
- repeated string textlines = 700;
- optional bool valid = 5;
-
- optional TestBasicChild child = 1;
- repeated group Children = 401
- {
- repeated EnumOptions options = 3;
- optional bytes binary = 4;
- }
-
- extensions 100 to 199;
-}
-
-message TestBasicExtension {
- required int32 number = 1;
-}
-
-extend TestBasicMessage {
- optional EnumOptions extension_enum = 101;
- optional string extension_text = 102;
- repeated int32 extension_number = 103 [packed = true];
- optional TestBasicExtension extension_message = 199;
-}
-
-// Issue for non-qualified type reference in new services generation
-option (google.protobuf.csharp_file_options).service_generator_type = IRPCDISPATCH;
-
-service TestGenericService {
- rpc Foo(TestBasicNoFields) returns (TestBasicMessage);
- rpc Bar(TestBasicNoFields) returns (TestBasicMessage);
-}
-*/
-
// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
// New issue 309: https://github.com/google/protobuf/issues/309
@@ -90,27 +31,17 @@ service TestGenericService {
// 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 {
+ NEGATIVE_ENUM_ZERO = 0;
FiveBelow = -5;
MinusOne = -1;
- Zero = 0;
}
message NegativeEnumMessage {
- optional NegativeEnum value = 1;
- repeated NegativeEnum values = 2;
+ NegativeEnum value = 1;
+ repeated NegativeEnum values = 2 [packed = false];
repeated NegativeEnum packed_values = 3 [packed=true];
}
@@ -121,21 +52,22 @@ message DeprecatedChild {
}
enum DeprecatedEnum {
+ DEPRECATED_ZERO = 0;
one = 1;
}
message DeprecatedFieldsMessage {
- optional int32 PrimitiveValue = 1 [deprecated = true];
+ int32 PrimitiveValue = 1 [deprecated = true];
repeated int32 PrimitiveArray = 2 [deprecated = true];
- optional DeprecatedChild MessageValue = 3 [deprecated = true];
+ DeprecatedChild MessageValue = 3 [deprecated = true];
repeated DeprecatedChild MessageArray = 4 [deprecated = true];
- optional DeprecatedEnum EnumValue = 5 [deprecated = true];
+ DeprecatedEnum EnumValue = 5 [deprecated = true];
repeated DeprecatedEnum EnumArray = 6 [deprecated = true];
}
// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45
message ItemField {
- optional int32 item = 1;
+ int32 item = 1;
}
diff --git a/csharp/src/AddressBook/AddPerson.cs b/csharp/src/AddressBook/AddPerson.cs
index 462b0c5647aa96abda6e04f944784136944705d5..630108cfc6cd1ddd6df323c43699d4d8f08b07eb 100644
--- a/csharp/src/AddressBook/AddPerson.cs
+++ b/csharp/src/AddressBook/AddPerson.cs
@@ -36,6 +36,7 @@
using System;
using System.IO;
+using Google.Protobuf;
namespace Google.ProtocolBuffers.Examples.AddressBook
{
@@ -46,7 +47,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
///
private static Person PromptForAddress(TextReader input, TextWriter output)
{
- Person.Builder person = Person.CreateBuilder();
+ Person person = new Person();
output.Write("Enter person ID: ");
person.Id = int.Parse(input.ReadLine());
@@ -70,8 +71,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
break;
}
- Person.Types.PhoneNumber.Builder phoneNumber =
- Person.Types.PhoneNumber.CreateBuilder().SetNumber(number);
+ Person.Types.PhoneNumber phoneNumber = new Person.Types.PhoneNumber { Number = number };
output.Write("Is this a mobile, home, or work phone? ");
String type = input.ReadLine();
@@ -91,9 +91,9 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
break;
}
- person.AddPhone(phoneNumber);
+ person.Phone.Add(phoneNumber);
}
- return person.Build();
+ return person;
}
///
@@ -108,27 +108,28 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
return -1;
}
- AddressBook.Builder addressBook = AddressBook.CreateBuilder();
+ AddressBook addressBook;
if (File.Exists(args[0]))
{
using (Stream file = File.OpenRead(args[0]))
{
- addressBook.MergeFrom(file);
+ addressBook = AddressBook.Parser.ParseFrom(file);
}
}
else
{
Console.WriteLine("{0}: File not found. Creating a new file.", args[0]);
+ addressBook = new AddressBook();
}
// Add an address.
- addressBook.AddPerson(PromptForAddress(Console.In, Console.Out));
+ addressBook.Person.Add(PromptForAddress(Console.In, Console.Out));
// Write the new address book back to disk.
using (Stream output = File.OpenWrite(args[0]))
{
- addressBook.Build().WriteTo(output);
+ addressBook.WriteTo(output);
}
return 0;
}
diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs
index 58ad28ad5d232324f57e1356297e55e39cccaea7..322f85f7b324312bf0dd9da454f21e7e9f710b96 100644
--- a/csharp/src/AddressBook/Addressbook.cs
+++ b/csharp/src/AddressBook/Addressbook.cs
@@ -3,26 +3,22 @@
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
-using pb = global::Google.ProtocolBuffers;
-using pbc = global::Google.ProtocolBuffers.Collections;
-using pbd = global::Google.ProtocolBuffers.Descriptors;
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbd = global::Google.Protobuf.Descriptors;
using scg = global::System.Collections.Generic;
namespace Google.ProtocolBuffers.Examples.AddressBook {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static partial class Addressbook {
- #region Extension registration
- public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
- }
- #endregion
#region Static variables
internal static pbd::MessageDescriptor internal__static_tutorial_Person__Descriptor;
- internal static pb::FieldAccess.FieldAccessorTable internal__static_tutorial_Person__FieldAccessorTable;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_tutorial_Person__FieldAccessorTable;
internal static pbd::MessageDescriptor internal__static_tutorial_Person_PhoneNumber__Descriptor;
- internal static pb::FieldAccess.FieldAccessorTable internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable;
internal static pbd::MessageDescriptor internal__static_tutorial_AddressBook__Descriptor;
- internal static pb::FieldAccess.FieldAccessorTable internal__static_tutorial_AddressBook__FieldAccessorTable;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_tutorial_AddressBook__FieldAccessorTable;
#endregion
#region Descriptor
public static pbd::FileDescriptor Descriptor {
@@ -46,19 +42,16 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
descriptor = root;
internal__static_tutorial_Person__Descriptor = Descriptor.MessageTypes[0];
internal__static_tutorial_Person__FieldAccessorTable =
- new pb::FieldAccess.FieldAccessorTable(internal__static_tutorial_Person__Descriptor,
+ new pb::FieldAccess.FieldAccessorTable(internal__static_tutorial_Person__Descriptor,
new string[] { "Name", "Id", "Email", "Phone", });
internal__static_tutorial_Person_PhoneNumber__Descriptor = internal__static_tutorial_Person__Descriptor.NestedTypes[0];
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable =
- new pb::FieldAccess.FieldAccessorTable(internal__static_tutorial_Person_PhoneNumber__Descriptor,
+ new pb::FieldAccess.FieldAccessorTable(internal__static_tutorial_Person_PhoneNumber__Descriptor,
new string[] { "Number", "Type", });
internal__static_tutorial_AddressBook__Descriptor = Descriptor.MessageTypes[1];
internal__static_tutorial_AddressBook__FieldAccessorTable =
- new pb::FieldAccess.FieldAccessorTable(internal__static_tutorial_AddressBook__Descriptor,
+ new pb::FieldAccess.FieldAccessorTable(internal__static_tutorial_AddressBook__Descriptor,
new string[] { "Person", });
- pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
- RegisterAllExtensions(registry);
- return registry;
};
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
new pbd::FileDescriptor[] {
@@ -69,1086 +62,383 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
}
#region Messages
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public sealed partial class Person : pb::GeneratedMessage {
- private Person() { }
- private static readonly Person defaultInstance = new Person().MakeReadOnly();
- private static readonly string[] _personFieldNames = new string[] { "email", "id", "name", "phone" };
- private static readonly uint[] _personFieldTags = new uint[] { 26, 16, 10, 34 };
- public static Person DefaultInstance {
- get { return defaultInstance; }
- }
-
- public override Person DefaultInstanceForType {
- get { return DefaultInstance; }
- }
-
- protected override Person ThisMessage {
- get { return this; }
- }
+ public sealed partial class Person : pb::IMessage, global::System.IEquatable {
+ private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Person());
+ public static pb::MessageParser Parser { get { return _parser; } }
+ private static readonly string[] _fieldNames = new string[] { "email", "id", "name", "phone" };
+ private static readonly uint[] _fieldTags = new uint[] { 26, 16, 10, 34 };
public static pbd::MessageDescriptor Descriptor {
get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_Person__Descriptor; }
}
- protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ public pb::FieldAccess.FieldAccessorTable Fields {
get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_Person__FieldAccessorTable; }
}
- #region Nested types
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public static partial class Types {
- public enum PhoneType {
- MOBILE = 0,
- HOME = 1,
- WORK = 2,
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public sealed partial class PhoneNumber : pb::GeneratedMessage {
- private PhoneNumber() { }
- private static readonly PhoneNumber defaultInstance = new PhoneNumber().MakeReadOnly();
- private static readonly string[] _phoneNumberFieldNames = new string[] { "number", "type" };
- private static readonly uint[] _phoneNumberFieldTags = new uint[] { 10, 16 };
- public static PhoneNumber DefaultInstance {
- get { return defaultInstance; }
- }
-
- public override PhoneNumber DefaultInstanceForType {
- get { return DefaultInstance; }
- }
-
- protected override PhoneNumber ThisMessage {
- get { return this; }
- }
-
- public static pbd::MessageDescriptor Descriptor {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_Person_PhoneNumber__Descriptor; }
- }
-
- protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable; }
- }
-
- public const int NumberFieldNumber = 1;
- private bool hasNumber;
- private string number_ = "";
- public bool HasNumber {
- get { return hasNumber; }
- }
- public string Number {
- get { return number_; }
- }
-
- public const int TypeFieldNumber = 2;
- private bool hasType;
- private global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType type_ = global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME;
- public bool HasType {
- get { return hasType; }
- }
- public global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType Type {
- get { return type_; }
- }
-
- public override bool IsInitialized {
- get {
- if (!hasNumber) return false;
- return true;
- }
- }
-
- public override void WriteTo(pb::ICodedOutputStream output) {
- CalcSerializedSize();
- string[] field_names = _phoneNumberFieldNames;
- if (hasNumber) {
- output.WriteString(1, field_names[0], Number);
- }
- if (hasType) {
- output.WriteEnum(2, field_names[1], (int) Type, Type);
- }
- UnknownFields.WriteTo(output);
- }
-
- private int memoizedSerializedSize = -1;
- public override int SerializedSize {
- get {
- int size = memoizedSerializedSize;
- if (size != -1) return size;
- return CalcSerializedSize();
- }
- }
-
- private int CalcSerializedSize() {
- int size = memoizedSerializedSize;
- if (size != -1) return size;
-
- size = 0;
- if (hasNumber) {
- size += pb::CodedOutputStream.ComputeStringSize(1, Number);
- }
- if (hasType) {
- size += pb::CodedOutputStream.ComputeEnumSize(2, (int) Type);
- }
- size += UnknownFields.SerializedSize;
- memoizedSerializedSize = size;
- return size;
- }
- public static PhoneNumber ParseFrom(pb::ByteString data) {
- return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
- }
- public static PhoneNumber ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
- }
- public static PhoneNumber ParseFrom(byte[] data) {
- return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
- }
- public static PhoneNumber ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
- }
- public static PhoneNumber ParseFrom(global::System.IO.Stream input) {
- return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
- }
- public static PhoneNumber ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
- }
- public static PhoneNumber ParseDelimitedFrom(global::System.IO.Stream input) {
- return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
- }
- public static PhoneNumber ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
- return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
- }
- public static PhoneNumber ParseFrom(pb::ICodedInputStream input) {
- return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
- }
- public static PhoneNumber ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
- }
- private PhoneNumber MakeReadOnly() {
- return this;
- }
-
- public static Builder CreateBuilder() { return new Builder(); }
- public override Builder ToBuilder() { return CreateBuilder(this); }
- public override Builder CreateBuilderForType() { return new Builder(); }
- public static Builder CreateBuilder(PhoneNumber prototype) {
- return new Builder(prototype);
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public sealed partial class Builder : pb::GeneratedBuilder {
- protected override Builder ThisBuilder {
- get { return this; }
- }
- public Builder() {
- result = DefaultInstance;
- resultIsReadOnly = true;
- }
- internal Builder(PhoneNumber cloneFrom) {
- result = cloneFrom;
- resultIsReadOnly = true;
- }
-
- private bool resultIsReadOnly;
- private PhoneNumber result;
-
- private PhoneNumber PrepareBuilder() {
- if (resultIsReadOnly) {
- PhoneNumber original = result;
- result = new PhoneNumber();
- resultIsReadOnly = false;
- MergeFrom(original);
- }
- return result;
- }
-
- public override bool IsInitialized {
- get { return result.IsInitialized; }
- }
-
- protected override PhoneNumber MessageBeingBuilt {
- get { return PrepareBuilder(); }
- }
-
- public override Builder Clear() {
- result = DefaultInstance;
- resultIsReadOnly = true;
- return this;
- }
-
- public override Builder Clone() {
- if (resultIsReadOnly) {
- return new Builder(result);
- } else {
- return new Builder().MergeFrom(result);
- }
- }
-
- public override pbd::MessageDescriptor DescriptorForType {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Descriptor; }
- }
-
- public override PhoneNumber DefaultInstanceForType {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.DefaultInstance; }
- }
-
- public override PhoneNumber BuildPartial() {
- if (resultIsReadOnly) {
- return result;
- }
- resultIsReadOnly = true;
- return result.MakeReadOnly();
- }
-
- public override Builder MergeFrom(pb::IMessage other) {
- if (other is PhoneNumber) {
- return MergeFrom((PhoneNumber) other);
- } else {
- base.MergeFrom(other);
- return this;
- }
- }
-
- public override Builder MergeFrom(PhoneNumber other) {
- if (other == global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.DefaultInstance) return this;
- PrepareBuilder();
- if (other.HasNumber) {
- Number = other.Number;
- }
- if (other.HasType) {
- Type = other.Type;
- }
- this.MergeUnknownFields(other.UnknownFields);
- return this;
- }
-
- public override Builder MergeFrom(pb::ICodedInputStream input) {
- return MergeFrom(input, pb::ExtensionRegistry.Empty);
- }
-
- public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
- PrepareBuilder();
- pb::UnknownFieldSet.Builder unknownFields = null;
- uint tag;
- string field_name;
- while (input.ReadTag(out tag, out field_name)) {
- if(tag == 0 && field_name != null) {
- int field_ordinal = global::System.Array.BinarySearch(_phoneNumberFieldNames, field_name, global::System.StringComparer.Ordinal);
- if(field_ordinal >= 0)
- tag = _phoneNumberFieldTags[field_ordinal];
- else {
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
- }
- ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
- continue;
- }
- }
- switch (tag) {
- case 0: {
- throw pb::InvalidProtocolBufferException.InvalidTag();
- }
- default: {
- if (pb::WireFormat.IsEndGroupTag(tag)) {
- if (unknownFields != null) {
- this.UnknownFields = unknownFields.Build();
- }
- return this;
- }
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
- }
- ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
- break;
- }
- case 10: {
- result.hasNumber = input.ReadString(ref result.number_);
- break;
- }
- case 16: {
- object unknown;
- if(input.ReadEnum(ref result.type_, out unknown)) {
- result.hasType = true;
- } else if(unknown is int) {
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
- }
- unknownFields.MergeVarintField(2, (ulong)(int)unknown);
- }
- break;
- }
- }
- }
-
- if (unknownFields != null) {
- this.UnknownFields = unknownFields.Build();
- }
- return this;
- }
-
-
- public bool HasNumber {
- get { return result.hasNumber; }
- }
- public string Number {
- get { return result.Number; }
- set { SetNumber(value); }
- }
- public Builder SetNumber(string value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.hasNumber = true;
- result.number_ = value;
- return this;
- }
- public Builder ClearNumber() {
- PrepareBuilder();
- result.hasNumber = false;
- result.number_ = "";
- return this;
- }
-
- public bool HasType {
- get { return result.hasType; }
- }
- public global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType Type {
- get { return result.Type; }
- set { SetType(value); }
- }
- public Builder SetType(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType value) {
- PrepareBuilder();
- result.hasType = true;
- result.type_ = value;
- return this;
- }
- public Builder ClearType() {
- PrepareBuilder();
- result.hasType = false;
- result.type_ = global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME;
- return this;
- }
- }
- static PhoneNumber() {
- object.ReferenceEquals(global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.Descriptor, null);
- }
- }
-
+ public Person() { }
+ public Person(Person other) {
+ MergeFrom(other);
}
- #endregion
-
public const int NameFieldNumber = 1;
- private bool hasName;
private string name_ = "";
- public bool HasName {
- get { return hasName; }
- }
public string Name {
get { return name_; }
+ set { name_ = value ?? ""; }
}
+
public const int IdFieldNumber = 2;
- private bool hasId;
private int id_;
- public bool HasId {
- get { return hasId; }
- }
public int Id {
get { return id_; }
+ set { id_ = value; }
}
+
public const int EmailFieldNumber = 3;
- private bool hasEmail;
private string email_ = "";
- public bool HasEmail {
- get { return hasEmail; }
- }
public string Email {
get { return email_; }
+ set { email_ = value ?? ""; }
}
+
public const int PhoneFieldNumber = 4;
- private pbc::PopsicleList phone_ = new pbc::PopsicleList();
- public scg::IList PhoneList {
+ private readonly pbc::RepeatedField phone_ = new pbc::RepeatedField();
+ public pbc::RepeatedField Phone {
get { return phone_; }
}
- public int PhoneCount {
- get { return phone_.Count; }
- }
- public global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber GetPhone(int index) {
- return phone_[index];
+
+ public override bool Equals(object other) {
+ return Equals(other as Person);
}
- public override bool IsInitialized {
- get {
- if (!hasName) return false;
- if (!hasId) return false;
- foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber element in PhoneList) {
- if (!element.IsInitialized) return false;
- }
+ public bool Equals(Person other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
return true;
}
+ if (Name != other.Name) return false;
+ if (Id != other.Id) return false;
+ if (Email != other.Email) return false;
+ if(!phone_.Equals(other.phone_)) return false;
+ return true;
+ }
+
+ public override int GetHashCode() {
+ int hash = 0;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Id != 0) hash ^= Id.GetHashCode();
+ if (Email.Length != 0) hash ^= Email.GetHashCode();
+ hash ^= phone_.GetHashCode();
+ return hash;
}
- public override void WriteTo(pb::ICodedOutputStream output) {
- CalcSerializedSize();
- string[] field_names = _personFieldNames;
- if (hasName) {
- output.WriteString(1, field_names[2], Name);
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
}
- if (hasId) {
- output.WriteInt32(2, field_names[1], Id);
+ if (Id != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Id);
}
- if (hasEmail) {
- output.WriteString(3, field_names[0], Email);
+ if (Email.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(Email);
}
if (phone_.Count > 0) {
- output.WriteMessageArray(4, field_names[3], phone_);
+ output.WriteMessageArray(4, phone_);
}
- UnknownFields.WriteTo(output);
}
- private int memoizedSerializedSize = -1;
- public override int SerializedSize {
- get {
- int size = memoizedSerializedSize;
- if (size != -1) return size;
- return CalcSerializedSize();
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
- }
-
- private int CalcSerializedSize() {
- int size = memoizedSerializedSize;
- if (size != -1) return size;
-
- size = 0;
- if (hasName) {
- size += pb::CodedOutputStream.ComputeStringSize(1, Name);
+ if (Id != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Id);
}
- if (hasId) {
- size += pb::CodedOutputStream.ComputeInt32Size(2, Id);
+ if (Email.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Email);
}
- if (hasEmail) {
- size += pb::CodedOutputStream.ComputeStringSize(3, Email);
- }
- foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber element in PhoneList) {
- size += pb::CodedOutputStream.ComputeMessageSize(4, element);
+ if (phone_.Count > 0) {
+ foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber element in phone_) {
+ size += pb::CodedOutputStream.ComputeMessageSize(element);
+ }
+ size += 1 * phone_.Count;
}
- size += UnknownFields.SerializedSize;
- memoizedSerializedSize = size;
return size;
}
- public static Person ParseFrom(pb::ByteString data) {
- return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
- }
- public static Person ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
- }
- public static Person ParseFrom(byte[] data) {
- return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
- }
- public static Person ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
- }
- public static Person ParseFrom(global::System.IO.Stream input) {
- return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
- }
- public static Person ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
- }
- public static Person ParseDelimitedFrom(global::System.IO.Stream input) {
- return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
- }
- public static Person ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
- return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
- }
- public static Person ParseFrom(pb::ICodedInputStream input) {
- return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
- }
- public static Person ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
- }
- private Person MakeReadOnly() {
- phone_.MakeReadOnly();
- return this;
+ public void MergeFrom(Person other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Id != 0) {
+ Id = other.Id;
+ }
+ if (other.Email.Length != 0) {
+ Email = other.Email;
+ }
+ phone_.Add(other.phone_);
}
- public static Builder CreateBuilder() { return new Builder(); }
- public override Builder ToBuilder() { return CreateBuilder(this); }
- public override Builder CreateBuilderForType() { return new Builder(); }
- public static Builder CreateBuilder(Person prototype) {
- return new Builder(prototype);
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while (input.ReadTag(out tag)) {
+ switch(tag) {
+ case 0:
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ default:
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ return;
+ }
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 16: {
+ Id = input.ReadInt32();
+ break;
+ }
+ case 26: {
+ Email = input.ReadString();
+ break;
+ }
+ case 34: {
+ input.ReadMessageArray(phone_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Parser);
+ break;
+ }
+ }
+ }
}
+ #region Nested types
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public sealed partial class Builder : pb::GeneratedBuilder {
- protected override Builder ThisBuilder {
- get { return this; }
- }
- public Builder() {
- result = DefaultInstance;
- resultIsReadOnly = true;
- }
- internal Builder(Person cloneFrom) {
- result = cloneFrom;
- resultIsReadOnly = true;
+ public static partial class Types {
+ public enum PhoneType {
+ MOBILE = 0,
+ HOME = 1,
+ WORK = 2,
}
- private bool resultIsReadOnly;
- private Person result;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class PhoneNumber : pb::IMessage, global::System.IEquatable {
+ private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PhoneNumber());
+ public static pb::MessageParser Parser { get { return _parser; } }
- private Person PrepareBuilder() {
- if (resultIsReadOnly) {
- Person original = result;
- result = new Person();
- resultIsReadOnly = false;
- MergeFrom(original);
+ private static readonly string[] _fieldNames = new string[] { "number", "type" };
+ private static readonly uint[] _fieldTags = new uint[] { 10, 16 };
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_Person_PhoneNumber__Descriptor; }
}
- return result;
- }
- public override bool IsInitialized {
- get { return result.IsInitialized; }
- }
+ public pb::FieldAccess.FieldAccessorTable Fields {
+ get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable; }
+ }
- protected override Person MessageBeingBuilt {
- get { return PrepareBuilder(); }
- }
+ public PhoneNumber() { }
+ public PhoneNumber(PhoneNumber other) {
+ MergeFrom(other);
+ }
+ public const int NumberFieldNumber = 1;
+ private string number_ = "";
+ public string Number {
+ get { return number_; }
+ set { number_ = value ?? ""; }
+ }
- public override Builder Clear() {
- result = DefaultInstance;
- resultIsReadOnly = true;
- return this;
- }
- public override Builder Clone() {
- if (resultIsReadOnly) {
- return new Builder(result);
- } else {
- return new Builder().MergeFrom(result);
+ public const int TypeFieldNumber = 2;
+ private global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType type_ = global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME;
+ public global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType Type {
+ get { return type_; }
+ set { type_ = value; }
}
- }
- public override pbd::MessageDescriptor DescriptorForType {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.Person.Descriptor; }
- }
- public override Person DefaultInstanceForType {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.Person.DefaultInstance; }
- }
-
- public override Person BuildPartial() {
- if (resultIsReadOnly) {
- return result;
+ public override bool Equals(object other) {
+ return Equals(other as PhoneNumber);
}
- resultIsReadOnly = true;
- return result.MakeReadOnly();
- }
- public override Builder MergeFrom(pb::IMessage other) {
- if (other is Person) {
- return MergeFrom((Person) other);
- } else {
- base.MergeFrom(other);
- return this;
+ public bool Equals(PhoneNumber other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Number != other.Number) return false;
+ if (Type != other.Type) return false;
+ return true;
}
- }
- public override Builder MergeFrom(Person other) {
- if (other == global::Google.ProtocolBuffers.Examples.AddressBook.Person.DefaultInstance) return this;
- PrepareBuilder();
- if (other.HasName) {
- Name = other.Name;
+ public override int GetHashCode() {
+ int hash = 0;
+ if (Number.Length != 0) hash ^= Number.GetHashCode();
+ if (Type != global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME) hash ^= Type.GetHashCode();
+ return hash;
}
- if (other.HasId) {
- Id = other.Id;
+
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Number.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Number);
+ }
+ if (Type != global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) Type);
+ }
}
- if (other.HasEmail) {
- Email = other.Email;
+
+ public int CalculateSize() {
+ int size = 0;
+ if (Number.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Number);
+ }
+ if (Type != global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
+ }
+ return size;
}
- if (other.phone_.Count != 0) {
- result.phone_.Add(other.phone_);
+ public void MergeFrom(PhoneNumber other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Number.Length != 0) {
+ Number = other.Number;
+ }
+ if (other.Type != global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME) {
+ Type = other.Type;
+ }
}
- this.MergeUnknownFields(other.UnknownFields);
- return this;
- }
- public override Builder MergeFrom(pb::ICodedInputStream input) {
- return MergeFrom(input, pb::ExtensionRegistry.Empty);
- }
-
- public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
- PrepareBuilder();
- pb::UnknownFieldSet.Builder unknownFields = null;
- uint tag;
- string field_name;
- while (input.ReadTag(out tag, out field_name)) {
- if(tag == 0 && field_name != null) {
- int field_ordinal = global::System.Array.BinarySearch(_personFieldNames, field_name, global::System.StringComparer.Ordinal);
- if(field_ordinal >= 0)
- tag = _personFieldTags[field_ordinal];
- else {
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
- }
- ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
- continue;
- }
- }
- switch (tag) {
- case 0: {
- throw pb::InvalidProtocolBufferException.InvalidTag();
- }
- default: {
- if (pb::WireFormat.IsEndGroupTag(tag)) {
- if (unknownFields != null) {
- this.UnknownFields = unknownFields.Build();
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while (input.ReadTag(out tag)) {
+ switch(tag) {
+ case 0:
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ default:
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ return;
}
- return this;
+ break;
+ case 10: {
+ Number = input.ReadString();
+ break;
}
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ case 16: {
+ type_ = (global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum();
+ break;
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
- break;
- }
- case 10: {
- result.hasName = input.ReadString(ref result.name_);
- break;
- }
- case 16: {
- result.hasId = input.ReadInt32(ref result.id_);
- break;
- }
- case 26: {
- result.hasEmail = input.ReadString(ref result.email_);
- break;
- }
- case 34: {
- input.ReadMessageArray(tag, field_name, result.phone_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.DefaultInstance, extensionRegistry);
- break;
}
}
}
- if (unknownFields != null) {
- this.UnknownFields = unknownFields.Build();
- }
- return this;
- }
-
-
- public bool HasName {
- get { return result.hasName; }
- }
- public string Name {
- get { return result.Name; }
- set { SetName(value); }
- }
- public Builder SetName(string value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.hasName = true;
- result.name_ = value;
- return this;
- }
- public Builder ClearName() {
- PrepareBuilder();
- result.hasName = false;
- result.name_ = "";
- return this;
}
- public bool HasId {
- get { return result.hasId; }
- }
- public int Id {
- get { return result.Id; }
- set { SetId(value); }
- }
- public Builder SetId(int value) {
- PrepareBuilder();
- result.hasId = true;
- result.id_ = value;
- return this;
- }
- public Builder ClearId() {
- PrepareBuilder();
- result.hasId = false;
- result.id_ = 0;
- return this;
- }
-
- public bool HasEmail {
- get { return result.hasEmail; }
- }
- public string Email {
- get { return result.Email; }
- set { SetEmail(value); }
- }
- public Builder SetEmail(string value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.hasEmail = true;
- result.email_ = value;
- return this;
- }
- public Builder ClearEmail() {
- PrepareBuilder();
- result.hasEmail = false;
- result.email_ = "";
- return this;
- }
-
- public pbc::IPopsicleList PhoneList {
- get { return PrepareBuilder().phone_; }
- }
- public int PhoneCount {
- get { return result.PhoneCount; }
- }
- public global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber GetPhone(int index) {
- return result.GetPhone(index);
- }
- public Builder SetPhone(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.phone_[index] = value;
- return this;
- }
- public Builder SetPhone(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Builder builderForValue) {
- pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
- PrepareBuilder();
- result.phone_[index] = builderForValue.Build();
- return this;
- }
- public Builder AddPhone(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.phone_.Add(value);
- return this;
- }
- public Builder AddPhone(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Builder builderForValue) {
- pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
- PrepareBuilder();
- result.phone_.Add(builderForValue.Build());
- return this;
- }
- public Builder AddRangePhone(scg::IEnumerable values) {
- PrepareBuilder();
- result.phone_.Add(values);
- return this;
- }
- public Builder ClearPhone() {
- PrepareBuilder();
- result.phone_.Clear();
- return this;
- }
- }
- static Person() {
- object.ReferenceEquals(global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.Descriptor, null);
}
+ #endregion
+
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public sealed partial class AddressBook : pb::GeneratedMessage {
- private AddressBook() { }
- private static readonly AddressBook defaultInstance = new AddressBook().MakeReadOnly();
- private static readonly string[] _addressBookFieldNames = new string[] { "person" };
- private static readonly uint[] _addressBookFieldTags = new uint[] { 10 };
- public static AddressBook DefaultInstance {
- get { return defaultInstance; }
- }
-
- public override AddressBook DefaultInstanceForType {
- get { return DefaultInstance; }
- }
-
- protected override AddressBook ThisMessage {
- get { return this; }
- }
+ public sealed partial class AddressBook : pb::IMessage, global::System.IEquatable {
+ private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AddressBook());
+ public static pb::MessageParser Parser { get { return _parser; } }
+ private static readonly string[] _fieldNames = new string[] { "person" };
+ private static readonly uint[] _fieldTags = new uint[] { 10 };
public static pbd::MessageDescriptor Descriptor {
get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_AddressBook__Descriptor; }
}
- protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ public pb::FieldAccess.FieldAccessorTable Fields {
get { return global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.internal__static_tutorial_AddressBook__FieldAccessorTable; }
}
+ public AddressBook() { }
+ public AddressBook(AddressBook other) {
+ MergeFrom(other);
+ }
public const int PersonFieldNumber = 1;
- private pbc::PopsicleList person_ = new pbc::PopsicleList();
- public scg::IList PersonList {
+ private readonly pbc::RepeatedField person_ = new pbc::RepeatedField();
+ public pbc::RepeatedField Person {
get { return person_; }
}
- public int PersonCount {
- get { return person_.Count; }
- }
- public global::Google.ProtocolBuffers.Examples.AddressBook.Person GetPerson(int index) {
- return person_[index];
+
+ public override bool Equals(object other) {
+ return Equals(other as AddressBook);
}
- public override bool IsInitialized {
- get {
- foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person element in PersonList) {
- if (!element.IsInitialized) return false;
- }
+ public bool Equals(AddressBook other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
return true;
}
+ if(!person_.Equals(other.person_)) return false;
+ return true;
}
- public override void WriteTo(pb::ICodedOutputStream output) {
- CalcSerializedSize();
- string[] field_names = _addressBookFieldNames;
- if (person_.Count > 0) {
- output.WriteMessageArray(1, field_names[0], person_);
- }
- UnknownFields.WriteTo(output);
+ public override int GetHashCode() {
+ int hash = 0;
+ hash ^= person_.GetHashCode();
+ return hash;
}
- private int memoizedSerializedSize = -1;
- public override int SerializedSize {
- get {
- int size = memoizedSerializedSize;
- if (size != -1) return size;
- return CalcSerializedSize();
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (person_.Count > 0) {
+ output.WriteMessageArray(1, person_);
}
}
- private int CalcSerializedSize() {
- int size = memoizedSerializedSize;
- if (size != -1) return size;
-
- size = 0;
- foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person element in PersonList) {
- size += pb::CodedOutputStream.ComputeMessageSize(1, element);
+ public int CalculateSize() {
+ int size = 0;
+ if (person_.Count > 0) {
+ foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person element in person_) {
+ size += pb::CodedOutputStream.ComputeMessageSize(element);
+ }
+ size += 1 * person_.Count;
}
- size += UnknownFields.SerializedSize;
- memoizedSerializedSize = size;
return size;
}
- public static AddressBook ParseFrom(pb::ByteString data) {
- return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
- }
- public static AddressBook ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
- }
- public static AddressBook ParseFrom(byte[] data) {
- return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
- }
- public static AddressBook ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
- }
- public static AddressBook ParseFrom(global::System.IO.Stream input) {
- return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
- }
- public static AddressBook ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
- }
- public static AddressBook ParseDelimitedFrom(global::System.IO.Stream input) {
- return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
- }
- public static AddressBook ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
- return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
- }
- public static AddressBook ParseFrom(pb::ICodedInputStream input) {
- return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
- }
- public static AddressBook ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
- return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
- }
- private AddressBook MakeReadOnly() {
- person_.MakeReadOnly();
- return this;
- }
-
- public static Builder CreateBuilder() { return new Builder(); }
- public override Builder ToBuilder() { return CreateBuilder(this); }
- public override Builder CreateBuilderForType() { return new Builder(); }
- public static Builder CreateBuilder(AddressBook prototype) {
- return new Builder(prototype);
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- public sealed partial class Builder : pb::GeneratedBuilder {
- protected override Builder ThisBuilder {
- get { return this; }
- }
- public Builder() {
- result = DefaultInstance;
- resultIsReadOnly = true;
- }
- internal Builder(AddressBook cloneFrom) {
- result = cloneFrom;
- resultIsReadOnly = true;
- }
-
- private bool resultIsReadOnly;
- private AddressBook result;
-
- private AddressBook PrepareBuilder() {
- if (resultIsReadOnly) {
- AddressBook original = result;
- result = new AddressBook();
- resultIsReadOnly = false;
- MergeFrom(original);
- }
- return result;
- }
-
- public override bool IsInitialized {
- get { return result.IsInitialized; }
- }
-
- protected override AddressBook MessageBeingBuilt {
- get { return PrepareBuilder(); }
- }
-
- public override Builder Clear() {
- result = DefaultInstance;
- resultIsReadOnly = true;
- return this;
- }
-
- public override Builder Clone() {
- if (resultIsReadOnly) {
- return new Builder(result);
- } else {
- return new Builder().MergeFrom(result);
- }
- }
-
- public override pbd::MessageDescriptor DescriptorForType {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.AddressBook.Descriptor; }
- }
-
- public override AddressBook DefaultInstanceForType {
- get { return global::Google.ProtocolBuffers.Examples.AddressBook.AddressBook.DefaultInstance; }
- }
-
- public override AddressBook BuildPartial() {
- if (resultIsReadOnly) {
- return result;
- }
- resultIsReadOnly = true;
- return result.MakeReadOnly();
- }
-
- public override Builder MergeFrom(pb::IMessage other) {
- if (other is AddressBook) {
- return MergeFrom((AddressBook) other);
- } else {
- base.MergeFrom(other);
- return this;
- }
- }
-
- public override Builder MergeFrom(AddressBook other) {
- if (other == global::Google.ProtocolBuffers.Examples.AddressBook.AddressBook.DefaultInstance) return this;
- PrepareBuilder();
- if (other.person_.Count != 0) {
- result.person_.Add(other.person_);
- }
- this.MergeUnknownFields(other.UnknownFields);
- return this;
- }
-
- public override Builder MergeFrom(pb::ICodedInputStream input) {
- return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ public void MergeFrom(AddressBook other) {
+ if (other == null) {
+ return;
}
+ person_.Add(other.person_);
+ }
- public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
- PrepareBuilder();
- pb::UnknownFieldSet.Builder unknownFields = null;
- uint tag;
- string field_name;
- while (input.ReadTag(out tag, out field_name)) {
- if(tag == 0 && field_name != null) {
- int field_ordinal = global::System.Array.BinarySearch(_addressBookFieldNames, field_name, global::System.StringComparer.Ordinal);
- if(field_ordinal >= 0)
- tag = _addressBookFieldTags[field_ordinal];
- else {
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
- }
- ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
- continue;
- }
- }
- switch (tag) {
- case 0: {
- throw pb::InvalidProtocolBufferException.InvalidTag();
- }
- default: {
- if (pb::WireFormat.IsEndGroupTag(tag)) {
- if (unknownFields != null) {
- this.UnknownFields = unknownFields.Build();
- }
- return this;
- }
- if (unknownFields == null) {
- unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
- }
- ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
- break;
- }
- case 10: {
- input.ReadMessageArray(tag, field_name, result.person_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.DefaultInstance, extensionRegistry);
- break;
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while (input.ReadTag(out tag)) {
+ switch(tag) {
+ case 0:
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ default:
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ return;
}
+ break;
+ case 10: {
+ input.ReadMessageArray(person_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Parser);
+ break;
}
}
-
- if (unknownFields != null) {
- this.UnknownFields = unknownFields.Build();
- }
- return this;
- }
-
-
- public pbc::IPopsicleList PersonList {
- get { return PrepareBuilder().person_; }
- }
- public int PersonCount {
- get { return result.PersonCount; }
- }
- public global::Google.ProtocolBuffers.Examples.AddressBook.Person GetPerson(int index) {
- return result.GetPerson(index);
- }
- public Builder SetPerson(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.person_[index] = value;
- return this;
- }
- public Builder SetPerson(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Builder builderForValue) {
- pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
- PrepareBuilder();
- result.person_[index] = builderForValue.Build();
- return this;
- }
- public Builder AddPerson(global::Google.ProtocolBuffers.Examples.AddressBook.Person value) {
- pb::ThrowHelper.ThrowIfNull(value, "value");
- PrepareBuilder();
- result.person_.Add(value);
- return this;
- }
- public Builder AddPerson(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Builder builderForValue) {
- pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
- PrepareBuilder();
- result.person_.Add(builderForValue.Build());
- return this;
- }
- public Builder AddRangePerson(scg::IEnumerable values) {
- PrepareBuilder();
- result.person_.Add(values);
- return this;
- }
- public Builder ClearPerson() {
- PrepareBuilder();
- result.person_.Clear();
- return this;
}
}
- static AddressBook() {
- object.ReferenceEquals(global::Google.ProtocolBuffers.Examples.AddressBook.Addressbook.Descriptor, null);
- }
+
}
#endregion
diff --git a/csharp/src/AddressBook/ListPeople.cs b/csharp/src/AddressBook/ListPeople.cs
index fe6f52d82870d14e116f977774ed431e704f9354..9666c425847300652f203d840fe300576495ceb9 100644
--- a/csharp/src/AddressBook/ListPeople.cs
+++ b/csharp/src/AddressBook/ListPeople.cs
@@ -46,16 +46,16 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
///
private static void Print(AddressBook addressBook)
{
- foreach (Person person in addressBook.PersonList)
+ foreach (Person person in addressBook.Person)
{
Console.WriteLine("Person ID: {0}", person.Id);
Console.WriteLine(" Name: {0}", person.Name);
- if (person.HasEmail)
+ if (person.Email != "")
{
Console.WriteLine(" E-mail address: {0}", person.Email);
}
- foreach (Person.Types.PhoneNumber phoneNumber in person.PhoneList)
+ foreach (Person.Types.PhoneNumber phoneNumber in person.Phone)
{
switch (phoneNumber.Type)
{
@@ -94,7 +94,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
// Read the existing address book.
using (Stream stream = File.OpenRead(args[0]))
{
- AddressBook addressBook = AddressBook.ParseFrom(stream);
+ AddressBook addressBook = AddressBook.Parser.ParseFrom(stream);
Print(addressBook);
}
return 0;
diff --git a/csharp/src/AddressBook/SampleUsage.cs b/csharp/src/AddressBook/SampleUsage.cs
index 084b16558ebee783825a9b53f487565c57bb8ae7..c06188b493ed8da54f2a2ab1360dcf0d95f7e396 100644
--- a/csharp/src/AddressBook/SampleUsage.cs
+++ b/csharp/src/AddressBook/SampleUsage.cs
@@ -1,4 +1,5 @@
-using System;
+using Google.Protobuf;
+using System;
using System.IO;
namespace Google.ProtocolBuffers.Examples.AddressBook
@@ -8,37 +9,31 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
private static void Main()
{
byte[] bytes;
- //Create a builder to start building a message
- Person.Builder newContact = Person.CreateBuilder();
- //Set the primitive properties
- newContact.SetId(1)
- .SetName("Foo")
- .SetEmail("foo@bar");
- //Now add an item to a list (repeating) field
- newContact.AddPhone(
- //Create the child message inline
- Person.Types.PhoneNumber.CreateBuilder().SetNumber("555-1212").Build()
- );
- //Now build the final message:
- Person person = newContact.Build();
- //The builder is no longer valid (at least not now, scheduled for 2.4):
- newContact = null;
+ // Create a new person
+ Person person = new Person
+ {
+ Id = 1,
+ Name = "Foo",
+ Email = "foo@bar",
+ Phone = { new Person.Types.PhoneNumber { Number = "555-1212" } }
+ };
using (MemoryStream stream = new MemoryStream())
{
- //Save the person to a stream
+ // Save the person to a stream
person.WriteTo(stream);
bytes = stream.ToArray();
}
- //Create another builder, merge the byte[], and build the message:
- Person copy = Person.CreateBuilder().MergeFrom(bytes).Build();
+ Person copy = Person.Parser.ParseFrom(bytes);
- //A more streamlined approach might look like this:
- bytes = AddressBook.CreateBuilder().AddPerson(copy).Build().ToByteArray();
- //And read the address book back again
- AddressBook restored = AddressBook.CreateBuilder().MergeFrom(bytes).Build();
- //The message performs a deep-comparison on equality:
- if (restored.PersonCount != 1 || !person.Equals(restored.PersonList[0]))
+ // A more streamlined approach might look like this:
+ bytes = copy.ToByteArray();
+ // And read the address book back again
+ AddressBook restored = AddressBook.Parser.ParseFrom(bytes);
+ // The message performs a deep-comparison on equality:
+ if (restored.Person.Count != 1 || !person.Equals(restored.Person[0]))
+ {
throw new ApplicationException("There is a bad person in here!");
+ }
}
}
}
\ No newline at end of file
diff --git a/csharp/src/ProtoMunge/Program.cs b/csharp/src/ProtoMunge/Program.cs
index 53dc3501dcceabc31496ada4f567d72ce35efb91..6379f30bba0cc695bce82062359275e9f607d706 100644
--- a/csharp/src/ProtoMunge/Program.cs
+++ b/csharp/src/ProtoMunge/Program.cs
@@ -38,6 +38,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
+using Google.Protobuf;
+using Google.Protobuf.Descriptors;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers.ProtoMunge
diff --git a/csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs b/csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs
deleted file mode 100644
index 99ecec88f5fbcd820ed678f9d245dc4f2d02d01c..0000000000000000000000000000000000000000
--- a/csharp/src/ProtocolBuffers.Serialization/AbstractReader.cs
+++ /dev/null
@@ -1,686 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using Google.ProtocolBuffers.Descriptors;
-
-//Disable CS3011: only CLS-compliant members can be abstract
-#pragma warning disable 3011
-
-namespace Google.ProtocolBuffers.Serialization
-{
- ///
- /// Provides a base-class that provides some basic functionality for handling type dispatching
- ///
- public abstract class AbstractReader : ICodedInputStream
- {
- private const int DefaultMaxDepth = 64;
- private int _depth;
-
- /// Constructs a new reader
- protected AbstractReader() { MaxDepth = DefaultMaxDepth; }
-
- /// Gets or sets the maximum recursion depth allowed
- public int MaxDepth { get; set; }
-
- ///
- /// Merges the contents of stream into the provided message builder
- ///
- public TBuilder Merge(TBuilder builder) where TBuilder : IBuilderLite
- {
- return Merge(builder, ExtensionRegistry.Empty);
- }
-
- ///
- /// Merges the contents of stream into the provided message builder
- ///
- public abstract TBuilder Merge(TBuilder builder, ExtensionRegistry registry)
- where TBuilder : IBuilderLite;
-
- ///
- /// Peeks at the next field in the input stream and returns what information is available.
- ///
- ///
- /// This may be called multiple times without actually reading the field. Only after the field
- /// is either read, or skipped, should PeekNext return a different value.
- ///
- protected abstract bool PeekNext(out string field);
-
- ///
- /// Causes the reader to skip past this field
- ///
- protected abstract void Skip();
-
- ///
- /// Returns true if it was able to read a Boolean from the input
- ///
- protected abstract bool Read(ref bool value);
-
- ///
- /// Returns true if it was able to read a Int32 from the input
- ///
- protected abstract bool Read(ref int value);
-
- ///
- /// Returns true if it was able to read a UInt32 from the input
- ///
- protected abstract bool Read(ref uint value);
-
- ///
- /// Returns true if it was able to read a Int64 from the input
- ///
- protected abstract bool Read(ref long value);
-
- ///
- /// Returns true if it was able to read a UInt64 from the input
- ///
- protected abstract bool Read(ref ulong value);
-
- ///
- /// Returns true if it was able to read a Single from the input
- ///
- protected abstract bool Read(ref float value);
-
- ///
- /// Returns true if it was able to read a Double from the input
- ///
- protected abstract bool Read(ref double value);
-
- ///
- /// Returns true if it was able to read a String from the input
- ///
- protected abstract bool Read(ref string value);
-
- ///
- /// Returns true if it was able to read a ByteString from the input
- ///
- protected abstract bool Read(ref ByteString value);
-
- ///
- /// returns true if it was able to read a single value into the value reference. The value
- /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
- ///
- protected abstract bool ReadEnum(ref object value);
-
- ///
- /// Merges the input stream into the provided IBuilderLite
- ///
- protected abstract bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry);
-
- ///
- /// Reads the root-message preamble specific to this formatter
- ///
- public abstract void ReadMessageStart();
-
- ///
- /// Reads the root-message close specific to this formatter
- ///
- public abstract void ReadMessageEnd();
-
- ///
- /// Merges the input stream into the provided IBuilderLite
- ///
- public virtual bool ReadGroup(IBuilderLite value, ExtensionRegistry registry)
- {
- return ReadMessage(value, registry);
- }
-
- ///
- /// Cursors through the array elements and stops at the end of the array
- ///
- protected virtual IEnumerable ForeachArrayItem(string field)
- {
- string next = field;
- while (true)
- {
- yield return next;
-
- if (!PeekNext(out next) || next != field)
- {
- break;
- }
- }
- }
-
- ///
- /// Reads an array of T messages
- ///
- public virtual bool ReadMessageArray(string field, ICollection items, IMessageLite messageType,
- ExtensionRegistry registry)
- {
- bool success = false;
- foreach (string next in ForeachArrayItem(field))
- {
- IBuilderLite builder = messageType.WeakCreateBuilderForType();
- if (ReadMessage(builder, registry))
- {
- items.Add((T) builder.WeakBuild());
- success |= true;
- }
- }
- return success;
- }
-
- ///
- /// Reads an array of T messages as a proto-buffer group
- ///
- public virtual bool ReadGroupArray(string field, ICollection items, IMessageLite messageType,
- ExtensionRegistry registry)
- {
- bool success = false;
- foreach (string next in ForeachArrayItem(field))
- {
- IBuilderLite builder = messageType.WeakCreateBuilderForType();
- if (ReadGroup(builder, registry))
- {
- items.Add((T) builder.WeakBuild());
- success |= true;
- }
- }
- return success;
- }
-
- ///
- /// Reads an array of System.Enum type T and adds them to the collection
- ///
- public virtual bool ReadEnumArray(string field, ICollection