From 09f3f4eec3a7e6b2f58b47eb007bcb24dfdbf7a0 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 17 Jun 2015 15:16:14 +0100 Subject: Updates to handle use of cmake for Windows builds. --- cmake/libprotoc.cmake | 2 -- 1 file changed, 2 deletions(-) (limited to 'cmake/libprotoc.cmake') diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 8caa9e9e..e9e88af5 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 -- cgit v1.2.3 From 0d684d34209f8405106e580af854c45fb7c3f16d Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 24 Jun 2015 17:21:55 +0100 Subject: First pass at map support. More tests required. Generated code in next commit. --- cmake/libprotoc.cmake | 1 + .../ProtocolBuffers.Test/GeneratedMessageTest.cs | 61 ++++ csharp/src/ProtocolBuffers/CodedOutputStream.cs | 8 + csharp/src/ProtocolBuffers/Collections/MapField.cs | 400 +++++++++++++++++++++ csharp/src/ProtocolBuffers/FieldCodec.cs | 178 +++++++++ csharp/src/ProtocolBuffers/ProtocolBuffers.csproj | 2 + src/Makefile.am | 2 + .../protobuf/compiler/csharp/csharp_enum_field.cc | 6 + .../protobuf/compiler/csharp/csharp_enum_field.h | 1 + .../protobuf/compiler/csharp/csharp_field_base.cc | 16 +- .../protobuf/compiler/csharp/csharp_field_base.h | 2 + .../protobuf/compiler/csharp/csharp_helpers.cc | 7 +- .../protobuf/compiler/csharp/csharp_map_field.cc | 141 ++++++++ .../protobuf/compiler/csharp/csharp_map_field.h | 71 ++++ .../protobuf/compiler/csharp/csharp_message.cc | 6 +- .../compiler/csharp/csharp_message_field.cc | 6 + .../compiler/csharp/csharp_message_field.h | 1 + .../compiler/csharp/csharp_primitive_field.cc | 8 +- .../compiler/csharp/csharp_primitive_field.h | 1 + src/google/protobuf/unittest_proto3.proto | 5 + 20 files changed, 913 insertions(+), 10 deletions(-) create mode 100644 csharp/src/ProtocolBuffers/Collections/MapField.cs create mode 100644 csharp/src/ProtocolBuffers/FieldCodec.cs create mode 100644 src/google/protobuf/compiler/csharp/csharp_map_field.cc create mode 100644 src/google/protobuf/compiler/csharp/csharp_map_field.h (limited to 'cmake/libprotoc.cmake') diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index e9e88af5..8bf0a1f3 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -19,6 +19,7 @@ set(libprotoc_files ${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 + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_map_field.cc ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message.cc ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message_field.cc ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc diff --git a/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs b/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs index 26165428..81e35940 100644 --- a/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs +++ b/csharp/src/ProtocolBuffers.Test/GeneratedMessageTest.cs @@ -1,4 +1,6 @@ using System; +using System.Configuration; +using System.IO; using Google.Protobuf.TestProtos; using NUnit.Framework; @@ -146,6 +148,65 @@ namespace Google.Protobuf Assert.AreEqual(message, parsed); } + [Test] + public void RoundTrip_Maps() + { + var message = new TestAllTypes + { + MapBoolToEnum = { + { false, TestAllTypes.Types.NestedEnum.BAR}, + { true, TestAllTypes.Types.NestedEnum.BAZ} + }, + MapInt32ToBytes = { + { 5, ByteString.CopyFrom(6, 7, 8) }, + { 25, ByteString.CopyFrom(1, 2, 3, 4, 5) }, + { 10, ByteString.Empty } + }, + MapStringToNestedMessage = { + { "", new TestAllTypes.Types.NestedMessage { Bb = 10 } }, + { "null value", null }, + } + }; + + byte[] bytes = message.ToByteArray(); + TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes); + Assert.AreEqual(message, parsed); + } + + [Test] + public void MapWithEmptyEntry() + { + var message = new TestAllTypes + { + MapInt32ToBytes = { { 0, ByteString.Empty } } + }; + + byte[] bytes = message.ToByteArray(); + Assert.AreEqual(3, bytes.Length); // Tag for field entry (2 bytes), length of entry (0; 1 byte) + + var parsed = TestAllTypes.Parser.ParseFrom(bytes); + Assert.AreEqual(1, parsed.MapInt32ToBytes.Count); + Assert.AreEqual(ByteString.Empty, parsed.MapInt32ToBytes[0]); + } + + [Test] + public void MapWithOnlyValue() + { + // Hand-craft the stream to contain a single entry with just a value. + var memoryStream = new MemoryStream(); + var output = CodedOutputStream.CreateInstance(memoryStream); + output.WriteTag(TestAllTypes.MapStringToNestedMessageFieldNumber, WireFormat.WireType.LengthDelimited); + var nestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 }; + // Size of the entry (tag, size written by WriteMessage, data written by WriteMessage) + output.WriteRawVarint32((uint)(nestedMessage.CalculateSize() + 3)); + output.WriteTag(2, WireFormat.WireType.LengthDelimited); + output.WriteMessage(nestedMessage); + output.Flush(); + + var parsed = TestAllTypes.Parser.ParseFrom(memoryStream.ToArray()); + Assert.AreEqual(nestedMessage, parsed.MapStringToNestedMessage[""]); + } + [Test] public void CloneSingleNonMessageValues() { diff --git a/csharp/src/ProtocolBuffers/CodedOutputStream.cs b/csharp/src/ProtocolBuffers/CodedOutputStream.cs index e56ce789..def874c0 100644 --- a/csharp/src/ProtocolBuffers/CodedOutputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedOutputStream.cs @@ -475,6 +475,14 @@ namespace Google.Protobuf WriteRawVarint32(WireFormat.MakeTag(fieldNumber, type)); } + /// + /// Writes an already-encoded tag. + /// + public void WriteTag(uint tag) + { + WriteRawVarint32(tag); + } + /// /// Writes the given single-byte tag directly to the stream. /// diff --git a/csharp/src/ProtocolBuffers/Collections/MapField.cs b/csharp/src/ProtocolBuffers/Collections/MapField.cs new file mode 100644 index 00000000..2f5a741d --- /dev/null +++ b/csharp/src/ProtocolBuffers/Collections/MapField.cs @@ -0,0 +1,400 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Google.Protobuf.Collections +{ + /// + /// Representation of a map field in a Protocol Buffer message. + /// + /// + /// This implementation preserves insertion order for simplicity of testing + /// code using maps fields. Overwriting an existing entry does not change the + /// position of that entry within the map. Equality is not order-sensitive. + /// For string keys, the equality comparison is provided by . + /// + /// Key type in the map. Must be a type supported by Protocol Buffer map keys. + /// Value type in the map. Must be a type supported by Protocol Buffers. + public sealed class MapField : IDeepCloneable>, IFreezable, IDictionary, IEquatable> + { + // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.) + private bool frozen; + private readonly Dictionary>> map = + new Dictionary>>(); + private readonly LinkedList> list = new LinkedList>(); + + public MapField Clone() + { + var clone = new MapField(); + // Keys are never cloneable. Values might be. + if (typeof(IDeepCloneable).IsAssignableFrom(typeof(TValue))) + { + foreach (var pair in list) + { + clone.Add(pair.Key, pair.Value == null ? pair.Value : ((IDeepCloneable) pair.Value).Clone()); + } + } + else + { + // Nothing is cloneable, so we don't need to worry. + clone.Add(this); + } + return clone; + } + + public void Add(TKey key, TValue value) + { + ThrowHelper.ThrowIfNull(key, "key"); + this.CheckMutable(); + if (ContainsKey(key)) + { + throw new ArgumentException("Key already exists in map", "key"); + } + this[key] = value; + } + + public bool ContainsKey(TKey key) + { + return map.ContainsKey(key); + } + + public bool Remove(TKey key) + { + this.CheckMutable(); + LinkedListNode> node; + if (map.TryGetValue(key, out node)) + { + map.Remove(key); + node.List.Remove(node); + return true; + } + else + { + return false; + } + } + + public bool TryGetValue(TKey key, out TValue value) + { + LinkedListNode> node; + if (map.TryGetValue(key, out node)) + { + value = node.Value.Value; + return true; + } + else + { + value = default(TValue); + return false; + } + } + + public TValue this[TKey key] + { + get + { + TValue value; + if (TryGetValue(key, out value)) + { + return value; + } + throw new KeyNotFoundException(); + } + set + { + this.CheckMutable(); + LinkedListNode> node; + var pair = new KeyValuePair(key, value); + if (map.TryGetValue(key, out node)) + { + node.Value = pair; + } + else + { + node = list.AddLast(pair); + map[key] = node; + } + } + } + + // TODO: Make these views? + public ICollection Keys { get { return list.Select(t => t.Key).ToList(); } } + public ICollection Values { get { return list.Select(t => t.Value).ToList(); } } + + public void Add(IDictionary entries) + { + foreach (var pair in entries) + { + Add(pair); + } + } + + public IEnumerator> GetEnumerator() + { + return list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + this.CheckMutable(); + Add(item.Key, item.Value); + } + + public void Clear() + { + this.CheckMutable(); + list.Clear(); + map.Clear(); + } + + public bool Contains(KeyValuePair item) + { + TValue value; + return TryGetValue(item.Key, out value) + && EqualityComparer.Default.Equals(item.Value, value); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); + } + + public bool Remove(KeyValuePair item) + { + this.CheckMutable(); + return Remove(item.Key); + } + + public int Count { get { return list.Count; } } + public bool IsReadOnly { get { return frozen; } } + + public void Freeze() + { + if (IsFrozen) + { + return; + } + frozen = true; + // Only values can be frozen, as all the key types are simple. + // Everything can be done in-place, as we're just freezing objects. + if (typeof(IFreezable).IsAssignableFrom(typeof(TValue))) + { + for (var node = list.First; node != null; node = node.Next) + { + var pair = node.Value; + IFreezable freezableValue = pair.Value as IFreezable; + if (freezableValue != null) + { + freezableValue.Freeze(); + } + } + } + } + + public bool IsFrozen { get { return frozen; } } + + public override bool Equals(object other) + { + return Equals(other as MapField); + } + + public override int GetHashCode() + { + var valueComparer = EqualityComparer.Default; + int hash = 0; + foreach (var pair in list) + { + hash ^= pair.Key.GetHashCode() * 31 + valueComparer.GetHashCode(pair.Value); + } + return hash; + } + + public bool Equals(MapField other) + { + if (other == null) + { + return false; + } + if (other == this) + { + return true; + } + if (other.Count != this.Count) + { + return false; + } + var valueComparer = EqualityComparer.Default; + foreach (var pair in this) + { + TValue value; + if (!other.TryGetValue(pair.Key, out value)) + { + return false; + } + if (!valueComparer.Equals(value, pair.Value)) + { + return false; + } + } + return true; + } + + public void AddEntriesFrom(CodedInputStream input, Codec codec) + { + // TODO: Peek at the next tag and see if it's the same. If it is, we can reuse the entry object... + var adapter = new Codec.MessageAdapter(codec); + adapter.Reset(); + input.ReadMessage(adapter); + this[adapter.Key] = adapter.Value; + } + + public void WriteTo(CodedOutputStream output, Codec codec) + { + var message = new Codec.MessageAdapter(codec); + foreach (var entry in list) + { + message.Key = entry.Key; + message.Value = entry.Value; + output.WriteTag(codec.MapTag); + output.WriteMessage(message); + } + } + + public int CalculateSize(Codec codec) + { + var message = new Codec.MessageAdapter(codec); + int size = 0; + foreach (var entry in list) + { + message.Key = entry.Key; + message.Value = entry.Value; + size += CodedOutputStream.ComputeRawVarint32Size(codec.MapTag); + size += CodedOutputStream.ComputeMessageSize(message); + } + return size; + } + + /// + /// A codec for a specific map field. This contains all the information required to encoded and + /// decode the nested messages. + /// + public sealed class Codec + { + private readonly FieldCodec keyCodec; + private readonly FieldCodec valueCodec; + private readonly uint mapTag; + + public Codec(FieldCodec keyCodec, FieldCodec valueCodec, uint mapTag) + { + this.keyCodec = keyCodec; + this.valueCodec = valueCodec; + this.mapTag = mapTag; + } + + /// + /// The tag used in the enclosing message to indicate map entries. + /// + internal uint MapTag { get { return mapTag; } } + + /// + /// A mutable message class, used for parsing and serializing. This + /// delegates the work to a codec, but implements the interface + /// for interop with and . + /// This is nested inside Codec as it's tightly coupled to the associated codec, + /// and it's simpler if it has direct access to all its fields. + /// + internal class MessageAdapter : IMessage + { + private readonly Codec codec; + internal TKey Key { get; set; } + internal TValue Value { get; set; } + internal int Size { get; set; } + + internal MessageAdapter(Codec codec) + { + this.codec = codec; + } + + internal void Reset() + { + Key = codec.keyCodec.DefaultValue; + Value = codec.valueCodec.DefaultValue; + } + + public void MergeFrom(CodedInputStream input) + { + uint tag; + while (input.ReadTag(out tag)) + { + if (tag == 0) + { + throw InvalidProtocolBufferException.InvalidTag(); + } + if (tag == codec.keyCodec.Tag) + { + Key = codec.keyCodec.Read(input); + } + else if (tag == codec.valueCodec.Tag) + { + Value = codec.valueCodec.Read(input); + } + else if (WireFormat.IsEndGroupTag(tag)) + { + // TODO(jonskeet): Do we need this? (Given that we don't support groups...) + return; + } + } + } + + public void WriteTo(CodedOutputStream output) + { + codec.keyCodec.Write(output, Key); + codec.valueCodec.Write(output, Value); + } + + public int CalculateSize() + { + return codec.keyCodec.CalculateSize(Key) + codec.valueCodec.CalculateSize(Value); + } + } + } + } +} diff --git a/csharp/src/ProtocolBuffers/FieldCodec.cs b/csharp/src/ProtocolBuffers/FieldCodec.cs new file mode 100644 index 00000000..931b54d3 --- /dev/null +++ b/csharp/src/ProtocolBuffers/FieldCodec.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; + +namespace Google.Protobuf +{ + /// + /// Factory methods for . + /// + public static class FieldCodec + { + public static FieldCodec ForString(uint tag) + { + return new FieldCodec(input => input.ReadString(), (output, value) => output.WriteString(value), CodedOutputStream.ComputeStringSize, tag); + } + + public static FieldCodec ForBytes(uint tag) + { + return new FieldCodec(input => input.ReadBytes(), (output, value) => output.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag); + } + + public static FieldCodec ForBool(uint tag) + { + return new FieldCodec(input => input.ReadBool(), (output, value) => output.WriteBool(value), CodedOutputStream.ComputeBoolSize, tag); + } + + public static FieldCodec ForInt32(uint tag) + { + return new FieldCodec(input => input.ReadInt32(), (output, value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag); + } + + public static FieldCodec ForSInt32(uint tag) + { + return new FieldCodec(input => input.ReadSInt32(), (output, value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag); + } + + public static FieldCodec ForFixedInt32(uint tag) + { + return new FieldCodec(input => input.ReadFixed32(), (output, value) => output.WriteFixed32(value), CodedOutputStream.ComputeFixed32Size, tag); + } + + public static FieldCodec ForUInt32(uint tag) + { + return new FieldCodec(input => input.ReadUInt32(), (output, value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag); + } + + public static FieldCodec ForInt64(uint tag) + { + return new FieldCodec(input => input.ReadInt64(), (output, value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag); + } + + public static FieldCodec ForSInt64(uint tag) + { + return new FieldCodec(input => input.ReadSInt64(), (output, value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag); + } + + public static FieldCodec ForFixedInt64(uint tag) + { + return new FieldCodec(input => input.ReadFixed64(), (output, value) => output.WriteFixed64(value), CodedOutputStream.ComputeFixed64Size, tag); + } + + public static FieldCodec ForUInt64(uint tag) + { + return new FieldCodec(input => input.ReadUInt64(), (output, value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag); + } + + public static FieldCodec ForFloat(uint tag) + { + return new FieldCodec(input => input.ReadFloat(), (output, value) => output.WriteFloat(value), CodedOutputStream.ComputeFloatSize, tag); + } + + public static FieldCodec ForDouble(uint tag) + { + return new FieldCodec(input => input.ReadFloat(), (output, value) => output.WriteDouble(value), CodedOutputStream.ComputeDoubleSize, tag); + } + + // Enums are tricky. We can probably use expression trees to build these delegates automatically, + // but it's easy to generate the code fdor it. + public static FieldCodec ForEnum(uint tag, Func toInt32, Func fromInt32) + { + return new FieldCodec(input => fromInt32( + input.ReadEnum()), + (output, value) => output.WriteEnum(toInt32(value)), + value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag); + } + + public static FieldCodec ForMessage(uint tag, MessageParser parser) where T : IMessage + { + return new FieldCodec(input => { T message = parser.CreateTemplate(); input.ReadMessage(message); return message; }, + (output, value) => output.WriteMessage(value), message => CodedOutputStream.ComputeMessageSize(message), tag); + } + } + + /// + /// An encode/decode pair for a single field. This effectively encapsulates + /// all the information needed to read or write the field value from/to a coded + /// stream. + /// + /// + /// This never writes default values to the stream, and is not currently designed + /// to play well with packed arrays. + /// + public sealed class FieldCodec + { + private static readonly Func IsDefault; + private static readonly T Default; + + static FieldCodec() + { + if (typeof(T) == typeof(string)) + { + Default = (T)(object)""; + IsDefault = CreateDefaultValueCheck(x => x.Length == 0); + } + else if (typeof(T) == typeof(ByteString)) + { + Default = (T)(object)ByteString.Empty; + IsDefault = CreateDefaultValueCheck(x => x.Length == 0); + } + else if (!typeof(T).IsValueType) + { + // Default default + IsDefault = CreateDefaultValueCheck(x => x == null); + } + else + { + // Default default + IsDefault = CreateDefaultValueCheck(x => EqualityComparer.Default.Equals(x, default(T))); + } + } + + private static Func CreateDefaultValueCheck(Func check) + { + return (Func)(object)check; + } + + private readonly Func reader; + private readonly Action writer; + private readonly Func sizeComputer; + private readonly uint tag; + private readonly int tagSize; + + internal FieldCodec( + Func reader, + Action writer, + Func sizeComputer, + uint tag) + { + this.reader = reader; + this.writer = writer; + this.sizeComputer = sizeComputer; + this.tag = tag; + tagSize = CodedOutputStream.ComputeRawVarint32Size(tag); + } + + public uint Tag { get { return tag; } } + + public T DefaultValue { get { return Default; } } + + public void Write(CodedOutputStream output, T value) + { + if (!IsDefault(value)) + { + output.WriteTag(tag); + writer(output, value); + } + } + + public T Read(CodedInputStream input) + { + return reader(input); + } + + public int CalculateSize(T value) + { + return IsDefault(value) ? 0 : sizeComputer(value) + CodedOutputStream.ComputeRawVarint32Size(tag); + } + } +} diff --git a/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj b/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj index d1551148..5edeff70 100644 --- a/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj +++ b/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj @@ -60,6 +60,7 @@ + @@ -84,6 +85,7 @@ + diff --git a/src/Makefile.am b/src/Makefile.am index 866af48a..cea3089e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -425,6 +425,8 @@ libprotoc_la_SOURCES = \ google/protobuf/compiler/csharp/csharp_generator.cc \ google/protobuf/compiler/csharp/csharp_helpers.cc \ google/protobuf/compiler/csharp/csharp_helpers.h \ + google/protobuf/compiler/csharp/csharp_map_field.cc \ + google/protobuf/compiler/csharp/csharp_map_field.h \ google/protobuf/compiler/csharp/csharp_message.cc \ google/protobuf/compiler/csharp/csharp_message.h \ google/protobuf/compiler/csharp/csharp_message_field.cc \ diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc index af34f50c..d38fb1ed 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc @@ -74,6 +74,12 @@ void EnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { "}\n"); } +void EnumFieldGenerator::GenerateCodecCode(io::Printer* printer) { + printer->Print( + variables_, + "pb::FieldCodec.ForEnum($tag$, x => (int) x, x => ($type_name$) x)"); +} + EnumOneofFieldGenerator::EnumOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal) : PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal) { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_enum_field.h index e627b7cc..08364157 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.h @@ -46,6 +46,7 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator { EnumFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal); ~EnumFieldGenerator(); + virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index c716e1bf..bfb39a64 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -65,6 +65,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( tag_bytes += ", " + SimpleItoa(tag_array[i]); } + (*variables)["tag"] = SimpleItoa(tag); (*variables)["tag_size"] = SimpleItoa(tag_size); (*variables)["tag_bytes"] = tag_bytes; @@ -112,6 +113,11 @@ void FieldGeneratorBase::GenerateFreezingCode(io::Printer* printer) { // special handling for freezing, so default to not generating any code. } +void FieldGeneratorBase::GenerateCodecCode(io::Printer* printer) { + // No-op: expect this to be overridden by appropriate types. + // Could fail if we get called here though... +} + void FieldGeneratorBase::AddDeprecatedFlag(io::Printer* printer) { if (descriptor_->options().deprecated()) { @@ -151,12 +157,16 @@ std::string FieldGeneratorBase::name() { } std::string FieldGeneratorBase::type_name() { - switch (descriptor_->type()) { + return type_name(descriptor_); +} + +std::string FieldGeneratorBase::type_name(const FieldDescriptor* descriptor) { + switch (descriptor->type()) { case FieldDescriptor::TYPE_ENUM: - return GetClassName(descriptor_->enum_type()); + return GetClassName(descriptor->enum_type()); case FieldDescriptor::TYPE_MESSAGE: case FieldDescriptor::TYPE_GROUP: - return GetClassName(descriptor_->message_type()); + return GetClassName(descriptor->message_type()); case FieldDescriptor::TYPE_DOUBLE: return "double"; case FieldDescriptor::TYPE_FLOAT: diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index abf9254b..349d835b 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -49,6 +49,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { virtual void GenerateCloningCode(io::Printer* printer) = 0; virtual void GenerateFreezingCode(io::Printer* printer); + virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer) = 0; virtual void GenerateMergingCode(io::Printer* printer) = 0; virtual void GenerateParsingCode(io::Printer* printer) = 0; @@ -76,6 +77,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { std::string property_name(); std::string name(); std::string type_name(); + std::string type_name(const FieldDescriptor* descriptor); bool has_default_value(); bool is_nullable_type(); std::string default_value(); diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 39a53268..927fea97 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -355,7 +356,11 @@ FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, case FieldDescriptor::TYPE_GROUP: case FieldDescriptor::TYPE_MESSAGE: if (descriptor->is_repeated()) { - return new RepeatedMessageFieldGenerator(descriptor, fieldOrdinal); + if (descriptor->is_map()) { + return new MapFieldGenerator(descriptor, fieldOrdinal); + } else { + return new RepeatedMessageFieldGenerator(descriptor, fieldOrdinal); + } } else { if (descriptor->containing_oneof()) { return new MessageOneofFieldGenerator(descriptor, fieldOrdinal); diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc new file mode 100644 index 00000000..b8f1592c --- /dev/null +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -0,0 +1,141 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace csharp { + +MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor, + int fieldOrdinal) + : FieldGeneratorBase(descriptor, fieldOrdinal) { +} + +MapFieldGenerator::~MapFieldGenerator() { +} + +void MapFieldGenerator::GenerateMembers(io::Printer* printer) { + const FieldDescriptor* key_descriptor = + descriptor_->message_type()->FindFieldByName("key"); + const FieldDescriptor* value_descriptor = + descriptor_->message_type()->FindFieldByName("value"); + variables_["key_type_name"] = type_name(key_descriptor); + variables_["value_type_name"] = type_name(value_descriptor); + scoped_ptr key_generator(CreateFieldGenerator(key_descriptor, 1)); + scoped_ptr value_generator(CreateFieldGenerator(value_descriptor, 2)); + + printer->Print( + variables_, + "private static readonly pbc::MapField<$key_type_name$, $value_type_name$>.Codec _map_$name$_codec\n" + " = new pbc::MapField<$key_type_name$, $value_type_name$>.Codec("); + key_generator->GenerateCodecCode(printer); + printer->Print(", "); + value_generator->GenerateCodecCode(printer); + printer->Print( + variables_, + ", $tag$);\n" + "private readonly pbc::MapField<$key_type_name$, $value_type_name$> $name$_ = new pbc::MapField<$key_type_name$, $value_type_name$>();\n"); + AddDeprecatedFlag(printer); + printer->Print( + variables_, + "public pbc::MapField<$key_type_name$, $value_type_name$> $property_name$ {\n" + " get { return $name$_; }\n" + "}\n"); +} + +void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.Add(other.$name$_);\n"); +} + +void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.AddEntriesFrom(input, _map_$name$_codec);\n"); +} + +void MapFieldGenerator::GenerateSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.WriteTo(output, _map_$name$_codec);\n"); +} + +void MapFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { + printer->Print( + variables_, + "size += $name$_.CalculateSize(_map_$name$_codec);\n"); +} + +void MapFieldGenerator::WriteHash(io::Printer* printer) { + printer->Print( + variables_, + "hash ^= $property_name$.GetHashCode();\n"); +} +void MapFieldGenerator::WriteEquals(io::Printer* printer) { + printer->Print( + variables_, + "if (!$property_name$.Equals(other.$property_name$)) return false;\n"); +} +void MapFieldGenerator::WriteToString(io::Printer* printer) { + /* + variables_["field_name"] = GetFieldName(descriptor_); + printer->Print( + variables_, + "PrintField(\"$field_name$\", has$property_name$, $name$_, writer);\n");*/ +} + +void MapFieldGenerator::GenerateCloningCode(io::Printer* printer) { + printer->Print(variables_, + "$name$_ = other.$name$_.Clone();\n"); +} + +void MapFieldGenerator::GenerateFreezingCode(io::Printer* printer) { + printer->Print(variables_, + "$name$_.Freeze();\n"); +} + +} // namespace csharp +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.h b/src/google/protobuf/compiler/csharp/csharp_map_field.h new file mode 100644 index 00000000..f33fe1c3 --- /dev/null +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.h @@ -0,0 +1,71 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace csharp { + +class MapFieldGenerator : public FieldGeneratorBase { + public: + MapFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal); + ~MapFieldGenerator(); + + virtual void GenerateCloningCode(io::Printer* printer); + virtual void GenerateFreezingCode(io::Printer* printer); + virtual void GenerateMembers(io::Printer* printer); + virtual void GenerateMergingCode(io::Printer* printer); + virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateSerializedSizeCode(io::Printer* printer); + + virtual void WriteHash(io::Printer* printer); + virtual void WriteEquals(io::Printer* printer); + virtual void WriteToString(io::Printer* printer); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator); +}; + +} // namespace csharp +} // namespace compiler +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ + diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index a6c8e32b..3cb91951 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -268,8 +268,6 @@ void MessageGenerator::Generate(io::Printer* printer) { "}\n\n"); } - // TODO(jonskeet): Map properties - // Standard methods GenerateFrameworkMethods(printer); GenerateMessageSerializationMethods(printer); @@ -299,7 +297,6 @@ void MessageGenerator::Generate(io::Printer* printer) { printer->Outdent(); printer->Print("}\n"); printer->Print("\n"); - } void MessageGenerator::GenerateCloningCode(io::Printer* printer) { @@ -451,7 +448,7 @@ void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer) } printer->Print("return size;\n"); printer->Outdent(); - printer->Print("}\n"); + printer->Print("}\n\n"); } void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { @@ -469,7 +466,6 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { "if (other == null) {\n" " return;\n" "}\n"); - // TODO(jonskeet): Maps? // Merge non-oneof fields for (int i = 0; i < descriptor_->field_count(); i++) { if (!descriptor_->field(i)->containing_oneof()) { diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_message_field.cc index cbf182d2..d8c82271 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.cc @@ -138,6 +138,12 @@ void MessageFieldGenerator::GenerateFreezingCode(io::Printer* printer) { "if ($has_property_check$) $property_name$.Freeze();\n"); } +void MessageFieldGenerator::GenerateCodecCode(io::Printer* printer) { + printer->Print( + variables_, + "pb::FieldCodec.ForMessage($tag$, $type_name$.Parser)"); +} + MessageOneofFieldGenerator::MessageOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal) : MessageFieldGenerator(descriptor, fieldOrdinal) { diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.h b/src/google/protobuf/compiler/csharp/csharp_message_field.h index 3e17f92a..dc6e4dc5 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.h @@ -46,6 +46,7 @@ class MessageFieldGenerator : public FieldGeneratorBase { MessageFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal); ~MessageFieldGenerator(); + virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc index d5542f57..c40cba13 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc @@ -129,7 +129,7 @@ void PrimitiveFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { "size += $tag_size$ + $fixed_size$;\n", "fixed_size", SimpleItoa(fixedSize), "tag_size", variables_["tag_size"]); - } + } printer->Outdent(); printer->Print("}\n"); } @@ -155,6 +155,12 @@ void PrimitiveFieldGenerator::GenerateCloningCode(io::Printer* printer) { "$name$_ = other.$name$_;\n"); } +void PrimitiveFieldGenerator::GenerateCodecCode(io::Printer* printer) { + printer->Print( + variables_, + "pb::FieldCodec.For$capitalized_type_name$($tag$)"); +} + PrimitiveOneofFieldGenerator::PrimitiveOneofFieldGenerator( const FieldDescriptor* descriptor, int fieldOrdinal) : PrimitiveFieldGenerator(descriptor, fieldOrdinal) { diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h index bac33214..8b87ebc4 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h @@ -46,6 +46,7 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase { PrimitiveFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal); ~PrimitiveFieldGenerator(); + virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); diff --git a/src/google/protobuf/unittest_proto3.proto b/src/google/protobuf/unittest_proto3.proto index f59d2178..41fa56dc 100644 --- a/src/google/protobuf/unittest_proto3.proto +++ b/src/google/protobuf/unittest_proto3.proto @@ -140,6 +140,11 @@ message TestAllTypes { string oneof_string = 113; bytes oneof_bytes = 114; } + + // Sample maps + map map_string_to_nested_message = 200; + map map_int32_to_bytes = 201; + map map_bool_to_enum = 202; } // This proto includes a recusively nested message. -- cgit v1.2.3 From b2ac868493742327b2ebbcacd97947126f8841f7 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 15 Jul 2015 13:17:42 +0100 Subject: First part of implementing wrapper types. Not ready yet! --- BUILD | 4 +- cmake/libprotoc.cmake | 1 + csharp/generate_protos.sh | 3 +- .../ProtocolBuffers.Test.csproj | 2 + .../TestProtos/UnittestWellKnownTypes.cs | 2335 ++++++++++++++++++++ .../WellKnownTypes/WrappersTest.cs | 85 + src/Makefile.am | 4 +- .../protobuf/compiler/csharp/csharp_field_base.cc | 12 + .../protobuf/compiler/csharp/csharp_helpers.cc | 39 +- .../protobuf/compiler/csharp/csharp_helpers.h | 9 + .../compiler/csharp/csharp_wrapper_field.cc | 210 ++ .../compiler/csharp/csharp_wrapper_field.h | 86 + .../protobuf/unittest_well_known_types.proto | 83 +- 13 files changed, 2853 insertions(+), 20 deletions(-) create mode 100644 csharp/src/ProtocolBuffers.Test/TestProtos/UnittestWellKnownTypes.cs create mode 100644 csharp/src/ProtocolBuffers.Test/WellKnownTypes/WrappersTest.cs create mode 100644 src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc create mode 100644 src/google/protobuf/compiler/csharp/csharp_wrapper_field.h (limited to 'cmake/libprotoc.cmake') diff --git a/BUILD b/BUILD index 5177e43d..5cfed337 100644 --- a/BUILD +++ b/BUILD @@ -162,10 +162,10 @@ cc_library( "src/google/protobuf/compiler/cpp/cpp_string_field.cc", "src/google/protobuf/compiler/csharp/csharp_enum.cc", "src/google/protobuf/compiler/csharp/csharp_enum_field.cc", - "src/google/protobuf/compiler/csharp/csharp_extension.cc", "src/google/protobuf/compiler/csharp/csharp_field_base.cc", "src/google/protobuf/compiler/csharp/csharp_generator.cc", "src/google/protobuf/compiler/csharp/csharp_helpers.cc", + "src/google/protobuf/compiler/csharp/csharp_map_field.cc", "src/google/protobuf/compiler/csharp/csharp_message.cc", "src/google/protobuf/compiler/csharp/csharp_message_field.cc", "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc", @@ -174,7 +174,7 @@ cc_library( "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc", "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc", "src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc", - "src/google/protobuf/compiler/csharp/csharp_writer.cc", + "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc", "src/google/protobuf/compiler/java/java_context.cc", "src/google/protobuf/compiler/java/java_doc_comment.cc", "src/google/protobuf/compiler/java/java_enum.cc", diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 8bf0a1f3..f8fa7adb 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -28,6 +28,7 @@ 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_wrapper_field.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/generate_protos.sh b/csharp/generate_protos.sh index b7f837e1..7978166d 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -58,7 +58,8 @@ $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \ src/google/protobuf/map_unittest_proto3.proto \ src/google/protobuf/unittest_proto3.proto \ src/google/protobuf/unittest_import_proto3.proto \ - src/google/protobuf/unittest_import_public_proto3.proto + src/google/protobuf/unittest_import_public_proto3.proto \ + src/google/protobuf/unittest_well_known_types.proto $PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \ diff --git a/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 45c75bae..a425ad84 100644 --- a/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/csharp/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -93,6 +93,8 @@ + + diff --git a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestWellKnownTypes.cs b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestWellKnownTypes.cs new file mode 100644 index 00000000..a995b2c6 --- /dev/null +++ b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestWellKnownTypes.cs @@ -0,0 +1,2335 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/unittest_well_known_types.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Google.Protobuf.TestProtos { + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public static partial class UnittestWellKnownTypes { + + #region Static variables + internal static pbr::FieldAccessorTable internal__static_protobuf_unittest_TestWellKnownTypes__FieldAccessorTable; + internal static pbr::FieldAccessorTable internal__static_protobuf_unittest_RepeatedWellKnownTypes__FieldAccessorTable; + internal static pbr::FieldAccessorTable internal__static_protobuf_unittest_OneofWellKnownTypes__FieldAccessorTable; + internal static pbr::FieldAccessorTable internal__static_protobuf_unittest_MapWellKnownTypes__FieldAccessorTable; + #endregion + #region Descriptor + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static UnittestWellKnownTypes() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ci9nb29nbGUvcHJvdG9idWYvdW5pdHRlc3Rfd2VsbF9rbm93bl90eXBlcy5w", + "cm90bxIRcHJvdG9idWZfdW5pdHRlc3QaGWdvb2dsZS9wcm90b2J1Zi9hbnku", + "cHJvdG8aGWdvb2dsZS9wcm90b2J1Zi9hcGkucHJvdG8aHmdvb2dsZS9wcm90", + "b2J1Zi9kdXJhdGlvbi5wcm90bxobZ29vZ2xlL3Byb3RvYnVmL2VtcHR5LnBy", + "b3RvGiBnb29nbGUvcHJvdG9idWYvZmllbGRfbWFzay5wcm90bxokZ29vZ2xl", + "L3Byb3RvYnVmL3NvdXJjZV9jb250ZXh0LnByb3RvGhxnb29nbGUvcHJvdG9i", + "dWYvc3RydWN0LnByb3RvGh9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1wLnBy", + "b3RvGhpnb29nbGUvcHJvdG9idWYvdHlwZS5wcm90bxoeZ29vZ2xlL3Byb3Rv", + "YnVmL3dyYXBwZXJzLnByb3RvIpEHChJUZXN0V2VsbEtub3duVHlwZXMSJwoJ", + "YW55X2ZpZWxkGAEgASgLMhQuZ29vZ2xlLnByb3RvYnVmLkFueRInCglhcGlf", + "ZmllbGQYAiABKAsyFC5nb29nbGUucHJvdG9idWYuQXBpEjEKDmR1cmF0aW9u", + "X2ZpZWxkGAMgASgLMhkuZ29vZ2xlLnByb3RvYnVmLkR1cmF0aW9uEisKC2Vt", + "cHR5X2ZpZWxkGAQgASgLMhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5EjQKEGZp", + "ZWxkX21hc2tfZmllbGQYBSABKAsyGi5nb29nbGUucHJvdG9idWYuRmllbGRN", + "YXNrEjwKFHNvdXJjZV9jb250ZXh0X2ZpZWxkGAYgASgLMh4uZ29vZ2xlLnBy", + "b3RvYnVmLlNvdXJjZUNvbnRleHQSLQoMc3RydWN0X2ZpZWxkGAcgASgLMhcu", + "Z29vZ2xlLnByb3RvYnVmLlN0cnVjdBIzCg90aW1lc3RhbXBfZmllbGQYCCAB", + "KAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wEikKCnR5cGVfZmllbGQY", + "CSABKAsyFS5nb29nbGUucHJvdG9idWYuVHlwZRIyCgxkb3VibGVfZmllbGQY", + "CiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSMAoLZmxvYXRf", + "ZmllbGQYCyABKAsyGy5nb29nbGUucHJvdG9idWYuRmxvYXRWYWx1ZRIwCgtp", + "bnQ2NF9maWVsZBgMIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVl", + "EjIKDHVpbnQ2NF9maWVsZBgNIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5VSW50", + "NjRWYWx1ZRIwCgtpbnQzMl9maWVsZBgOIAEoCzIbLmdvb2dsZS5wcm90b2J1", + "Zi5JbnQzMlZhbHVlEjIKDHVpbnQzMl9maWVsZBgPIAEoCzIcLmdvb2dsZS5w", + "cm90b2J1Zi5VSW50MzJWYWx1ZRIuCgpib29sX2ZpZWxkGBAgASgLMhouZ29v", + "Z2xlLnByb3RvYnVmLkJvb2xWYWx1ZRIyCgxzdHJpbmdfZmllbGQYESABKAsy", + "HC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUSMAoLYnl0ZXNfZmllbGQY", + "EiABKAsyGy5nb29nbGUucHJvdG9idWYuQnl0ZXNWYWx1ZSLNAwoWUmVwZWF0", + "ZWRXZWxsS25vd25UeXBlcxInCglhbnlfZmllbGQYASADKAsyFC5nb29nbGUu", + "cHJvdG9idWYuQW55EicKCWFwaV9maWVsZBgCIAMoCzIULmdvb2dsZS5wcm90", + "b2J1Zi5BcGkSMQoOZHVyYXRpb25fZmllbGQYAyADKAsyGS5nb29nbGUucHJv", + "dG9idWYuRHVyYXRpb24SKwoLZW1wdHlfZmllbGQYBCADKAsyFi5nb29nbGUu", + "cHJvdG9idWYuRW1wdHkSNAoQZmllbGRfbWFza19maWVsZBgFIAMoCzIaLmdv", + "b2dsZS5wcm90b2J1Zi5GaWVsZE1hc2sSPAoUc291cmNlX2NvbnRleHRfZmll", + "bGQYBiADKAsyHi5nb29nbGUucHJvdG9idWYuU291cmNlQ29udGV4dBItCgxz", + "dHJ1Y3RfZmllbGQYByADKAsyFy5nb29nbGUucHJvdG9idWYuU3RydWN0EjMK", + "D3RpbWVzdGFtcF9maWVsZBgIIAMoCzIaLmdvb2dsZS5wcm90b2J1Zi5UaW1l", + "c3RhbXASKQoKdHlwZV9maWVsZBgJIAMoCzIVLmdvb2dsZS5wcm90b2J1Zi5U", + "eXBlIsUHChNPbmVvZldlbGxLbm93blR5cGVzEikKCWFueV9maWVsZBgBIAEo", + "CzIULmdvb2dsZS5wcm90b2J1Zi5BbnlIABIpCglhcGlfZmllbGQYAiABKAsy", + "FC5nb29nbGUucHJvdG9idWYuQXBpSAASMwoOZHVyYXRpb25fZmllbGQYAyAB", + "KAsyGS5nb29nbGUucHJvdG9idWYuRHVyYXRpb25IABItCgtlbXB0eV9maWVs", + "ZBgEIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5FbXB0eUgAEjYKEGZpZWxkX21h", + "c2tfZmllbGQYBSABKAsyGi5nb29nbGUucHJvdG9idWYuRmllbGRNYXNrSAAS", + "PgoUc291cmNlX2NvbnRleHRfZmllbGQYBiABKAsyHi5nb29nbGUucHJvdG9i", + "dWYuU291cmNlQ29udGV4dEgAEi8KDHN0cnVjdF9maWVsZBgHIAEoCzIXLmdv", + "b2dsZS5wcm90b2J1Zi5TdHJ1Y3RIABI1Cg90aW1lc3RhbXBfZmllbGQYCCAB", + "KAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wSAASKwoKdHlwZV9maWVs", + "ZBgJIAEoCzIVLmdvb2dsZS5wcm90b2J1Zi5UeXBlSAASNAoMZG91YmxlX2Zp", + "ZWxkGAogASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlSAASMgoL", + "ZmxvYXRfZmllbGQYCyABKAsyGy5nb29nbGUucHJvdG9idWYuRmxvYXRWYWx1", + "ZUgAEjIKC2ludDY0X2ZpZWxkGAwgASgLMhsuZ29vZ2xlLnByb3RvYnVmLklu", + "dDY0VmFsdWVIABI0Cgx1aW50NjRfZmllbGQYDSABKAsyHC5nb29nbGUucHJv", + "dG9idWYuVUludDY0VmFsdWVIABIyCgtpbnQzMl9maWVsZBgOIAEoCzIbLmdv", + "b2dsZS5wcm90b2J1Zi5JbnQzMlZhbHVlSAASNAoMdWludDMyX2ZpZWxkGA8g", + "ASgLMhwuZ29vZ2xlLnByb3RvYnVmLlVJbnQzMlZhbHVlSAASMAoKYm9vbF9m", + "aWVsZBgQIAEoCzIaLmdvb2dsZS5wcm90b2J1Zi5Cb29sVmFsdWVIABI0Cgxz", + "dHJpbmdfZmllbGQYESABKAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFs", + "dWVIABIyCgtieXRlc19maWVsZBgSIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5C", + "eXRlc1ZhbHVlSABCDQoLb25lb2ZfZmllbGQilhYKEU1hcFdlbGxLbm93blR5", + "cGVzEkUKCWFueV9maWVsZBgBIAMoCzIyLnByb3RvYnVmX3VuaXR0ZXN0Lk1h", + "cFdlbGxLbm93blR5cGVzLkFueUZpZWxkRW50cnkSRQoJYXBpX2ZpZWxkGAIg", + "AygLMjIucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3duVHlwZXMuQXBp", + "RmllbGRFbnRyeRJPCg5kdXJhdGlvbl9maWVsZBgDIAMoCzI3LnByb3RvYnVm", + "X3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkR1cmF0aW9uRmllbGRFbnRy", + "eRJJCgtlbXB0eV9maWVsZBgEIAMoCzI0LnByb3RvYnVmX3VuaXR0ZXN0Lk1h", + "cFdlbGxLbm93blR5cGVzLkVtcHR5RmllbGRFbnRyeRJSChBmaWVsZF9tYXNr", + "X2ZpZWxkGAUgAygLMjgucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3du", + "VHlwZXMuRmllbGRNYXNrRmllbGRFbnRyeRJaChRzb3VyY2VfY29udGV4dF9m", + "aWVsZBgGIAMoCzI8LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5", + "cGVzLlNvdXJjZUNvbnRleHRGaWVsZEVudHJ5EksKDHN0cnVjdF9maWVsZBgH", + "IAMoCzI1LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLlN0", + "cnVjdEZpZWxkRW50cnkSUQoPdGltZXN0YW1wX2ZpZWxkGAggAygLMjgucHJv", + "dG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3duVHlwZXMuVGltZXN0YW1wRmll", + "bGRFbnRyeRJHCgp0eXBlX2ZpZWxkGAkgAygLMjMucHJvdG9idWZfdW5pdHRl", + "c3QuTWFwV2VsbEtub3duVHlwZXMuVHlwZUZpZWxkRW50cnkSSwoMZG91Ymxl", + "X2ZpZWxkGAogAygLMjUucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3du", + "VHlwZXMuRG91YmxlRmllbGRFbnRyeRJJCgtmbG9hdF9maWVsZBgLIAMoCzI0", + "LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkZsb2F0Rmll", + "bGRFbnRyeRJJCgtpbnQ2NF9maWVsZBgMIAMoCzI0LnByb3RvYnVmX3VuaXR0", + "ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkludDY0RmllbGRFbnRyeRJLCgx1aW50", + "NjRfZmllbGQYDSADKAsyNS5wcm90b2J1Zl91bml0dGVzdC5NYXBXZWxsS25v", + "d25UeXBlcy5VaW50NjRGaWVsZEVudHJ5EkkKC2ludDMyX2ZpZWxkGA4gAygL", + "MjQucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3duVHlwZXMuSW50MzJG", + "aWVsZEVudHJ5EksKDHVpbnQzMl9maWVsZBgPIAMoCzI1LnByb3RvYnVmX3Vu", + "aXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLlVpbnQzMkZpZWxkRW50cnkSRwoK", + "Ym9vbF9maWVsZBgQIAMoCzIzLnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxL", + "bm93blR5cGVzLkJvb2xGaWVsZEVudHJ5EksKDHN0cmluZ19maWVsZBgRIAMo", + "CzI1LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLlN0cmlu", + "Z0ZpZWxkRW50cnkSSQoLYnl0ZXNfZmllbGQYEiADKAsyNC5wcm90b2J1Zl91", + "bml0dGVzdC5NYXBXZWxsS25vd25UeXBlcy5CeXRlc0ZpZWxkRW50cnkaRQoN", + "QW55RmllbGRFbnRyeRILCgNrZXkYASABKAUSIwoFdmFsdWUYAiABKAsyFC5n", + "b29nbGUucHJvdG9idWYuQW55OgI4ARpFCg1BcGlGaWVsZEVudHJ5EgsKA2tl", + "eRgBIAEoBRIjCgV2YWx1ZRgCIAEoCzIULmdvb2dsZS5wcm90b2J1Zi5BcGk6", + "AjgBGk8KEkR1cmF0aW9uRmllbGRFbnRyeRILCgNrZXkYASABKAUSKAoFdmFs", + "dWUYAiABKAsyGS5nb29nbGUucHJvdG9idWYuRHVyYXRpb246AjgBGkkKD0Vt", + "cHR5RmllbGRFbnRyeRILCgNrZXkYASABKAUSJQoFdmFsdWUYAiABKAsyFi5n", + "b29nbGUucHJvdG9idWYuRW1wdHk6AjgBGlEKE0ZpZWxkTWFza0ZpZWxkRW50", + "cnkSCwoDa2V5GAEgASgFEikKBXZhbHVlGAIgASgLMhouZ29vZ2xlLnByb3Rv", + "YnVmLkZpZWxkTWFzazoCOAEaWQoXU291cmNlQ29udGV4dEZpZWxkRW50cnkS", + "CwoDa2V5GAEgASgFEi0KBXZhbHVlGAIgASgLMh4uZ29vZ2xlLnByb3RvYnVm", + "LlNvdXJjZUNvbnRleHQ6AjgBGksKEFN0cnVjdEZpZWxkRW50cnkSCwoDa2V5", + "GAEgASgFEiYKBXZhbHVlGAIgASgLMhcuZ29vZ2xlLnByb3RvYnVmLlN0cnVj", + "dDoCOAEaUQoTVGltZXN0YW1wRmllbGRFbnRyeRILCgNrZXkYASABKAUSKQoF", + "dmFsdWUYAiABKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wOgI4ARpH", + "Cg5UeXBlRmllbGRFbnRyeRILCgNrZXkYASABKAUSJAoFdmFsdWUYAiABKAsy", + "FS5nb29nbGUucHJvdG9idWYuVHlwZToCOAEaUAoQRG91YmxlRmllbGRFbnRy", + "eRILCgNrZXkYASABKAUSKwoFdmFsdWUYAiABKAsyHC5nb29nbGUucHJvdG9i", + "dWYuRG91YmxlVmFsdWU6AjgBGk4KD0Zsb2F0RmllbGRFbnRyeRILCgNrZXkY", + "ASABKAUSKgoFdmFsdWUYAiABKAsyGy5nb29nbGUucHJvdG9idWYuRmxvYXRW", + "YWx1ZToCOAEaTgoPSW50NjRGaWVsZEVudHJ5EgsKA2tleRgBIAEoBRIqCgV2", + "YWx1ZRgCIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlOgI4ARpQ", + "ChBVaW50NjRGaWVsZEVudHJ5EgsKA2tleRgBIAEoBRIrCgV2YWx1ZRgCIAEo", + "CzIcLmdvb2dsZS5wcm90b2J1Zi5VSW50NjRWYWx1ZToCOAEaTgoPSW50MzJG", + "aWVsZEVudHJ5EgsKA2tleRgBIAEoBRIqCgV2YWx1ZRgCIAEoCzIbLmdvb2ds", + "ZS5wcm90b2J1Zi5JbnQzMlZhbHVlOgI4ARpQChBVaW50MzJGaWVsZEVudHJ5", + "EgsKA2tleRgBIAEoBRIrCgV2YWx1ZRgCIAEoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5VSW50MzJWYWx1ZToCOAEaTAoOQm9vbEZpZWxkRW50cnkSCwoDa2V5GAEg", + "ASgFEikKBXZhbHVlGAIgASgLMhouZ29vZ2xlLnByb3RvYnVmLkJvb2xWYWx1", + "ZToCOAEaUAoQU3RyaW5nRmllbGRFbnRyeRILCgNrZXkYASABKAUSKwoFdmFs", + "dWUYAiABKAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWU6AjgBGk4K", + "D0J5dGVzRmllbGRFbnRyeRILCgNrZXkYASABKAUSKgoFdmFsdWUYAiABKAsy", + "Gy5nb29nbGUucHJvdG9idWYuQnl0ZXNWYWx1ZToCOAFCOQoYY29tLmdvb2ds", + "ZS5wcm90b2J1Zi50ZXN0UAGqAhpHb29nbGUuUHJvdG9idWYuVGVzdFByb3Rv", + "c2IGcHJvdG8z")); + descriptor = pbr::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, + new pbr::FileDescriptor[] { + global::Google.Protobuf.WellKnownTypes.Proto.Any.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.Api.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.Duration.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.Empty.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.FieldMask.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.SourceContext.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.Struct.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.Timestamp.Descriptor, + global::Google.Protobuf.WellKnownTypes.Proto.Type.Descriptor, + global::Google.Protobuf.WellKnownTypes.Wrappers.Descriptor, + }); + internal__static_protobuf_unittest_TestWellKnownTypes__FieldAccessorTable = + new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.TestProtos.TestWellKnownTypes), descriptor.MessageTypes[0], + new string[] { "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField", }, new string[] { }); + internal__static_protobuf_unittest_RepeatedWellKnownTypes__FieldAccessorTable = + new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.TestProtos.RepeatedWellKnownTypes), descriptor.MessageTypes[1], + new string[] { "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", }, new string[] { }); + internal__static_protobuf_unittest_OneofWellKnownTypes__FieldAccessorTable = + new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.TestProtos.OneofWellKnownTypes), descriptor.MessageTypes[2], + new string[] { "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField", }, new string[] { "OneofField", }); + internal__static_protobuf_unittest_MapWellKnownTypes__FieldAccessorTable = + new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.TestProtos.MapWellKnownTypes), descriptor.MessageTypes[3], + new string[] { "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField", }, new string[] { }); + } + #endregion + + } + #region Messages + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class TestWellKnownTypes : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestWellKnownTypes()); + public static pb::MessageParser Parser { get { return _parser; } } + + private static readonly string[] _fieldNames = new string[] { "any_field", "api_field", "bool_field", "bytes_field", "double_field", "duration_field", "empty_field", "field_mask_field", "float_field", "int32_field", "int64_field", "source_context_field", "string_field", "struct_field", "timestamp_field", "type_field", "uint32_field", "uint64_field" }; + private static readonly uint[] _fieldTags = new uint[] { 10, 18, 130, 146, 82, 26, 34, 42, 90, 114, 98, 50, 138, 58, 66, 74, 122, 106 }; + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.Descriptor.MessageTypes[0]; } + } + + pbr::FieldAccessorTable pb::IReflectedMessage.Fields { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.internal__static_protobuf_unittest_TestWellKnownTypes__FieldAccessorTable; } + } + + private bool _frozen = false; + public bool IsFrozen { get { return _frozen; } } + + public TestWellKnownTypes() { + OnConstruction(); + } + + partial void OnConstruction(); + + public TestWellKnownTypes(TestWellKnownTypes other) : this() { + AnyField = other.anyField_ != null ? other.AnyField.Clone() : null; + ApiField = other.apiField_ != null ? other.ApiField.Clone() : null; + DurationField = other.durationField_ != null ? other.DurationField.Clone() : null; + EmptyField = other.emptyField_ != null ? other.EmptyField.Clone() : null; + FieldMaskField = other.fieldMaskField_ != null ? other.FieldMaskField.Clone() : null; + SourceContextField = other.sourceContextField_ != null ? other.SourceContextField.Clone() : null; + StructField = other.structField_ != null ? other.StructField.Clone() : null; + TimestampField = other.timestampField_ != null ? other.TimestampField.Clone() : null; + TypeField = other.typeField_ != null ? other.TypeField.Clone() : null; + DoubleField = other.DoubleField; + FloatField = other.FloatField; + Int64Field = other.Int64Field; + Uint64Field = other.Uint64Field; + Int32Field = other.Int32Field; + Uint32Field = other.Uint32Field; + BoolField = other.BoolField; + StringField = other.StringField; + BytesField = other.BytesField; + } + + public TestWellKnownTypes Clone() { + return new TestWellKnownTypes(this); + } + + public void Freeze() { + if (IsFrozen) { + return; + } + _frozen = true; + if (anyField_ != null) AnyField.Freeze(); + if (apiField_ != null) ApiField.Freeze(); + if (durationField_ != null) DurationField.Freeze(); + if (emptyField_ != null) EmptyField.Freeze(); + if (fieldMaskField_ != null) FieldMaskField.Freeze(); + if (sourceContextField_ != null) SourceContextField.Freeze(); + if (structField_ != null) StructField.Freeze(); + if (timestampField_ != null) TimestampField.Freeze(); + if (typeField_ != null) TypeField.Freeze(); + } + + public const int AnyFieldFieldNumber = 1; + private global::Google.Protobuf.WellKnownTypes.Any anyField_; + public global::Google.Protobuf.WellKnownTypes.Any AnyField { + get { return anyField_; } + set { + pb::Freezable.CheckMutable(this); + anyField_ = value; + } + } + + public const int ApiFieldFieldNumber = 2; + private global::Google.Protobuf.WellKnownTypes.Api apiField_; + public global::Google.Protobuf.WellKnownTypes.Api ApiField { + get { return apiField_; } + set { + pb::Freezable.CheckMutable(this); + apiField_ = value; + } + } + + public const int DurationFieldFieldNumber = 3; + private global::Google.Protobuf.WellKnownTypes.Duration durationField_; + public global::Google.Protobuf.WellKnownTypes.Duration DurationField { + get { return durationField_; } + set { + pb::Freezable.CheckMutable(this); + durationField_ = value; + } + } + + public const int EmptyFieldFieldNumber = 4; + private global::Google.Protobuf.WellKnownTypes.Empty emptyField_; + public global::Google.Protobuf.WellKnownTypes.Empty EmptyField { + get { return emptyField_; } + set { + pb::Freezable.CheckMutable(this); + emptyField_ = value; + } + } + + public const int FieldMaskFieldFieldNumber = 5; + private global::Google.Protobuf.WellKnownTypes.FieldMask fieldMaskField_; + public global::Google.Protobuf.WellKnownTypes.FieldMask FieldMaskField { + get { return fieldMaskField_; } + set { + pb::Freezable.CheckMutable(this); + fieldMaskField_ = value; + } + } + + public const int SourceContextFieldFieldNumber = 6; + private global::Google.Protobuf.WellKnownTypes.SourceContext sourceContextField_; + public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContextField { + get { return sourceContextField_; } + set { + pb::Freezable.CheckMutable(this); + sourceContextField_ = value; + } + } + + public const int StructFieldFieldNumber = 7; + private global::Google.Protobuf.WellKnownTypes.Struct structField_; + public global::Google.Protobuf.WellKnownTypes.Struct StructField { + get { return structField_; } + set { + pb::Freezable.CheckMutable(this); + structField_ = value; + } + } + + public const int TimestampFieldFieldNumber = 8; + private global::Google.Protobuf.WellKnownTypes.Timestamp timestampField_; + public global::Google.Protobuf.WellKnownTypes.Timestamp TimestampField { + get { return timestampField_; } + set { + pb::Freezable.CheckMutable(this); + timestampField_ = value; + } + } + + public const int TypeFieldFieldNumber = 9; + private global::Google.Protobuf.WellKnownTypes.Type typeField_; + public global::Google.Protobuf.WellKnownTypes.Type TypeField { + get { return typeField_; } + set { + pb::Freezable.CheckMutable(this); + typeField_ = value; + } + } + + public const int DoubleFieldFieldNumber = 10; + private global::Google.Protobuf.WellKnownTypes.DoubleValue doubleField_; + public double? DoubleField { + get { return doubleField_ == null ? (double?) null : doubleField_.Value; } + set { + pb::Freezable.CheckMutable(this); + doubleField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.DoubleValue { Value = value.Value }; + } + } + + public const int FloatFieldFieldNumber = 11; + private global::Google.Protobuf.WellKnownTypes.FloatValue floatField_; + public float? FloatField { + get { return floatField_ == null ? (float?) null : floatField_.Value; } + set { + pb::Freezable.CheckMutable(this); + floatField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.FloatValue { Value = value.Value }; + } + } + + public const int Int64FieldFieldNumber = 12; + private global::Google.Protobuf.WellKnownTypes.Int64Value int64Field_; + public long? Int64Field { + get { return int64Field_ == null ? (long?) null : int64Field_.Value; } + set { + pb::Freezable.CheckMutable(this); + int64Field_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.Int64Value { Value = value.Value }; + } + } + + public const int Uint64FieldFieldNumber = 13; + private global::Google.Protobuf.WellKnownTypes.UInt64Value uint64Field_; + public ulong? Uint64Field { + get { return uint64Field_ == null ? (ulong?) null : uint64Field_.Value; } + set { + pb::Freezable.CheckMutable(this); + uint64Field_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.UInt64Value { Value = value.Value }; + } + } + + public const int Int32FieldFieldNumber = 14; + private global::Google.Protobuf.WellKnownTypes.Int32Value int32Field_; + public int? Int32Field { + get { return int32Field_ == null ? (int?) null : int32Field_.Value; } + set { + pb::Freezable.CheckMutable(this); + int32Field_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.Int32Value { Value = value.Value }; + } + } + + public const int Uint32FieldFieldNumber = 15; + private global::Google.Protobuf.WellKnownTypes.UInt32Value uint32Field_; + public uint? Uint32Field { + get { return uint32Field_ == null ? (uint?) null : uint32Field_.Value; } + set { + pb::Freezable.CheckMutable(this); + uint32Field_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.UInt32Value { Value = value.Value }; + } + } + + public const int BoolFieldFieldNumber = 16; + private global::Google.Protobuf.WellKnownTypes.BoolValue boolField_; + public bool? BoolField { + get { return boolField_ == null ? (bool?) null : boolField_.Value; } + set { + pb::Freezable.CheckMutable(this); + boolField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.BoolValue { Value = value.Value }; + } + } + + public const int StringFieldFieldNumber = 17; + private global::Google.Protobuf.WellKnownTypes.StringValue stringField_; + public string StringField { + get { return stringField_ == null ? (string) null : stringField_.Value; } + set { + pb::Freezable.CheckMutable(this); + stringField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.StringValue { Value = value }; + } + } + + public const int BytesFieldFieldNumber = 18; + private global::Google.Protobuf.WellKnownTypes.BytesValue bytesField_; + public pb::ByteString BytesField { + get { return bytesField_ == null ? (pb::ByteString) null : bytesField_.Value; } + set { + pb::Freezable.CheckMutable(this); + bytesField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.BytesValue { Value = value }; + } + } + + public override bool Equals(object other) { + return Equals(other as TestWellKnownTypes); + } + + public bool Equals(TestWellKnownTypes other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!object.Equals(AnyField, other.AnyField)) return false; + if (!object.Equals(ApiField, other.ApiField)) return false; + if (!object.Equals(DurationField, other.DurationField)) return false; + if (!object.Equals(EmptyField, other.EmptyField)) return false; + if (!object.Equals(FieldMaskField, other.FieldMaskField)) return false; + if (!object.Equals(SourceContextField, other.SourceContextField)) return false; + if (!object.Equals(StructField, other.StructField)) return false; + if (!object.Equals(TimestampField, other.TimestampField)) return false; + if (!object.Equals(TypeField, other.TypeField)) return false; + if (DoubleField != other.DoubleField) return false; + if (FloatField != other.FloatField) return false; + if (Int64Field != other.Int64Field) return false; + if (Uint64Field != other.Uint64Field) return false; + if (Int32Field != other.Int32Field) return false; + if (Uint32Field != other.Uint32Field) return false; + if (BoolField != other.BoolField) return false; + if (StringField != other.StringField) return false; + if (BytesField != other.BytesField) return false; + return true; + } + + public override int GetHashCode() { + int hash = 1; + if (anyField_ != null) hash ^= AnyField.GetHashCode(); + if (apiField_ != null) hash ^= ApiField.GetHashCode(); + if (durationField_ != null) hash ^= DurationField.GetHashCode(); + if (emptyField_ != null) hash ^= EmptyField.GetHashCode(); + if (fieldMaskField_ != null) hash ^= FieldMaskField.GetHashCode(); + if (sourceContextField_ != null) hash ^= SourceContextField.GetHashCode(); + if (structField_ != null) hash ^= StructField.GetHashCode(); + if (timestampField_ != null) hash ^= TimestampField.GetHashCode(); + if (typeField_ != null) hash ^= TypeField.GetHashCode(); + if (doubleField_ != null) hash ^= DoubleField.GetHashCode(); + if (floatField_ != null) hash ^= FloatField.GetHashCode(); + if (int64Field_ != null) hash ^= Int64Field.GetHashCode(); + if (uint64Field_ != null) hash ^= Uint64Field.GetHashCode(); + if (int32Field_ != null) hash ^= Int32Field.GetHashCode(); + if (uint32Field_ != null) hash ^= Uint32Field.GetHashCode(); + if (boolField_ != null) hash ^= BoolField.GetHashCode(); + if (stringField_ != null) hash ^= StringField.GetHashCode(); + if (bytesField_ != null) hash ^= BytesField.GetHashCode(); + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + if (anyField_ != null) { + output.WriteRawTag(10); + output.WriteMessage(AnyField); + } + if (apiField_ != null) { + output.WriteRawTag(18); + output.WriteMessage(ApiField); + } + if (durationField_ != null) { + output.WriteRawTag(26); + output.WriteMessage(DurationField); + } + if (emptyField_ != null) { + output.WriteRawTag(34); + output.WriteMessage(EmptyField); + } + if (fieldMaskField_ != null) { + output.WriteRawTag(42); + output.WriteMessage(FieldMaskField); + } + if (sourceContextField_ != null) { + output.WriteRawTag(50); + output.WriteMessage(SourceContextField); + } + if (structField_ != null) { + output.WriteRawTag(58); + output.WriteMessage(StructField); + } + if (timestampField_ != null) { + output.WriteRawTag(66); + output.WriteMessage(TimestampField); + } + if (typeField_ != null) { + output.WriteRawTag(74); + output.WriteMessage(TypeField); + } + if (doubleField_ != null) { + output.WriteRawTag(82); + output.WriteMessage(doubleField_); + } + if (floatField_ != null) { + output.WriteRawTag(90); + output.WriteMessage(floatField_); + } + if (int64Field_ != null) { + output.WriteRawTag(98); + output.WriteMessage(int64Field_); + } + if (uint64Field_ != null) { + output.WriteRawTag(106); + output.WriteMessage(uint64Field_); + } + if (int32Field_ != null) { + output.WriteRawTag(114); + output.WriteMessage(int32Field_); + } + if (uint32Field_ != null) { + output.WriteRawTag(122); + output.WriteMessage(uint32Field_); + } + if (boolField_ != null) { + output.WriteRawTag(130, 1); + output.WriteMessage(boolField_); + } + if (stringField_ != null) { + output.WriteRawTag(138, 1); + output.WriteMessage(stringField_); + } + if (bytesField_ != null) { + output.WriteRawTag(146, 1); + output.WriteMessage(bytesField_); + } + } + + public int CalculateSize() { + int size = 0; + if (anyField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(AnyField); + } + if (apiField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(ApiField); + } + if (durationField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(DurationField); + } + if (emptyField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(EmptyField); + } + if (fieldMaskField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(FieldMaskField); + } + if (sourceContextField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContextField); + } + if (structField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(StructField); + } + if (timestampField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(TimestampField); + } + if (typeField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(TypeField); + } + if (doubleField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(doubleField_); + } + if (floatField_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(floatField_); + } + if (int64Field_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(int64Field_); + } + if (uint64Field_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(uint64Field_); + } + if (int32Field_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(int32Field_); + } + if (uint32Field_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(uint32Field_); + } + if (boolField_ != null) { + size += 2 + pb::CodedOutputStream.ComputeMessageSize(boolField_); + } + if (stringField_ != null) { + size += 2 + pb::CodedOutputStream.ComputeMessageSize(stringField_); + } + if (bytesField_ != null) { + size += 2 + pb::CodedOutputStream.ComputeMessageSize(bytesField_); + } + return size; + } + + public void MergeFrom(TestWellKnownTypes other) { + if (other == null) { + return; + } + if (other.anyField_ != null) { + if (anyField_ == null) { + anyField_ = new global::Google.Protobuf.WellKnownTypes.Any(); + } + AnyField.MergeFrom(other.AnyField); + } + if (other.apiField_ != null) { + if (apiField_ == null) { + apiField_ = new global::Google.Protobuf.WellKnownTypes.Api(); + } + ApiField.MergeFrom(other.ApiField); + } + if (other.durationField_ != null) { + if (durationField_ == null) { + durationField_ = new global::Google.Protobuf.WellKnownTypes.Duration(); + } + DurationField.MergeFrom(other.DurationField); + } + if (other.emptyField_ != null) { + if (emptyField_ == null) { + emptyField_ = new global::Google.Protobuf.WellKnownTypes.Empty(); + } + EmptyField.MergeFrom(other.EmptyField); + } + if (other.fieldMaskField_ != null) { + if (fieldMaskField_ == null) { + fieldMaskField_ = new global::Google.Protobuf.WellKnownTypes.FieldMask(); + } + FieldMaskField.MergeFrom(other.FieldMaskField); + } + if (other.sourceContextField_ != null) { + if (sourceContextField_ == null) { + sourceContextField_ = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + } + SourceContextField.MergeFrom(other.SourceContextField); + } + if (other.structField_ != null) { + if (structField_ == null) { + structField_ = new global::Google.Protobuf.WellKnownTypes.Struct(); + } + StructField.MergeFrom(other.StructField); + } + if (other.timestampField_ != null) { + if (timestampField_ == null) { + timestampField_ = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + } + TimestampField.MergeFrom(other.TimestampField); + } + if (other.typeField_ != null) { + if (typeField_ == null) { + typeField_ = new global::Google.Protobuf.WellKnownTypes.Type(); + } + TypeField.MergeFrom(other.TypeField); + } + if (other.doubleField_ != null) { + if (doubleField_ == null) { + doubleField_ = new global::Google.Protobuf.WellKnownTypes.DoubleValue(); + } + doubleField_.MergeFrom(other.doubleField_); + } + if (other.floatField_ != null) { + if (floatField_ == null) { + floatField_ = new global::Google.Protobuf.WellKnownTypes.FloatValue(); + } + floatField_.MergeFrom(other.floatField_); + } + if (other.int64Field_ != null) { + if (int64Field_ == null) { + int64Field_ = new global::Google.Protobuf.WellKnownTypes.Int64Value(); + } + int64Field_.MergeFrom(other.int64Field_); + } + if (other.uint64Field_ != null) { + if (uint64Field_ == null) { + uint64Field_ = new global::Google.Protobuf.WellKnownTypes.UInt64Value(); + } + uint64Field_.MergeFrom(other.uint64Field_); + } + if (other.int32Field_ != null) { + if (int32Field_ == null) { + int32Field_ = new global::Google.Protobuf.WellKnownTypes.Int32Value(); + } + int32Field_.MergeFrom(other.int32Field_); + } + if (other.uint32Field_ != null) { + if (uint32Field_ == null) { + uint32Field_ = new global::Google.Protobuf.WellKnownTypes.UInt32Value(); + } + uint32Field_.MergeFrom(other.uint32Field_); + } + if (other.boolField_ != null) { + if (boolField_ == null) { + boolField_ = new global::Google.Protobuf.WellKnownTypes.BoolValue(); + } + boolField_.MergeFrom(other.boolField_); + } + if (other.stringField_ != null) { + if (stringField_ == null) { + stringField_ = new global::Google.Protobuf.WellKnownTypes.StringValue(); + } + stringField_.MergeFrom(other.stringField_); + } + if (other.bytesField_ != null) { + if (bytesField_ == null) { + bytesField_ = new global::Google.Protobuf.WellKnownTypes.BytesValue(); + } + bytesField_.MergeFrom(other.bytesField_); + } + } + + 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: { + if (anyField_ == null) { + anyField_ = new global::Google.Protobuf.WellKnownTypes.Any(); + } + input.ReadMessage(anyField_); + break; + } + case 18: { + if (apiField_ == null) { + apiField_ = new global::Google.Protobuf.WellKnownTypes.Api(); + } + input.ReadMessage(apiField_); + break; + } + case 26: { + if (durationField_ == null) { + durationField_ = new global::Google.Protobuf.WellKnownTypes.Duration(); + } + input.ReadMessage(durationField_); + break; + } + case 34: { + if (emptyField_ == null) { + emptyField_ = new global::Google.Protobuf.WellKnownTypes.Empty(); + } + input.ReadMessage(emptyField_); + break; + } + case 42: { + if (fieldMaskField_ == null) { + fieldMaskField_ = new global::Google.Protobuf.WellKnownTypes.FieldMask(); + } + input.ReadMessage(fieldMaskField_); + break; + } + case 50: { + if (sourceContextField_ == null) { + sourceContextField_ = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(sourceContextField_); + break; + } + case 58: { + if (structField_ == null) { + structField_ = new global::Google.Protobuf.WellKnownTypes.Struct(); + } + input.ReadMessage(structField_); + break; + } + case 66: { + if (timestampField_ == null) { + timestampField_ = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + } + input.ReadMessage(timestampField_); + break; + } + case 74: { + if (typeField_ == null) { + typeField_ = new global::Google.Protobuf.WellKnownTypes.Type(); + } + input.ReadMessage(typeField_); + break; + } + case 82: { + if (doubleField_ == null) { + doubleField_ = new global::Google.Protobuf.WellKnownTypes.DoubleValue(); + } + input.ReadMessage(doubleField_); + break; + } + case 90: { + if (floatField_ == null) { + floatField_ = new global::Google.Protobuf.WellKnownTypes.FloatValue(); + } + input.ReadMessage(floatField_); + break; + } + case 98: { + if (int64Field_ == null) { + int64Field_ = new global::Google.Protobuf.WellKnownTypes.Int64Value(); + } + input.ReadMessage(int64Field_); + break; + } + case 106: { + if (uint64Field_ == null) { + uint64Field_ = new global::Google.Protobuf.WellKnownTypes.UInt64Value(); + } + input.ReadMessage(uint64Field_); + break; + } + case 114: { + if (int32Field_ == null) { + int32Field_ = new global::Google.Protobuf.WellKnownTypes.Int32Value(); + } + input.ReadMessage(int32Field_); + break; + } + case 122: { + if (uint32Field_ == null) { + uint32Field_ = new global::Google.Protobuf.WellKnownTypes.UInt32Value(); + } + input.ReadMessage(uint32Field_); + break; + } + case 130: { + if (boolField_ == null) { + boolField_ = new global::Google.Protobuf.WellKnownTypes.BoolValue(); + } + input.ReadMessage(boolField_); + break; + } + case 138: { + if (stringField_ == null) { + stringField_ = new global::Google.Protobuf.WellKnownTypes.StringValue(); + } + input.ReadMessage(stringField_); + break; + } + case 146: { + if (bytesField_ == null) { + bytesField_ = new global::Google.Protobuf.WellKnownTypes.BytesValue(); + } + input.ReadMessage(bytesField_); + break; + } + } + } + } + + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class RepeatedWellKnownTypes : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RepeatedWellKnownTypes()); + public static pb::MessageParser Parser { get { return _parser; } } + + private static readonly string[] _fieldNames = new string[] { "any_field", "api_field", "duration_field", "empty_field", "field_mask_field", "source_context_field", "struct_field", "timestamp_field", "type_field" }; + private static readonly uint[] _fieldTags = new uint[] { 10, 18, 26, 34, 42, 50, 58, 66, 74 }; + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.Descriptor.MessageTypes[1]; } + } + + pbr::FieldAccessorTable pb::IReflectedMessage.Fields { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.internal__static_protobuf_unittest_RepeatedWellKnownTypes__FieldAccessorTable; } + } + + private bool _frozen = false; + public bool IsFrozen { get { return _frozen; } } + + public RepeatedWellKnownTypes() { + OnConstruction(); + } + + partial void OnConstruction(); + + public RepeatedWellKnownTypes(RepeatedWellKnownTypes other) : this() { + anyField_ = other.anyField_.Clone(); + apiField_ = other.apiField_.Clone(); + durationField_ = other.durationField_.Clone(); + emptyField_ = other.emptyField_.Clone(); + fieldMaskField_ = other.fieldMaskField_.Clone(); + sourceContextField_ = other.sourceContextField_.Clone(); + structField_ = other.structField_.Clone(); + timestampField_ = other.timestampField_.Clone(); + typeField_ = other.typeField_.Clone(); + } + + public RepeatedWellKnownTypes Clone() { + return new RepeatedWellKnownTypes(this); + } + + public void Freeze() { + if (IsFrozen) { + return; + } + _frozen = true; + anyField_.Freeze(); + apiField_.Freeze(); + durationField_.Freeze(); + emptyField_.Freeze(); + fieldMaskField_.Freeze(); + sourceContextField_.Freeze(); + structField_.Freeze(); + timestampField_.Freeze(); + typeField_.Freeze(); + } + + public const int AnyFieldFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_anyField_codec + = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.WellKnownTypes.Any.Parser); + private readonly pbc::RepeatedField anyField_ = new pbc::RepeatedField(); + public pbc::RepeatedField AnyField { + get { return anyField_; } + } + + public const int ApiFieldFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_apiField_codec + = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Api.Parser); + private readonly pbc::RepeatedField apiField_ = new pbc::RepeatedField(); + public pbc::RepeatedField ApiField { + get { return apiField_; } + } + + public const int DurationFieldFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_durationField_codec + = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.WellKnownTypes.Duration.Parser); + private readonly pbc::RepeatedField durationField_ = new pbc::RepeatedField(); + public pbc::RepeatedField DurationField { + get { return durationField_; } + } + + public const int EmptyFieldFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_emptyField_codec + = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.WellKnownTypes.Empty.Parser); + private readonly pbc::RepeatedField emptyField_ = new pbc::RepeatedField(); + public pbc::RepeatedField EmptyField { + get { return emptyField_; } + } + + public const int FieldMaskFieldFieldNumber = 5; + private static readonly pb::FieldCodec _repeated_fieldMaskField_codec + = pb::FieldCodec.ForMessage(42, global::Google.Protobuf.WellKnownTypes.FieldMask.Parser); + private readonly pbc::RepeatedField fieldMaskField_ = new pbc::RepeatedField(); + public pbc::RepeatedField FieldMaskField { + get { return fieldMaskField_; } + } + + public const int SourceContextFieldFieldNumber = 6; + private static readonly pb::FieldCodec _repeated_sourceContextField_codec + = pb::FieldCodec.ForMessage(50, global::Google.Protobuf.WellKnownTypes.SourceContext.Parser); + private readonly pbc::RepeatedField sourceContextField_ = new pbc::RepeatedField(); + public pbc::RepeatedField SourceContextField { + get { return sourceContextField_; } + } + + public const int StructFieldFieldNumber = 7; + private static readonly pb::FieldCodec _repeated_structField_codec + = pb::FieldCodec.ForMessage(58, global::Google.Protobuf.WellKnownTypes.Struct.Parser); + private readonly pbc::RepeatedField structField_ = new pbc::RepeatedField(); + public pbc::RepeatedField StructField { + get { return structField_; } + } + + public const int TimestampFieldFieldNumber = 8; + private static readonly pb::FieldCodec _repeated_timestampField_codec + = pb::FieldCodec.ForMessage(66, global::Google.Protobuf.WellKnownTypes.Timestamp.Parser); + private readonly pbc::RepeatedField timestampField_ = new pbc::RepeatedField(); + public pbc::RepeatedField TimestampField { + get { return timestampField_; } + } + + public const int TypeFieldFieldNumber = 9; + private static readonly pb::FieldCodec _repeated_typeField_codec + = pb::FieldCodec.ForMessage(74, global::Google.Protobuf.WellKnownTypes.Type.Parser); + private readonly pbc::RepeatedField typeField_ = new pbc::RepeatedField(); + public pbc::RepeatedField TypeField { + get { return typeField_; } + } + + public override bool Equals(object other) { + return Equals(other as RepeatedWellKnownTypes); + } + + public bool Equals(RepeatedWellKnownTypes other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!anyField_.Equals(other.anyField_)) return false; + if(!apiField_.Equals(other.apiField_)) return false; + if(!durationField_.Equals(other.durationField_)) return false; + if(!emptyField_.Equals(other.emptyField_)) return false; + if(!fieldMaskField_.Equals(other.fieldMaskField_)) return false; + if(!sourceContextField_.Equals(other.sourceContextField_)) return false; + if(!structField_.Equals(other.structField_)) return false; + if(!timestampField_.Equals(other.timestampField_)) return false; + if(!typeField_.Equals(other.typeField_)) return false; + return true; + } + + public override int GetHashCode() { + int hash = 1; + hash ^= anyField_.GetHashCode(); + hash ^= apiField_.GetHashCode(); + hash ^= durationField_.GetHashCode(); + hash ^= emptyField_.GetHashCode(); + hash ^= fieldMaskField_.GetHashCode(); + hash ^= sourceContextField_.GetHashCode(); + hash ^= structField_.GetHashCode(); + hash ^= timestampField_.GetHashCode(); + hash ^= typeField_.GetHashCode(); + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + anyField_.WriteTo(output, _repeated_anyField_codec); + apiField_.WriteTo(output, _repeated_apiField_codec); + durationField_.WriteTo(output, _repeated_durationField_codec); + emptyField_.WriteTo(output, _repeated_emptyField_codec); + fieldMaskField_.WriteTo(output, _repeated_fieldMaskField_codec); + sourceContextField_.WriteTo(output, _repeated_sourceContextField_codec); + structField_.WriteTo(output, _repeated_structField_codec); + timestampField_.WriteTo(output, _repeated_timestampField_codec); + typeField_.WriteTo(output, _repeated_typeField_codec); + } + + public int CalculateSize() { + int size = 0; + size += anyField_.CalculateSize(_repeated_anyField_codec); + size += apiField_.CalculateSize(_repeated_apiField_codec); + size += durationField_.CalculateSize(_repeated_durationField_codec); + size += emptyField_.CalculateSize(_repeated_emptyField_codec); + size += fieldMaskField_.CalculateSize(_repeated_fieldMaskField_codec); + size += sourceContextField_.CalculateSize(_repeated_sourceContextField_codec); + size += structField_.CalculateSize(_repeated_structField_codec); + size += timestampField_.CalculateSize(_repeated_timestampField_codec); + size += typeField_.CalculateSize(_repeated_typeField_codec); + return size; + } + + public void MergeFrom(RepeatedWellKnownTypes other) { + if (other == null) { + return; + } + anyField_.Add(other.anyField_); + apiField_.Add(other.apiField_); + durationField_.Add(other.durationField_); + emptyField_.Add(other.emptyField_); + fieldMaskField_.Add(other.fieldMaskField_); + sourceContextField_.Add(other.sourceContextField_); + structField_.Add(other.structField_); + timestampField_.Add(other.timestampField_); + typeField_.Add(other.typeField_); + } + + 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: { + anyField_.AddEntriesFrom(input, _repeated_anyField_codec); + break; + } + case 18: { + apiField_.AddEntriesFrom(input, _repeated_apiField_codec); + break; + } + case 26: { + durationField_.AddEntriesFrom(input, _repeated_durationField_codec); + break; + } + case 34: { + emptyField_.AddEntriesFrom(input, _repeated_emptyField_codec); + break; + } + case 42: { + fieldMaskField_.AddEntriesFrom(input, _repeated_fieldMaskField_codec); + break; + } + case 50: { + sourceContextField_.AddEntriesFrom(input, _repeated_sourceContextField_codec); + break; + } + case 58: { + structField_.AddEntriesFrom(input, _repeated_structField_codec); + break; + } + case 66: { + timestampField_.AddEntriesFrom(input, _repeated_timestampField_codec); + break; + } + case 74: { + typeField_.AddEntriesFrom(input, _repeated_typeField_codec); + break; + } + } + } + } + + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class OneofWellKnownTypes : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofWellKnownTypes()); + public static pb::MessageParser Parser { get { return _parser; } } + + private static readonly string[] _fieldNames = new string[] { "any_field", "api_field", "bool_field", "bytes_field", "double_field", "duration_field", "empty_field", "field_mask_field", "float_field", "int32_field", "int64_field", "source_context_field", "string_field", "struct_field", "timestamp_field", "type_field", "uint32_field", "uint64_field" }; + private static readonly uint[] _fieldTags = new uint[] { 10, 18, 130, 146, 82, 26, 34, 42, 90, 114, 98, 50, 138, 58, 66, 74, 122, 106 }; + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.Descriptor.MessageTypes[2]; } + } + + pbr::FieldAccessorTable pb::IReflectedMessage.Fields { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.internal__static_protobuf_unittest_OneofWellKnownTypes__FieldAccessorTable; } + } + + private bool _frozen = false; + public bool IsFrozen { get { return _frozen; } } + + public OneofWellKnownTypes() { + OnConstruction(); + } + + partial void OnConstruction(); + + public OneofWellKnownTypes(OneofWellKnownTypes other) : this() { + switch (other.OneofFieldCase) { + case OneofFieldOneofCase.AnyField: + AnyField = other.AnyField.Clone(); + break; + case OneofFieldOneofCase.ApiField: + ApiField = other.ApiField.Clone(); + break; + case OneofFieldOneofCase.DurationField: + DurationField = other.DurationField.Clone(); + break; + case OneofFieldOneofCase.EmptyField: + EmptyField = other.EmptyField.Clone(); + break; + case OneofFieldOneofCase.FieldMaskField: + FieldMaskField = other.FieldMaskField.Clone(); + break; + case OneofFieldOneofCase.SourceContextField: + SourceContextField = other.SourceContextField.Clone(); + break; + case OneofFieldOneofCase.StructField: + StructField = other.StructField.Clone(); + break; + case OneofFieldOneofCase.TimestampField: + TimestampField = other.TimestampField.Clone(); + break; + case OneofFieldOneofCase.TypeField: + TypeField = other.TypeField.Clone(); + break; + case OneofFieldOneofCase.DoubleField: + DoubleField = other.DoubleField; + break; + case OneofFieldOneofCase.FloatField: + FloatField = other.FloatField; + break; + case OneofFieldOneofCase.Int64Field: + Int64Field = other.Int64Field; + break; + case OneofFieldOneofCase.Uint64Field: + Uint64Field = other.Uint64Field; + break; + case OneofFieldOneofCase.Int32Field: + Int32Field = other.Int32Field; + break; + case OneofFieldOneofCase.Uint32Field: + Uint32Field = other.Uint32Field; + break; + case OneofFieldOneofCase.BoolField: + BoolField = other.BoolField; + break; + case OneofFieldOneofCase.StringField: + StringField = other.StringField; + break; + case OneofFieldOneofCase.BytesField: + BytesField = other.BytesField; + break; + } + + } + + public OneofWellKnownTypes Clone() { + return new OneofWellKnownTypes(this); + } + + public void Freeze() { + if (IsFrozen) { + return; + } + _frozen = true; + if (oneofField_ is IFreezable) ((IFreezable) oneofField_).Freeze(); + } + + public const int AnyFieldFieldNumber = 1; + public global::Google.Protobuf.WellKnownTypes.Any AnyField { + get { return oneofFieldCase_ == OneofFieldOneofCase.AnyField ? (global::Google.Protobuf.WellKnownTypes.Any) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.AnyField; + } + } + + public const int ApiFieldFieldNumber = 2; + public global::Google.Protobuf.WellKnownTypes.Api ApiField { + get { return oneofFieldCase_ == OneofFieldOneofCase.ApiField ? (global::Google.Protobuf.WellKnownTypes.Api) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.ApiField; + } + } + + public const int DurationFieldFieldNumber = 3; + public global::Google.Protobuf.WellKnownTypes.Duration DurationField { + get { return oneofFieldCase_ == OneofFieldOneofCase.DurationField ? (global::Google.Protobuf.WellKnownTypes.Duration) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.DurationField; + } + } + + public const int EmptyFieldFieldNumber = 4; + public global::Google.Protobuf.WellKnownTypes.Empty EmptyField { + get { return oneofFieldCase_ == OneofFieldOneofCase.EmptyField ? (global::Google.Protobuf.WellKnownTypes.Empty) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.EmptyField; + } + } + + public const int FieldMaskFieldFieldNumber = 5; + public global::Google.Protobuf.WellKnownTypes.FieldMask FieldMaskField { + get { return oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField ? (global::Google.Protobuf.WellKnownTypes.FieldMask) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.FieldMaskField; + } + } + + public const int SourceContextFieldFieldNumber = 6; + public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContextField { + get { return oneofFieldCase_ == OneofFieldOneofCase.SourceContextField ? (global::Google.Protobuf.WellKnownTypes.SourceContext) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.SourceContextField; + } + } + + public const int StructFieldFieldNumber = 7; + public global::Google.Protobuf.WellKnownTypes.Struct StructField { + get { return oneofFieldCase_ == OneofFieldOneofCase.StructField ? (global::Google.Protobuf.WellKnownTypes.Struct) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.StructField; + } + } + + public const int TimestampFieldFieldNumber = 8; + public global::Google.Protobuf.WellKnownTypes.Timestamp TimestampField { + get { return oneofFieldCase_ == OneofFieldOneofCase.TimestampField ? (global::Google.Protobuf.WellKnownTypes.Timestamp) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.TimestampField; + } + } + + public const int TypeFieldFieldNumber = 9; + public global::Google.Protobuf.WellKnownTypes.Type TypeField { + get { return oneofFieldCase_ == OneofFieldOneofCase.TypeField ? (global::Google.Protobuf.WellKnownTypes.Type) oneofField_ : null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.TypeField; + } + } + + public const int DoubleFieldFieldNumber = 10; + public double? DoubleField { + get { return oneofFieldCase_ == OneofFieldOneofCase.DoubleField ? ((global::Google.Protobuf.WellKnownTypes.DoubleValue) oneofField_).Value : (double?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.DoubleValue { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.DoubleField; + } + } + + public const int FloatFieldFieldNumber = 11; + public float? FloatField { + get { return oneofFieldCase_ == OneofFieldOneofCase.FloatField ? ((global::Google.Protobuf.WellKnownTypes.FloatValue) oneofField_).Value : (float?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.FloatValue { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.FloatField; + } + } + + public const int Int64FieldFieldNumber = 12; + public long? Int64Field { + get { return oneofFieldCase_ == OneofFieldOneofCase.Int64Field ? ((global::Google.Protobuf.WellKnownTypes.Int64Value) oneofField_).Value : (long?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.Int64Value { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Int64Field; + } + } + + public const int Uint64FieldFieldNumber = 13; + public ulong? Uint64Field { + get { return oneofFieldCase_ == OneofFieldOneofCase.Uint64Field ? ((global::Google.Protobuf.WellKnownTypes.UInt64Value) oneofField_).Value : (ulong?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.UInt64Value { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Uint64Field; + } + } + + public const int Int32FieldFieldNumber = 14; + public int? Int32Field { + get { return oneofFieldCase_ == OneofFieldOneofCase.Int32Field ? ((global::Google.Protobuf.WellKnownTypes.Int32Value) oneofField_).Value : (int?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.Int32Value { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Int32Field; + } + } + + public const int Uint32FieldFieldNumber = 15; + public uint? Uint32Field { + get { return oneofFieldCase_ == OneofFieldOneofCase.Uint32Field ? ((global::Google.Protobuf.WellKnownTypes.UInt32Value) oneofField_).Value : (uint?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.UInt32Value { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Uint32Field; + } + } + + public const int BoolFieldFieldNumber = 16; + public bool? BoolField { + get { return oneofFieldCase_ == OneofFieldOneofCase.BoolField ? ((global::Google.Protobuf.WellKnownTypes.BoolValue) oneofField_).Value : (bool?) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.BoolValue { Value = value.Value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.BoolField; + } + } + + public const int StringFieldFieldNumber = 17; + public string StringField { + get { return oneofFieldCase_ == OneofFieldOneofCase.StringField ? ((global::Google.Protobuf.WellKnownTypes.StringValue) oneofField_).Value : (string) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.StringValue { Value = value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.StringField; + } + } + + public const int BytesFieldFieldNumber = 18; + public pb::ByteString BytesField { + get { return oneofFieldCase_ == OneofFieldOneofCase.BytesField ? ((global::Google.Protobuf.WellKnownTypes.BytesValue) oneofField_).Value : (pb::ByteString) null; } + set { + pb::Freezable.CheckMutable(this); + oneofField_ = value == null ? null : new global::Google.Protobuf.WellKnownTypes.BytesValue { Value = value }; + oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.BytesField; + } + } + + private object oneofField_; + public enum OneofFieldOneofCase { + None = 0, + AnyField = 1, + ApiField = 2, + DurationField = 3, + EmptyField = 4, + FieldMaskField = 5, + SourceContextField = 6, + StructField = 7, + TimestampField = 8, + TypeField = 9, + DoubleField = 10, + FloatField = 11, + Int64Field = 12, + Uint64Field = 13, + Int32Field = 14, + Uint32Field = 15, + BoolField = 16, + StringField = 17, + BytesField = 18, + } + private OneofFieldOneofCase oneofFieldCase_ = OneofFieldOneofCase.None; + public OneofFieldOneofCase OneofFieldCase { + get { return oneofFieldCase_; } + } + + public void ClearOneofField() { + pb::Freezable.CheckMutable(this); + oneofFieldCase_ = OneofFieldOneofCase.None; + oneofField_ = null; + } + + public override bool Equals(object other) { + return Equals(other as OneofWellKnownTypes); + } + + public bool Equals(OneofWellKnownTypes other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!object.Equals(AnyField, other.AnyField)) return false; + if (!object.Equals(ApiField, other.ApiField)) return false; + if (!object.Equals(DurationField, other.DurationField)) return false; + if (!object.Equals(EmptyField, other.EmptyField)) return false; + if (!object.Equals(FieldMaskField, other.FieldMaskField)) return false; + if (!object.Equals(SourceContextField, other.SourceContextField)) return false; + if (!object.Equals(StructField, other.StructField)) return false; + if (!object.Equals(TimestampField, other.TimestampField)) return false; + if (!object.Equals(TypeField, other.TypeField)) return false; + if (DoubleField != other.DoubleField) return false; + if (FloatField != other.FloatField) return false; + if (Int64Field != other.Int64Field) return false; + if (Uint64Field != other.Uint64Field) return false; + if (Int32Field != other.Int32Field) return false; + if (Uint32Field != other.Uint32Field) return false; + if (BoolField != other.BoolField) return false; + if (StringField != other.StringField) return false; + if (BytesField != other.BytesField) return false; + return true; + } + + public override int GetHashCode() { + int hash = 1; + if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) hash ^= AnyField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) hash ^= ApiField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) hash ^= DurationField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) hash ^= EmptyField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) hash ^= FieldMaskField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) hash ^= SourceContextField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.StructField) hash ^= StructField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) hash ^= TimestampField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) hash ^= TypeField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) hash ^= DoubleField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) hash ^= FloatField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) hash ^= Int64Field.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) hash ^= Uint64Field.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) hash ^= Int32Field.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) hash ^= Uint32Field.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) hash ^= BoolField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.StringField) hash ^= StringField.GetHashCode(); + if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) hash ^= BytesField.GetHashCode(); + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) { + output.WriteRawTag(10); + output.WriteMessage(AnyField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) { + output.WriteRawTag(18); + output.WriteMessage(ApiField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) { + output.WriteRawTag(26); + output.WriteMessage(DurationField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) { + output.WriteRawTag(34); + output.WriteMessage(EmptyField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) { + output.WriteRawTag(42); + output.WriteMessage(FieldMaskField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) { + output.WriteRawTag(50); + output.WriteMessage(SourceContextField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.StructField) { + output.WriteRawTag(58); + output.WriteMessage(StructField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) { + output.WriteRawTag(66); + output.WriteMessage(TimestampField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) { + output.WriteRawTag(74); + output.WriteMessage(TypeField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) { + output.WriteRawTag(82); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.DoubleValue) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) { + output.WriteRawTag(90); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.FloatValue) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) { + output.WriteRawTag(98); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.Int64Value) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) { + output.WriteRawTag(106); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.UInt64Value) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) { + output.WriteRawTag(114); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.Int32Value) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) { + output.WriteRawTag(122); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.UInt32Value) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) { + output.WriteRawTag(130, 1); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.BoolValue) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.StringField) { + output.WriteRawTag(138, 1); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.StringValue) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) { + output.WriteRawTag(146, 1); + output.WriteMessage((global::Google.Protobuf.WellKnownTypes.BytesValue) oneofField_); + } + } + + public int CalculateSize() { + int size = 0; + if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(AnyField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(ApiField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(DurationField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(EmptyField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(FieldMaskField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContextField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.StructField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(StructField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(TimestampField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(TypeField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.DoubleValue) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.FloatValue) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.Int64Value) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.UInt64Value) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.Int32Value) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.UInt32Value) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) { + size += 2 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.BoolValue) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.StringField) { + size += 2 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.StringValue) oneofField_)); + } + if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) { + size += 2 + pb::CodedOutputStream.ComputeMessageSize(((global::Google.Protobuf.WellKnownTypes.BytesValue) oneofField_)); + } + return size; + } + + public void MergeFrom(OneofWellKnownTypes other) { + if (other == null) { + return; + } + switch (other.OneofFieldCase) { + case OneofFieldOneofCase.AnyField: + AnyField = other.AnyField; + break; + case OneofFieldOneofCase.ApiField: + ApiField = other.ApiField; + break; + case OneofFieldOneofCase.DurationField: + DurationField = other.DurationField; + break; + case OneofFieldOneofCase.EmptyField: + EmptyField = other.EmptyField; + break; + case OneofFieldOneofCase.FieldMaskField: + FieldMaskField = other.FieldMaskField; + break; + case OneofFieldOneofCase.SourceContextField: + SourceContextField = other.SourceContextField; + break; + case OneofFieldOneofCase.StructField: + StructField = other.StructField; + break; + case OneofFieldOneofCase.TimestampField: + TimestampField = other.TimestampField; + break; + case OneofFieldOneofCase.TypeField: + TypeField = other.TypeField; + break; + case OneofFieldOneofCase.DoubleField: + DoubleField = other.DoubleField; + break; + case OneofFieldOneofCase.FloatField: + FloatField = other.FloatField; + break; + case OneofFieldOneofCase.Int64Field: + Int64Field = other.Int64Field; + break; + case OneofFieldOneofCase.Uint64Field: + Uint64Field = other.Uint64Field; + break; + case OneofFieldOneofCase.Int32Field: + Int32Field = other.Int32Field; + break; + case OneofFieldOneofCase.Uint32Field: + Uint32Field = other.Uint32Field; + break; + case OneofFieldOneofCase.BoolField: + BoolField = other.BoolField; + break; + case OneofFieldOneofCase.StringField: + StringField = other.StringField; + break; + case OneofFieldOneofCase.BytesField: + BytesField = other.BytesField; + 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: { + global::Google.Protobuf.WellKnownTypes.Any subBuilder = new global::Google.Protobuf.WellKnownTypes.Any(); + if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) { + subBuilder.MergeFrom(AnyField); + } + input.ReadMessage(subBuilder); + AnyField = subBuilder; + break; + } + case 18: { + global::Google.Protobuf.WellKnownTypes.Api subBuilder = new global::Google.Protobuf.WellKnownTypes.Api(); + if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) { + subBuilder.MergeFrom(ApiField); + } + input.ReadMessage(subBuilder); + ApiField = subBuilder; + break; + } + case 26: { + global::Google.Protobuf.WellKnownTypes.Duration subBuilder = new global::Google.Protobuf.WellKnownTypes.Duration(); + if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) { + subBuilder.MergeFrom(DurationField); + } + input.ReadMessage(subBuilder); + DurationField = subBuilder; + break; + } + case 34: { + global::Google.Protobuf.WellKnownTypes.Empty subBuilder = new global::Google.Protobuf.WellKnownTypes.Empty(); + if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) { + subBuilder.MergeFrom(EmptyField); + } + input.ReadMessage(subBuilder); + EmptyField = subBuilder; + break; + } + case 42: { + global::Google.Protobuf.WellKnownTypes.FieldMask subBuilder = new global::Google.Protobuf.WellKnownTypes.FieldMask(); + if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) { + subBuilder.MergeFrom(FieldMaskField); + } + input.ReadMessage(subBuilder); + FieldMaskField = subBuilder; + break; + } + case 50: { + global::Google.Protobuf.WellKnownTypes.SourceContext subBuilder = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) { + subBuilder.MergeFrom(SourceContextField); + } + input.ReadMessage(subBuilder); + SourceContextField = subBuilder; + break; + } + case 58: { + global::Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::Google.Protobuf.WellKnownTypes.Struct(); + if (oneofFieldCase_ == OneofFieldOneofCase.StructField) { + subBuilder.MergeFrom(StructField); + } + input.ReadMessage(subBuilder); + StructField = subBuilder; + break; + } + case 66: { + global::Google.Protobuf.WellKnownTypes.Timestamp subBuilder = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) { + subBuilder.MergeFrom(TimestampField); + } + input.ReadMessage(subBuilder); + TimestampField = subBuilder; + break; + } + case 74: { + global::Google.Protobuf.WellKnownTypes.Type subBuilder = new global::Google.Protobuf.WellKnownTypes.Type(); + if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) { + subBuilder.MergeFrom(TypeField); + } + input.ReadMessage(subBuilder); + TypeField = subBuilder; + break; + } + case 82: { + global::Google.Protobuf.WellKnownTypes.DoubleValue subBuilder = new global::Google.Protobuf.WellKnownTypes.DoubleValue(); + if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.DoubleValue) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.DoubleField; + oneofField_ = subBuilder; + break; + } + case 90: { + global::Google.Protobuf.WellKnownTypes.FloatValue subBuilder = new global::Google.Protobuf.WellKnownTypes.FloatValue(); + if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.FloatValue) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.FloatField; + oneofField_ = subBuilder; + break; + } + case 98: { + global::Google.Protobuf.WellKnownTypes.Int64Value subBuilder = new global::Google.Protobuf.WellKnownTypes.Int64Value(); + if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.Int64Value) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.Int64Field; + oneofField_ = subBuilder; + break; + } + case 106: { + global::Google.Protobuf.WellKnownTypes.UInt64Value subBuilder = new global::Google.Protobuf.WellKnownTypes.UInt64Value(); + if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.UInt64Value) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.Uint64Field; + oneofField_ = subBuilder; + break; + } + case 114: { + global::Google.Protobuf.WellKnownTypes.Int32Value subBuilder = new global::Google.Protobuf.WellKnownTypes.Int32Value(); + if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.Int32Value) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.Int32Field; + oneofField_ = subBuilder; + break; + } + case 122: { + global::Google.Protobuf.WellKnownTypes.UInt32Value subBuilder = new global::Google.Protobuf.WellKnownTypes.UInt32Value(); + if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.UInt32Value) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.Uint32Field; + oneofField_ = subBuilder; + break; + } + case 130: { + global::Google.Protobuf.WellKnownTypes.BoolValue subBuilder = new global::Google.Protobuf.WellKnownTypes.BoolValue(); + if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.BoolValue) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.BoolField; + oneofField_ = subBuilder; + break; + } + case 138: { + global::Google.Protobuf.WellKnownTypes.StringValue subBuilder = new global::Google.Protobuf.WellKnownTypes.StringValue(); + if (oneofFieldCase_ == OneofFieldOneofCase.StringField) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.StringValue) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.StringField; + oneofField_ = subBuilder; + break; + } + case 146: { + global::Google.Protobuf.WellKnownTypes.BytesValue subBuilder = new global::Google.Protobuf.WellKnownTypes.BytesValue(); + if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) { + subBuilder.MergeFrom((global::Google.Protobuf.WellKnownTypes.BytesValue) oneofField_); + } + input.ReadMessage(subBuilder); + oneofFieldCase_ = OneofFieldOneofCase.BytesField; + oneofField_ = subBuilder; + break; + } + } + } + } + + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class MapWellKnownTypes : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MapWellKnownTypes()); + public static pb::MessageParser Parser { get { return _parser; } } + + private static readonly string[] _fieldNames = new string[] { "any_field", "api_field", "bool_field", "bytes_field", "double_field", "duration_field", "empty_field", "field_mask_field", "float_field", "int32_field", "int64_field", "source_context_field", "string_field", "struct_field", "timestamp_field", "type_field", "uint32_field", "uint64_field" }; + private static readonly uint[] _fieldTags = new uint[] { 10, 18, 130, 146, 82, 26, 34, 42, 90, 114, 98, 50, 138, 58, 66, 74, 122, 106 }; + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.Descriptor.MessageTypes[3]; } + } + + pbr::FieldAccessorTable pb::IReflectedMessage.Fields { + get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypes.internal__static_protobuf_unittest_MapWellKnownTypes__FieldAccessorTable; } + } + + private bool _frozen = false; + public bool IsFrozen { get { return _frozen; } } + + public MapWellKnownTypes() { + OnConstruction(); + } + + partial void OnConstruction(); + + public MapWellKnownTypes(MapWellKnownTypes other) : this() { + anyField_ = other.anyField_.Clone(); + apiField_ = other.apiField_.Clone(); + durationField_ = other.durationField_.Clone(); + emptyField_ = other.emptyField_.Clone(); + fieldMaskField_ = other.fieldMaskField_.Clone(); + sourceContextField_ = other.sourceContextField_.Clone(); + structField_ = other.structField_.Clone(); + timestampField_ = other.timestampField_.Clone(); + typeField_ = other.typeField_.Clone(); + doubleField_ = other.doubleField_.Clone(); + floatField_ = other.floatField_.Clone(); + int64Field_ = other.int64Field_.Clone(); + uint64Field_ = other.uint64Field_.Clone(); + int32Field_ = other.int32Field_.Clone(); + uint32Field_ = other.uint32Field_.Clone(); + boolField_ = other.boolField_.Clone(); + stringField_ = other.stringField_.Clone(); + bytesField_ = other.bytesField_.Clone(); + } + + public MapWellKnownTypes Clone() { + return new MapWellKnownTypes(this); + } + + public void Freeze() { + if (IsFrozen) { + return; + } + _frozen = true; + anyField_.Freeze(); + apiField_.Freeze(); + durationField_.Freeze(); + emptyField_.Freeze(); + fieldMaskField_.Freeze(); + sourceContextField_.Freeze(); + structField_.Freeze(); + timestampField_.Freeze(); + typeField_.Freeze(); + doubleField_.Freeze(); + floatField_.Freeze(); + int64Field_.Freeze(); + uint64Field_.Freeze(); + int32Field_.Freeze(); + uint32Field_.Freeze(); + boolField_.Freeze(); + stringField_.Freeze(); + bytesField_.Freeze(); + } + + public const int AnyFieldFieldNumber = 1; + private static readonly pbc::MapField.Codec _map_anyField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Any.Parser), 10); + private readonly pbc::MapField anyField_ = new pbc::MapField(); + public pbc::MapField AnyField { + get { return anyField_; } + } + + public const int ApiFieldFieldNumber = 2; + private static readonly pbc::MapField.Codec _map_apiField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Api.Parser), 18); + private readonly pbc::MapField apiField_ = new pbc::MapField(); + public pbc::MapField ApiField { + get { return apiField_; } + } + + public const int DurationFieldFieldNumber = 3; + private static readonly pbc::MapField.Codec _map_durationField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Duration.Parser), 26); + private readonly pbc::MapField durationField_ = new pbc::MapField(); + public pbc::MapField DurationField { + get { return durationField_; } + } + + public const int EmptyFieldFieldNumber = 4; + private static readonly pbc::MapField.Codec _map_emptyField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Empty.Parser), 34); + private readonly pbc::MapField emptyField_ = new pbc::MapField(); + public pbc::MapField EmptyField { + get { return emptyField_; } + } + + public const int FieldMaskFieldFieldNumber = 5; + private static readonly pbc::MapField.Codec _map_fieldMaskField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.FieldMask.Parser), 42); + private readonly pbc::MapField fieldMaskField_ = new pbc::MapField(); + public pbc::MapField FieldMaskField { + get { return fieldMaskField_; } + } + + public const int SourceContextFieldFieldNumber = 6; + private static readonly pbc::MapField.Codec _map_sourceContextField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.SourceContext.Parser), 50); + private readonly pbc::MapField sourceContextField_ = new pbc::MapField(); + public pbc::MapField SourceContextField { + get { return sourceContextField_; } + } + + public const int StructFieldFieldNumber = 7; + private static readonly pbc::MapField.Codec _map_structField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Struct.Parser), 58); + private readonly pbc::MapField structField_ = new pbc::MapField(); + public pbc::MapField StructField { + get { return structField_; } + } + + public const int TimestampFieldFieldNumber = 8; + private static readonly pbc::MapField.Codec _map_timestampField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Timestamp.Parser), 66); + private readonly pbc::MapField timestampField_ = new pbc::MapField(); + public pbc::MapField TimestampField { + get { return timestampField_; } + } + + public const int TypeFieldFieldNumber = 9; + private static readonly pbc::MapField.Codec _map_typeField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Type.Parser), 74); + private readonly pbc::MapField typeField_ = new pbc::MapField(); + public pbc::MapField TypeField { + get { return typeField_; } + } + + public const int DoubleFieldFieldNumber = 10; + private static readonly pbc::MapField.Codec _map_doubleField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.DoubleValue.Parser), 82); + private readonly pbc::MapField doubleField_ = new pbc::MapField(); + public pbc::MapField DoubleField { + get { return doubleField_; } + } + + public const int FloatFieldFieldNumber = 11; + private static readonly pbc::MapField.Codec _map_floatField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.FloatValue.Parser), 90); + private readonly pbc::MapField floatField_ = new pbc::MapField(); + public pbc::MapField FloatField { + get { return floatField_; } + } + + public const int Int64FieldFieldNumber = 12; + private static readonly pbc::MapField.Codec _map_int64Field_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.Int64Value.Parser), 98); + private readonly pbc::MapField int64Field_ = new pbc::MapField(); + public pbc::MapField Int64Field { + get { return int64Field_; } + } + + public const int Uint64FieldFieldNumber = 13; + private static readonly pbc::MapField.Codec _map_uint64Field_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.UInt64Value.Parser), 106); + private readonly pbc::MapField uint64Field_ = new pbc::MapField(); + public pbc::MapField Uint64Field { + get { return uint64Field_; } + } + + public const int Int32FieldFieldNumber = 14; + private static readonly pbc::MapField.Codec _map_int32Field_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.Int32Value.Parser), 114); + private readonly pbc::MapField int32Field_ = new pbc::MapField(); + public pbc::MapField Int32Field { + get { return int32Field_; } + } + + public const int Uint32FieldFieldNumber = 15; + private static readonly pbc::MapField.Codec _map_uint32Field_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.UInt32Value.Parser), 122); + private readonly pbc::MapField uint32Field_ = new pbc::MapField(); + public pbc::MapField Uint32Field { + get { return uint32Field_; } + } + + public const int BoolFieldFieldNumber = 16; + private static readonly pbc::MapField.Codec _map_boolField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.BoolValue.Parser), 130); + private readonly pbc::MapField boolField_ = new pbc::MapField(); + public pbc::MapField BoolField { + get { return boolField_; } + } + + public const int StringFieldFieldNumber = 17; + private static readonly pbc::MapField.Codec _map_stringField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.StringValue.Parser), 138); + private readonly pbc::MapField stringField_ = new pbc::MapField(); + public pbc::MapField StringField { + get { return stringField_; } + } + + public const int BytesFieldFieldNumber = 18; + private static readonly pbc::MapField.Codec _map_bytesField_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForWrapperType(18, global::Google.Protobuf.WellKnownTypes.BytesValue.Parser), 146); + private readonly pbc::MapField bytesField_ = new pbc::MapField(); + public pbc::MapField BytesField { + get { return bytesField_; } + } + + public override bool Equals(object other) { + return Equals(other as MapWellKnownTypes); + } + + public bool Equals(MapWellKnownTypes other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!AnyField.Equals(other.AnyField)) return false; + if (!ApiField.Equals(other.ApiField)) return false; + if (!DurationField.Equals(other.DurationField)) return false; + if (!EmptyField.Equals(other.EmptyField)) return false; + if (!FieldMaskField.Equals(other.FieldMaskField)) return false; + if (!SourceContextField.Equals(other.SourceContextField)) return false; + if (!StructField.Equals(other.StructField)) return false; + if (!TimestampField.Equals(other.TimestampField)) return false; + if (!TypeField.Equals(other.TypeField)) return false; + if (!DoubleField.Equals(other.DoubleField)) return false; + if (!FloatField.Equals(other.FloatField)) return false; + if (!Int64Field.Equals(other.Int64Field)) return false; + if (!Uint64Field.Equals(other.Uint64Field)) return false; + if (!Int32Field.Equals(other.Int32Field)) return false; + if (!Uint32Field.Equals(other.Uint32Field)) return false; + if (!BoolField.Equals(other.BoolField)) return false; + if (!StringField.Equals(other.StringField)) return false; + if (!BytesField.Equals(other.BytesField)) return false; + return true; + } + + public override int GetHashCode() { + int hash = 1; + hash ^= AnyField.GetHashCode(); + hash ^= ApiField.GetHashCode(); + hash ^= DurationField.GetHashCode(); + hash ^= EmptyField.GetHashCode(); + hash ^= FieldMaskField.GetHashCode(); + hash ^= SourceContextField.GetHashCode(); + hash ^= StructField.GetHashCode(); + hash ^= TimestampField.GetHashCode(); + hash ^= TypeField.GetHashCode(); + hash ^= DoubleField.GetHashCode(); + hash ^= FloatField.GetHashCode(); + hash ^= Int64Field.GetHashCode(); + hash ^= Uint64Field.GetHashCode(); + hash ^= Int32Field.GetHashCode(); + hash ^= Uint32Field.GetHashCode(); + hash ^= BoolField.GetHashCode(); + hash ^= StringField.GetHashCode(); + hash ^= BytesField.GetHashCode(); + return hash; + } + + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } + + public void WriteTo(pb::CodedOutputStream output) { + anyField_.WriteTo(output, _map_anyField_codec); + apiField_.WriteTo(output, _map_apiField_codec); + durationField_.WriteTo(output, _map_durationField_codec); + emptyField_.WriteTo(output, _map_emptyField_codec); + fieldMaskField_.WriteTo(output, _map_fieldMaskField_codec); + sourceContextField_.WriteTo(output, _map_sourceContextField_codec); + structField_.WriteTo(output, _map_structField_codec); + timestampField_.WriteTo(output, _map_timestampField_codec); + typeField_.WriteTo(output, _map_typeField_codec); + doubleField_.WriteTo(output, _map_doubleField_codec); + floatField_.WriteTo(output, _map_floatField_codec); + int64Field_.WriteTo(output, _map_int64Field_codec); + uint64Field_.WriteTo(output, _map_uint64Field_codec); + int32Field_.WriteTo(output, _map_int32Field_codec); + uint32Field_.WriteTo(output, _map_uint32Field_codec); + boolField_.WriteTo(output, _map_boolField_codec); + stringField_.WriteTo(output, _map_stringField_codec); + bytesField_.WriteTo(output, _map_bytesField_codec); + } + + public int CalculateSize() { + int size = 0; + size += anyField_.CalculateSize(_map_anyField_codec); + size += apiField_.CalculateSize(_map_apiField_codec); + size += durationField_.CalculateSize(_map_durationField_codec); + size += emptyField_.CalculateSize(_map_emptyField_codec); + size += fieldMaskField_.CalculateSize(_map_fieldMaskField_codec); + size += sourceContextField_.CalculateSize(_map_sourceContextField_codec); + size += structField_.CalculateSize(_map_structField_codec); + size += timestampField_.CalculateSize(_map_timestampField_codec); + size += typeField_.CalculateSize(_map_typeField_codec); + size += doubleField_.CalculateSize(_map_doubleField_codec); + size += floatField_.CalculateSize(_map_floatField_codec); + size += int64Field_.CalculateSize(_map_int64Field_codec); + size += uint64Field_.CalculateSize(_map_uint64Field_codec); + size += int32Field_.CalculateSize(_map_int32Field_codec); + size += uint32Field_.CalculateSize(_map_uint32Field_codec); + size += boolField_.CalculateSize(_map_boolField_codec); + size += stringField_.CalculateSize(_map_stringField_codec); + size += bytesField_.CalculateSize(_map_bytesField_codec); + return size; + } + + public void MergeFrom(MapWellKnownTypes other) { + if (other == null) { + return; + } + anyField_.Add(other.anyField_); + apiField_.Add(other.apiField_); + durationField_.Add(other.durationField_); + emptyField_.Add(other.emptyField_); + fieldMaskField_.Add(other.fieldMaskField_); + sourceContextField_.Add(other.sourceContextField_); + structField_.Add(other.structField_); + timestampField_.Add(other.timestampField_); + typeField_.Add(other.typeField_); + doubleField_.Add(other.doubleField_); + floatField_.Add(other.floatField_); + int64Field_.Add(other.int64Field_); + uint64Field_.Add(other.uint64Field_); + int32Field_.Add(other.int32Field_); + uint32Field_.Add(other.uint32Field_); + boolField_.Add(other.boolField_); + stringField_.Add(other.stringField_); + bytesField_.Add(other.bytesField_); + } + + 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: { + anyField_.AddEntriesFrom(input, _map_anyField_codec); + break; + } + case 18: { + apiField_.AddEntriesFrom(input, _map_apiField_codec); + break; + } + case 26: { + durationField_.AddEntriesFrom(input, _map_durationField_codec); + break; + } + case 34: { + emptyField_.AddEntriesFrom(input, _map_emptyField_codec); + break; + } + case 42: { + fieldMaskField_.AddEntriesFrom(input, _map_fieldMaskField_codec); + break; + } + case 50: { + sourceContextField_.AddEntriesFrom(input, _map_sourceContextField_codec); + break; + } + case 58: { + structField_.AddEntriesFrom(input, _map_structField_codec); + break; + } + case 66: { + timestampField_.AddEntriesFrom(input, _map_timestampField_codec); + break; + } + case 74: { + typeField_.AddEntriesFrom(input, _map_typeField_codec); + break; + } + case 82: { + doubleField_.AddEntriesFrom(input, _map_doubleField_codec); + break; + } + case 90: { + floatField_.AddEntriesFrom(input, _map_floatField_codec); + break; + } + case 98: { + int64Field_.AddEntriesFrom(input, _map_int64Field_codec); + break; + } + case 106: { + uint64Field_.AddEntriesFrom(input, _map_uint64Field_codec); + break; + } + case 114: { + int32Field_.AddEntriesFrom(input, _map_int32Field_codec); + break; + } + case 122: { + uint32Field_.AddEntriesFrom(input, _map_uint32Field_codec); + break; + } + case 130: { + boolField_.AddEntriesFrom(input, _map_boolField_codec); + break; + } + case 138: { + stringField_.AddEntriesFrom(input, _map_stringField_codec); + break; + } + case 146: { + bytesField_.AddEntriesFrom(input, _map_bytesField_codec); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/csharp/src/ProtocolBuffers.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/ProtocolBuffers.Test/WellKnownTypes/WrappersTest.cs new file mode 100644 index 00000000..185a277c --- /dev/null +++ b/csharp/src/ProtocolBuffers.Test/WellKnownTypes/WrappersTest.cs @@ -0,0 +1,85 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using Google.Protobuf.TestProtos; +using NUnit.Framework; + +namespace Google.Protobuf.WellKnownTypes +{ + public class WrappersTest + { + [Test] + public void NullIsDefault() + { + var message = new TestWellKnownTypes(); + Assert.IsNull(message.StringField); + Assert.IsNull(message.BytesField); + Assert.IsNull(message.BoolField); + Assert.IsNull(message.FloatField); + Assert.IsNull(message.DoubleField); + Assert.IsNull(message.Int32Field); + Assert.IsNull(message.Int64Field); + Assert.IsNull(message.Uint32Field); + Assert.IsNull(message.Uint64Field); + } + + [Test] + public void NonNullDefaultIsPreservedThroughSerialization() + { + var message = new TestWellKnownTypes + { + StringField = "", + BytesField = ByteString.Empty, + BoolField = false, + FloatField = 0f, + DoubleField = 0d, + Int32Field = 0, + Int64Field = 0, + Uint32Field = 0, + Uint64Field = 0 + }; + + var bytes = message.ToByteArray(); + var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes); + + Assert.AreEqual("", message.StringField); + Assert.AreEqual(ByteString.Empty, message.BytesField); + Assert.AreEqual(false, message.BoolField); + Assert.AreEqual(0f, message.FloatField); + Assert.AreEqual(0d, message.DoubleField); + Assert.AreEqual(0, message.Int32Field); + Assert.AreEqual(0L, message.Int64Field); + Assert.AreEqual(0U, message.Uint32Field); + Assert.AreEqual(0UL, message.Uint64Field); + } + } +} diff --git a/src/Makefile.am b/src/Makefile.am index 233b6260..0a7d3a3d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -441,7 +441,9 @@ libprotoc_la_SOURCES = \ google/protobuf/compiler/csharp/csharp_source_generator_base.cc \ google/protobuf/compiler/csharp/csharp_source_generator_base.h \ google/protobuf/compiler/csharp/csharp_umbrella_class.cc \ - google/protobuf/compiler/csharp/csharp_umbrella_class.h + google/protobuf/compiler/csharp/csharp_umbrella_class.h \ + google/protobuf/compiler/csharp/csharp_wrapper_field.cc \ + google/protobuf/compiler/csharp/csharp_wrapper_field.h bin_PROGRAMS = protoc protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 914b972d..f36e6fde 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -168,6 +168,18 @@ std::string FieldGeneratorBase::type_name(const FieldDescriptor* descriptor) { return GetClassName(descriptor->enum_type()); case FieldDescriptor::TYPE_MESSAGE: case FieldDescriptor::TYPE_GROUP: + if (IsWrapperType(descriptor)) { + const FieldDescriptor* wrapped_field = descriptor->message_type()->field(0); + string wrapped_field_type_name = type_name(wrapped_field); + // String and ByteString go to the same type; other wrapped types go to the + // nullable equivalent. + if (wrapped_field->type() == FieldDescriptor::TYPE_STRING || + wrapped_field->type() == FieldDescriptor::TYPE_BYTES) { + return wrapped_field_type_name; + } else { + return wrapped_field_type_name + "?"; + } + } return GetClassName(descriptor->message_type()); case FieldDescriptor::TYPE_DOUBLE: return "double"; diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 8ecd1dc2..1c7a24a9 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -52,6 +52,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -366,31 +367,39 @@ FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, return new RepeatedMessageFieldGenerator(descriptor, fieldOrdinal); } } else { - if (descriptor->containing_oneof()) { - return new MessageOneofFieldGenerator(descriptor, fieldOrdinal); - } else { - return new MessageFieldGenerator(descriptor, fieldOrdinal); - } + if (IsWrapperType(descriptor)) { + if (descriptor->containing_oneof()) { + return new WrapperOneofFieldGenerator(descriptor, fieldOrdinal); + } else { + return new WrapperFieldGenerator(descriptor, fieldOrdinal); + } + } else { + if (descriptor->containing_oneof()) { + return new MessageOneofFieldGenerator(descriptor, fieldOrdinal); + } else { + return new MessageFieldGenerator(descriptor, fieldOrdinal); + } + } } case FieldDescriptor::TYPE_ENUM: if (descriptor->is_repeated()) { return new RepeatedEnumFieldGenerator(descriptor, fieldOrdinal); } else { - if (descriptor->containing_oneof()) { - return new EnumOneofFieldGenerator(descriptor, fieldOrdinal); - } else { - return new EnumFieldGenerator(descriptor, fieldOrdinal); - } + if (descriptor->containing_oneof()) { + return new EnumOneofFieldGenerator(descriptor, fieldOrdinal); + } else { + return new EnumFieldGenerator(descriptor, fieldOrdinal); + } } default: if (descriptor->is_repeated()) { return new RepeatedPrimitiveFieldGenerator(descriptor, fieldOrdinal); } else { - if (descriptor->containing_oneof()) { - return new PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal); - } else { - return new PrimitiveFieldGenerator(descriptor, fieldOrdinal); - } + if (descriptor->containing_oneof()) { + return new PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal); + } else { + return new PrimitiveFieldGenerator(descriptor, fieldOrdinal); + } } } } diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index a7c2395b..b6a75b34 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -120,6 +120,15 @@ inline bool IsDescriptorProto(const FileDescriptor* descriptor) { return descriptor->name() == "google/protobuf/descriptor_proto_file.proto"; } +inline bool IsMapEntry(const Descriptor* descriptor) { + return descriptor->options().map_entry(); +} + +inline bool IsWrapperType(const FieldDescriptor* descriptor) { + return descriptor->type() == FieldDescriptor::TYPE_MESSAGE && + descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto"; +} + } // namespace csharp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc new file mode 100644 index 00000000..eb3791ec --- /dev/null +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc @@ -0,0 +1,210 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace csharp { + +WrapperFieldGenerator::WrapperFieldGenerator(const FieldDescriptor* descriptor, + int fieldOrdinal) + : FieldGeneratorBase(descriptor, fieldOrdinal) { + variables_["has_property_check"] = name() + "_ != null"; + variables_["has_not_property_check"] = name() + "_ == null"; + variables_["message_type_name"] = GetClassName(descriptor->message_type()); + const FieldDescriptor* wrapped_field = descriptor->message_type()->field(0); + is_value_type = wrapped_field->type() != FieldDescriptor::TYPE_STRING && + wrapped_field->type() != FieldDescriptor::TYPE_BYTES; + variables_["deref"] = is_value_type ? ".Value" : ""; + // This will always be a single byte, because it's always field 1. + variables_["message_tag_bytes"] = SimpleItoa(FixedMakeTag(wrapped_field)); +} + +WrapperFieldGenerator::~WrapperFieldGenerator() { +} + +void WrapperFieldGenerator::GenerateMembers(io::Printer* printer) { + // Back the underlying property with an underlying message. This isn't efficient, + // but it makes it easier to be compliant with what platforms which don't support wrapper + // types would do. Currently, each time the value is changed, we create a new instance. + // With suitable care to avoid aliasing, we could probably check whether or not we've already + // got an instance, and simply mutate the existing one. + printer->Print( + variables_, + "private $message_type_name$ $name$_;\n"); + AddDeprecatedFlag(printer); + printer->Print( + variables_, + "$access_level$ $type_name$ $property_name$ {\n" + " get { return $name$_ == null ? ($type_name$) null : $name$_.Value; }\n" + " set {\n" + " pb::Freezable.CheckMutable(this);\n" + " $name$_ = value == null ? null : new $message_type_name$ { Value = value$deref$ };\n" + " }\n" + "}\n"); +} + +void WrapperFieldGenerator::GenerateMergingCode(io::Printer* printer) { + printer->Print( + variables_, + "if (other.$has_property_check$) {\n" + " if ($has_not_property_check$) {\n" + " $name$_ = new $message_type_name$();\n" + " }\n" + " $name$_.MergeFrom(other.$name$_);\n" + "}\n"); +} + +void WrapperFieldGenerator::GenerateParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_not_property_check$) {\n" + " $name$_ = new $message_type_name$();\n" + "}\n" + "input.ReadMessage($name$_);\n"); // No need to support TYPE_GROUP... +} + +void WrapperFieldGenerator::GenerateSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_property_check$) {\n" + " output.WriteRawTag($tag_bytes$);\n" + " output.WriteMessage($name$_);\n" + "}\n"); +} + +void WrapperFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_property_check$) {\n" + " size += $tag_size$ + pb::CodedOutputStream.ComputeMessageSize($name$_);\n" + "}\n"); +} + +void WrapperFieldGenerator::WriteHash(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_property_check$) hash ^= $property_name$.GetHashCode();\n"); +} + +void WrapperFieldGenerator::WriteEquals(io::Printer* printer) { + printer->Print( + variables_, + "if ($property_name$ != other.$property_name$) return false;\n"); +} + +void WrapperFieldGenerator::WriteToString(io::Printer* printer) { + // TODO: Implement if we ever actually need it... +} + +void WrapperFieldGenerator::GenerateCloningCode(io::Printer* printer) { + // This will effectively perform a deep clone - it will create a new + // underlying message if necessary + printer->Print(variables_, + "$property_name$ = other.$property_name$;\n"); +} + +void WrapperFieldGenerator::GenerateCodecCode(io::Printer* printer) { + printer->Print( + variables_, + "pb::FieldCodec.ForWrapperType<$type_name$, $message_type_name$>($tag$, $message_type_name$.Parser)"); +} + +WrapperOneofFieldGenerator::WrapperOneofFieldGenerator(const FieldDescriptor* descriptor, + int fieldOrdinal) + : WrapperFieldGenerator(descriptor, fieldOrdinal) { + SetCommonOneofFieldVariables(&variables_); +} + +WrapperOneofFieldGenerator::~WrapperOneofFieldGenerator() { +} + +void WrapperOneofFieldGenerator::GenerateMembers(io::Printer* printer) { + AddDeprecatedFlag(printer); + printer->Print( + variables_, + "$access_level$ $type_name$ $property_name$ {\n" + " get { return $has_property_check$ ? (($message_type_name$) $oneof_name$_).Value : ($type_name$) null; }\n" + " set {\n" + " pb::Freezable.CheckMutable(this);\n" + " $oneof_name$_ = value == null ? null : new $message_type_name$ { Value = value$deref$ };\n" + " $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n" + " }\n" + "}\n"); +} + + + +void WrapperOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$message_type_name$ subBuilder = new $message_type_name$();\n" + "if ($has_property_check$) {\n" + " subBuilder.MergeFrom(($message_type_name$) $oneof_name$_);\n" + "}\n" + "input.ReadMessage(subBuilder);\n" + // Don't set the property, which would create a new and equivalent message; just set the two fields. + "$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n" + "$oneof_name$_ = subBuilder;\n"); +} + +void WrapperOneofFieldGenerator::GenerateSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_property_check$) {\n" + " output.WriteRawTag($tag_bytes$);\n" + " output.WriteMessage(($message_type_name$) $oneof_name$_);\n" + "}\n"); +} + +void WrapperOneofFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_property_check$) {\n" + " size += $tag_size$ + pb::CodedOutputStream.ComputeMessageSize((($message_type_name$) $oneof_name$_));\n" + "}\n"); +} + +} // namespace csharp +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h new file mode 100644 index 00000000..5e2c5bc3 --- /dev/null +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h @@ -0,0 +1,86 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ +#define GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace csharp { + +class WrapperFieldGenerator : public FieldGeneratorBase { + public: + WrapperFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal); + ~WrapperFieldGenerator(); + + virtual void GenerateCodecCode(io::Printer* printer); + virtual void GenerateCloningCode(io::Printer* printer); + virtual void GenerateMembers(io::Printer* printer); + virtual void GenerateMergingCode(io::Printer* printer); + virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateSerializedSizeCode(io::Printer* printer); + + virtual void WriteHash(io::Printer* printer); + virtual void WriteEquals(io::Printer* printer); + virtual void WriteToString(io::Printer* printer); + + private: + bool is_value_type; // True for int32 etc; false for bytes and string + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WrapperFieldGenerator); +}; + +class WrapperOneofFieldGenerator : public WrapperFieldGenerator { + public: + WrapperOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal); + ~WrapperOneofFieldGenerator(); + + virtual void GenerateMembers(io::Printer* printer); + virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateSerializedSizeCode(io::Printer* printer); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WrapperOneofFieldGenerator); +}; + +} // namespace csharp +} // namespace compiler +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ + diff --git a/src/google/protobuf/unittest_well_known_types.proto b/src/google/protobuf/unittest_well_known_types.proto index e157260e..4771c094 100644 --- a/src/google/protobuf/unittest_well_known_types.proto +++ b/src/google/protobuf/unittest_well_known_types.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package protobuf_unittest; +option csharp_namespace = "Google.Protobuf.TestProtos"; option java_multiple_files = true; option java_package = "com.google.protobuf.test"; @@ -17,6 +18,8 @@ import "google/protobuf/type.proto"; import "google/protobuf/wrappers.proto"; // Test that we can include all well-known types. +// Each wrapper type is included separately, as languages +// map handle different wrappers in different ways. message TestWellKnownTypes { google.protobuf.Any any_field = 1; google.protobuf.Api api_field = 2; @@ -27,5 +30,83 @@ message TestWellKnownTypes { google.protobuf.Struct struct_field = 7; google.protobuf.Timestamp timestamp_field = 8; google.protobuf.Type type_field = 9; - google.protobuf.Int32Value int32_field = 10; + google.protobuf.DoubleValue double_field = 10; + google.protobuf.FloatValue float_field = 11; + google.protobuf.Int64Value int64_field = 12; + google.protobuf.UInt64Value uint64_field = 13; + google.protobuf.Int32Value int32_field = 14; + google.protobuf.UInt32Value uint32_field = 15; + google.protobuf.BoolValue bool_field = 16; + google.protobuf.StringValue string_field = 17; + google.protobuf.BytesValue bytes_field = 18; +} + +// A repeated field for each well-known type. +message RepeatedWellKnownTypes { + repeated google.protobuf.Any any_field = 1; + repeated google.protobuf.Api api_field = 2; + repeated google.protobuf.Duration duration_field = 3; + repeated google.protobuf.Empty empty_field = 4; + repeated google.protobuf.FieldMask field_mask_field = 5; + repeated google.protobuf.SourceContext source_context_field = 6; + repeated google.protobuf.Struct struct_field = 7; + repeated google.protobuf.Timestamp timestamp_field = 8; + repeated google.protobuf.Type type_field = 9; + // TODO: Do these even make sense? Should they be prohibited? +// repeated google.protobuf.DoubleValue double_field = 10; +// repeated google.protobuf.FloatValue float_field = 11; +// repeated google.protobuf.Int64Value int64_field = 12; +// repeated google.protobuf.UInt64Value uint64_field = 13; +// repeated google.protobuf.Int32Value int32_field = 14; +// repeated google.protobuf.UInt32Value uint32_field = 15; +// repeated google.protobuf.BoolValue bool_field = 16; +// repeated google.protobuf.StringValue string_field = 17; +// repeated google.protobuf.BytesValue bytes_field = 18; +} + +message OneofWellKnownTypes { + oneof oneof_field { + google.protobuf.Any any_field = 1; + google.protobuf.Api api_field = 2; + google.protobuf.Duration duration_field = 3; + google.protobuf.Empty empty_field = 4; + google.protobuf.FieldMask field_mask_field = 5; + google.protobuf.SourceContext source_context_field = 6; + google.protobuf.Struct struct_field = 7; + google.protobuf.Timestamp timestamp_field = 8; + google.protobuf.Type type_field = 9; + google.protobuf.DoubleValue double_field = 10; + google.protobuf.FloatValue float_field = 11; + google.protobuf.Int64Value int64_field = 12; + google.protobuf.UInt64Value uint64_field = 13; + google.protobuf.Int32Value int32_field = 14; + google.protobuf.UInt32Value uint32_field = 15; + google.protobuf.BoolValue bool_field = 16; + google.protobuf.StringValue string_field = 17; + google.protobuf.BytesValue bytes_field = 18; + } +} + +// A map field for each well-known type. We only +// need to worry about the value part of the map being the +// well-known types, as messages can't be map keys. +message MapWellKnownTypes { + map any_field = 1; + map api_field = 2; + map duration_field = 3; + map empty_field = 4; + map field_mask_field = 5; + map source_context_field = 6; + map struct_field = 7; + map timestamp_field = 8; + map type_field = 9; + map double_field = 10; + map float_field = 11; + map int64_field = 12; + map uint64_field = 13; + map int32_field = 14; + map uint32_field = 15; + map bool_field = 16; + map string_field = 17; + map bytes_field = 18; } -- cgit v1.2.3