diff --git a/Libs/Google.Protobuf/ByteArray.cs b/Libs/Google.Protobuf/ByteArray.cs new file mode 100644 index 0000000..b945ee1 --- /dev/null +++ b/Libs/Google.Protobuf/ByteArray.cs @@ -0,0 +1,79 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf +{ + /// + /// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy + /// + internal static class ByteArray + { + /// + /// The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy + /// + private const int CopyThreshold = 12; + + /// + /// Determines which copy routine to use based on the number of bytes to be copied. + /// + internal static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) + { + if (count > CopyThreshold) + { + Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count); + } + else + { + int stop = srcOffset + count; + for (int i = srcOffset; i < stop; i++) + { + dst[dstOffset++] = src[i]; + } + } + } + + /// + /// Reverses the order of bytes in the array + /// + internal static void Reverse(byte[] bytes) + { + for (int first = 0, last = bytes.Length - 1; first < last; first++, last--) + { + byte temp = bytes[first]; + bytes[first] = bytes[last]; + bytes[last] = temp; + } + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/ByteString.cs b/Libs/Google.Protobuf/ByteString.cs new file mode 100644 index 0000000..1d2ccbe --- /dev/null +++ b/Libs/Google.Protobuf/ByteString.cs @@ -0,0 +1,434 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +#if !NET35 +using System.Threading; +using System.Threading.Tasks; +#endif +#if NET35 +using LC.Google.Protobuf.Compatibility; +#endif + +namespace LC.Google.Protobuf +{ + /// + /// Immutable array of bytes. + /// + [SecuritySafeCritical] + public sealed class ByteString : IEnumerable, IEquatable + { + private static readonly ByteString empty = new ByteString(new byte[0]); + + private readonly ReadOnlyMemory bytes; + + /// + /// Internal use only. Ensure that the provided memory is not mutated and belongs to this instance. + /// + internal static ByteString AttachBytes(ReadOnlyMemory bytes) + { + return new ByteString(bytes); + } + + /// + /// Internal use only. Ensure that the provided memory is not mutated and belongs to this instance. + /// This method encapsulates converting array to memory. Reduces need for SecuritySafeCritical + /// in .NET Framework. + /// + internal static ByteString AttachBytes(byte[] bytes) + { + return AttachBytes(bytes.AsMemory()); + } + + /// + /// Constructs a new ByteString from the given memory. The memory is + /// *not* copied, and must not be modified after this constructor is called. + /// + private ByteString(ReadOnlyMemory bytes) + { + this.bytes = bytes; + } + + /// + /// Returns an empty ByteString. + /// + public static ByteString Empty + { + get { return empty; } + } + + /// + /// Returns the length of this ByteString in bytes. + /// + public int Length + { + get { return bytes.Length; } + } + + /// + /// Returns true if this byte string is empty, false otherwise. + /// + public bool IsEmpty + { + get { return Length == 0; } + } + + /// + /// Provides read-only access to the data of this . + /// No data is copied so this is the most efficient way of accessing. + /// + public ReadOnlySpan Span + { + get { return bytes.Span; } + } + + /// + /// Provides read-only access to the data of this . + /// No data is copied so this is the most efficient way of accessing. + /// + public ReadOnlyMemory Memory + { + get { return bytes; } + } + + /// + /// Converts this into a byte array. + /// + /// The data is copied - changes to the returned array will not be reflected in this ByteString. + /// A byte array with the same data as this ByteString. + public byte[] ToByteArray() + { + return bytes.ToArray(); + } + + /// + /// Converts this into a standard base64 representation. + /// + /// A base64 representation of this ByteString. + public string ToBase64() + { + if (MemoryMarshal.TryGetArray(bytes, out ArraySegment segment)) + { + // Fast path. ByteString was created with an array, so pass the underlying array. + return Convert.ToBase64String(segment.Array, segment.Offset, segment.Count); + } + else + { + // Slow path. BytesString is not an array. Convert memory and pass result to ToBase64String. + return Convert.ToBase64String(bytes.ToArray()); + } + } + + /// + /// Constructs a from the Base64 Encoded String. + /// + public static ByteString FromBase64(string bytes) + { + // By handling the empty string explicitly, we not only optimize but we fix a + // problem on CF 2.0. See issue 61 for details. + return bytes == "" ? Empty : new ByteString(Convert.FromBase64String(bytes)); + } + + /// + /// Constructs a from data in the given stream, synchronously. + /// + /// If successful, will be read completely, from the position + /// at the start of the call. + /// The stream to copy into a ByteString. + /// A ByteString with content read from the given stream. + public static ByteString FromStream(Stream stream) + { + ProtoPreconditions.CheckNotNull(stream, nameof(stream)); + int capacity = stream.CanSeek ? checked((int) (stream.Length - stream.Position)) : 0; + var memoryStream = new MemoryStream(capacity); + stream.CopyTo(memoryStream); +#if NETSTANDARD1_1 || NETSTANDARD2_0 + byte[] bytes = memoryStream.ToArray(); +#else + // Avoid an extra copy if we can. + byte[] bytes = memoryStream.Length == memoryStream.Capacity ? memoryStream.GetBuffer() : memoryStream.ToArray(); +#endif + return AttachBytes(bytes); + } + +#if !NET35 + /// + /// Constructs a from data in the given stream, asynchronously. + /// + /// If successful, will be read completely, from the position + /// at the start of the call. + /// The stream to copy into a ByteString. + /// The cancellation token to use when reading from the stream, if any. + /// A ByteString with content read from the given stream. + public static Task FromStreamAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken)) + { + ProtoPreconditions.CheckNotNull(stream, nameof(stream)); + return ByteStringAsync.FromStreamAsyncCore(stream, cancellationToken); + } +#endif + + /// + /// Constructs a from the given array. The contents + /// are copied, so further modifications to the array will not + /// be reflected in the returned ByteString. + /// This method can also be invoked in ByteString.CopyFrom(0xaa, 0xbb, ...) form + /// which is primarily useful for testing. + /// + public static ByteString CopyFrom(params byte[] bytes) + { + return new ByteString((byte[]) bytes.Clone()); + } + + /// + /// Constructs a from a portion of a byte array. + /// + public static ByteString CopyFrom(byte[] bytes, int offset, int count) + { + byte[] portion = new byte[count]; + ByteArray.Copy(bytes, offset, portion, 0, count); + return new ByteString(portion); + } + + /// + /// Constructs a from a read only span. The contents + /// are copied, so further modifications to the span will not + /// be reflected in the returned . + /// + public static ByteString CopyFrom(ReadOnlySpan bytes) + { + return new ByteString(bytes.ToArray()); + } + + /// + /// Creates a new by encoding the specified text with + /// the given encoding. + /// + public static ByteString CopyFrom(string text, Encoding encoding) + { + return new ByteString(encoding.GetBytes(text)); + } + + /// + /// Creates a new by encoding the specified text in UTF-8. + /// + public static ByteString CopyFromUtf8(string text) + { + return CopyFrom(text, Encoding.UTF8); + } + + /// + /// Returns the byte at the given index. + /// + public byte this[int index] + { + get { return bytes.Span[index]; } + } + + /// + /// Converts this into a string by applying the given encoding. + /// + /// + /// This method should only be used to convert binary data which was the result of encoding + /// text with the given encoding. + /// + /// The encoding to use to decode the binary data into text. + /// The result of decoding the binary data with the given decoding. + public string ToString(Encoding encoding) + { + if (MemoryMarshal.TryGetArray(bytes, out ArraySegment segment)) + { + // Fast path. ByteString was created with an array. + return encoding.GetString(segment.Array, segment.Offset, segment.Count); + } + else + { + // Slow path. BytesString is not an array. Convert memory and pass result to GetString. + // TODO: Consider using GetString overload that takes a pointer. + byte[] array = bytes.ToArray(); + return encoding.GetString(array, 0, array.Length); + } + } + + /// + /// Converts this into a string by applying the UTF-8 encoding. + /// + /// + /// This method should only be used to convert binary data which was the result of encoding + /// text with UTF-8. + /// + /// The result of decoding the binary data with the given decoding. + public string ToStringUtf8() + { + return ToString(Encoding.UTF8); + } + + /// + /// Returns an iterator over the bytes in this . + /// + /// An iterator over the bytes in this object. + [SecuritySafeCritical] + public IEnumerator GetEnumerator() + { + return MemoryMarshal.ToEnumerable(bytes).GetEnumerator(); + } + + /// + /// Returns an iterator over the bytes in this . + /// + /// An iterator over the bytes in this object. + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Creates a CodedInputStream from this ByteString's data. + /// + public CodedInputStream CreateCodedInput() + { + // We trust CodedInputStream not to reveal the provided byte array or modify it + if (MemoryMarshal.TryGetArray(bytes, out ArraySegment segment) && segment.Count == bytes.Length) + { + // Fast path. ByteString was created with a complete array. + return new CodedInputStream(segment.Array); + } + else + { + // Slow path. BytesString is not an array, or is a slice of an array. + // Convert memory and pass result to WriteRawBytes. + return new CodedInputStream(bytes.ToArray()); + } + } + + /// + /// Compares two byte strings for equality. + /// + /// The first byte string to compare. + /// The second byte string to compare. + /// true if the byte strings are equal; false otherwise. + public static bool operator ==(ByteString lhs, ByteString rhs) + { + if (ReferenceEquals(lhs, rhs)) + { + return true; + } + if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) + { + return false; + } + + return lhs.bytes.Span.SequenceEqual(rhs.bytes.Span); + } + + /// + /// Compares two byte strings for inequality. + /// + /// The first byte string to compare. + /// The second byte string to compare. + /// false if the byte strings are equal; true otherwise. + public static bool operator !=(ByteString lhs, ByteString rhs) + { + return !(lhs == rhs); + } + + /// + /// Compares this byte string with another object. + /// + /// The object to compare this with. + /// true if refers to an equal ; false otherwise. + [SecuritySafeCritical] + public override bool Equals(object obj) + { + return this == (obj as ByteString); + } + + /// + /// Returns a hash code for this object. Two equal byte strings + /// will return the same hash code. + /// + /// A hash code for this object. + [SecuritySafeCritical] + public override int GetHashCode() + { + ReadOnlySpan b = bytes.Span; + + int ret = 23; + for (int i = 0; i < b.Length; i++) + { + ret = (ret * 31) + b[i]; + } + return ret; + } + + /// + /// Compares this byte string with another. + /// + /// The to compare this with. + /// true if refers to an equal byte string; false otherwise. + public bool Equals(ByteString other) + { + return this == other; + } + + /// + /// Copies the entire byte array to the destination array provided at the offset specified. + /// + public void CopyTo(byte[] array, int position) + { + bytes.CopyTo(array.AsMemory(position)); + } + + /// + /// Writes the entire byte array to the provided stream + /// + public void WriteTo(Stream outputStream) + { + if (MemoryMarshal.TryGetArray(bytes, out ArraySegment segment)) + { + // Fast path. ByteString was created with an array, so pass the underlying array. + outputStream.Write(segment.Array, segment.Offset, segment.Count); + } + else + { + // Slow path. BytesString is not an array. Convert memory and pass result to WriteRawBytes. + var array = bytes.ToArray(); + outputStream.Write(array, 0, array.Length); + } + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/ByteStringAsync.cs b/Libs/Google.Protobuf/ByteStringAsync.cs new file mode 100644 index 0000000..68c4d7f --- /dev/null +++ b/Libs/Google.Protobuf/ByteStringAsync.cs @@ -0,0 +1,64 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace LC.Google.Protobuf +{ + /// + /// SecuritySafeCritical attribute can not be placed on types with async methods. + /// This class has ByteString's async methods so it can be marked with SecuritySafeCritical. + /// + internal static class ByteStringAsync + { +#if !NET35 + internal static async Task FromStreamAsyncCore(Stream stream, CancellationToken cancellationToken) + { + int capacity = stream.CanSeek ? checked((int)(stream.Length - stream.Position)) : 0; + var memoryStream = new MemoryStream(capacity); + // We have to specify the buffer size here, as there's no overload accepting the cancellation token + // alone. But it's documented to use 81920 by default if not specified. + await stream.CopyToAsync(memoryStream, 81920, cancellationToken); +#if NETSTANDARD1_1 + byte[] bytes = memoryStream.ToArray(); +#else + // Avoid an extra copy if we can. + byte[] bytes = memoryStream.Length == memoryStream.Capacity ? memoryStream.GetBuffer() : memoryStream.ToArray(); +#endif + return ByteString.AttachBytes(bytes); + } +#endif + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/CodedInputStream.cs b/Libs/Google.Protobuf/CodedInputStream.cs new file mode 100644 index 0000000..3660c19 --- /dev/null +++ b/Libs/Google.Protobuf/CodedInputStream.cs @@ -0,0 +1,699 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// Reads and decodes protocol message fields. + /// + /// + /// + /// This class is generally used by generated code to read appropriate + /// primitives from the stream. It effectively encapsulates the lowest + /// levels of protocol buffer format. + /// + /// + /// Repeated fields and map fields are not handled by this class; use + /// and to serialize such fields. + /// + /// + [SecuritySafeCritical] + public sealed class CodedInputStream : IDisposable + { + /// + /// Whether to leave the underlying stream open when disposing of this stream. + /// This is always true when there's no stream. + /// + private readonly bool leaveOpen; + + /// + /// Buffer of data read from the stream or provided at construction time. + /// + private readonly byte[] buffer; + + /// + /// The stream to read further input from, or null if the byte array buffer was provided + /// directly on construction, with no further data available. + /// + private readonly Stream input; + + /// + /// The parser state is kept separately so that other parse implementations can reuse the same + /// parsing primitives. + /// + private ParserInternalState state; + + internal const int DefaultRecursionLimit = 100; + internal const int DefaultSizeLimit = Int32.MaxValue; + internal const int BufferSize = 4096; + + #region Construction + // Note that the checks are performed such that we don't end up checking obviously-valid things + // like non-null references for arrays we've just created. + + /// + /// Creates a new CodedInputStream reading data from the given byte array. + /// + public CodedInputStream(byte[] buffer) : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), 0, buffer.Length, true) + { + } + + /// + /// Creates a new that reads from the given byte array slice. + /// + public CodedInputStream(byte[] buffer, int offset, int length) + : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), offset, offset + length, true) + { + if (offset < 0 || offset > buffer.Length) + { + throw new ArgumentOutOfRangeException("offset", "Offset must be within the buffer"); + } + if (length < 0 || offset + length > buffer.Length) + { + throw new ArgumentOutOfRangeException("length", "Length must be non-negative and within the buffer"); + } + } + + /// + /// Creates a new reading data from the given stream, which will be disposed + /// when the returned object is disposed. + /// + /// The stream to read from. + public CodedInputStream(Stream input) : this(input, false) + { + } + + /// + /// Creates a new reading data from the given stream. + /// + /// The stream to read from. + /// true to leave open when the returned + /// is disposed; false to dispose of the given stream when the + /// returned object is disposed. + public CodedInputStream(Stream input, bool leaveOpen) + : this(ProtoPreconditions.CheckNotNull(input, "input"), new byte[BufferSize], 0, 0, leaveOpen) + { + } + + /// + /// Creates a new CodedInputStream reading data from the given + /// stream and buffer, using the default limits. + /// + internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize, bool leaveOpen) + { + this.input = input; + this.buffer = buffer; + this.state.bufferPos = bufferPos; + this.state.bufferSize = bufferSize; + this.state.sizeLimit = DefaultSizeLimit; + this.state.recursionLimit = DefaultRecursionLimit; + SegmentedBufferHelper.Initialize(this, out this.state.segmentedBufferHelper); + this.leaveOpen = leaveOpen; + + this.state.currentLimit = int.MaxValue; + } + + /// + /// Creates a new CodedInputStream reading data from the given + /// stream and buffer, using the specified limits. + /// + /// + /// This chains to the version with the default limits instead of vice versa to avoid + /// having to check that the default values are valid every time. + /// + internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize, int sizeLimit, int recursionLimit, bool leaveOpen) + : this(input, buffer, bufferPos, bufferSize, leaveOpen) + { + if (sizeLimit <= 0) + { + throw new ArgumentOutOfRangeException("sizeLimit", "Size limit must be positive"); + } + if (recursionLimit <= 0) + { + throw new ArgumentOutOfRangeException("recursionLimit!", "Recursion limit must be positive"); + } + this.state.sizeLimit = sizeLimit; + this.state.recursionLimit = recursionLimit; + } + #endregion + + /// + /// Creates a with the specified size and recursion limits, reading + /// from an input stream. + /// + /// + /// This method exists separately from the constructor to reduce the number of constructor overloads. + /// It is likely to be used considerably less frequently than the constructors, as the default limits + /// are suitable for most use cases. + /// + /// The input stream to read from + /// The total limit of data to read from the stream. + /// The maximum recursion depth to allow while reading. + /// A CodedInputStream reading from with the specified size + /// and recursion limits. + public static CodedInputStream CreateWithLimits(Stream input, int sizeLimit, int recursionLimit) + { + // Note: we may want an overload accepting leaveOpen + return new CodedInputStream(input, new byte[BufferSize], 0, 0, sizeLimit, recursionLimit, false); + } + + /// + /// Returns the current position in the input stream, or the position in the input buffer + /// + public long Position + { + get + { + if (input != null) + { + return input.Position - ((state.bufferSize + state.bufferSizeAfterLimit) - state.bufferPos); + } + return state.bufferPos; + } + } + + /// + /// Returns the last tag read, or 0 if no tags have been read or we've read beyond + /// the end of the stream. + /// + internal uint LastTag { get { return state.lastTag; } } + + /// + /// Returns the size limit for this stream. + /// + /// + /// This limit is applied when reading from the underlying stream, as a sanity check. It is + /// not applied when reading from a byte array data source without an underlying stream. + /// The default value is Int32.MaxValue. + /// + /// + /// The size limit. + /// + public int SizeLimit { get { return state.sizeLimit; } } + + /// + /// Returns the recursion limit for this stream. This limit is applied whilst reading messages, + /// to avoid maliciously-recursive data. + /// + /// + /// The default limit is 100. + /// + /// + /// The recursion limit for this stream. + /// + public int RecursionLimit { get { return state.recursionLimit; } } + + /// + /// Internal-only property; when set to true, unknown fields will be discarded while parsing. + /// + internal bool DiscardUnknownFields + { + get { return state.DiscardUnknownFields; } + set { state.DiscardUnknownFields = value; } + } + + /// + /// Internal-only property; provides extension identifiers to compatible messages while parsing. + /// + internal ExtensionRegistry ExtensionRegistry + { + get { return state.ExtensionRegistry; } + set { state.ExtensionRegistry = value; } + } + + internal byte[] InternalBuffer => buffer; + + internal Stream InternalInputStream => input; + + internal ref ParserInternalState InternalState => ref state; + + /// + /// Disposes of this instance, potentially closing any underlying stream. + /// + /// + /// As there is no flushing to perform here, disposing of a which + /// was constructed with the leaveOpen option parameter set to true (or one which + /// was constructed to read from a byte array) has no effect. + /// + public void Dispose() + { + if (!leaveOpen) + { + input.Dispose(); + } + } + + #region Validation + /// + /// Verifies that the last call to ReadTag() returned tag 0 - in other words, + /// we've reached the end of the stream when we expected to. + /// + /// The + /// tag read was not the one specified + internal void CheckReadEndOfStreamTag() + { + ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref state); + } + #endregion + + #region Reading of tags etc + + /// + /// Peeks at the next field tag. This is like calling , but the + /// tag is not consumed. (So a subsequent call to will return the + /// same value.) + /// + public uint PeekTag() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.PeekTag(ref span, ref state); + } + + /// + /// Reads a field tag, returning the tag of 0 for "end of stream". + /// + /// + /// If this method returns 0, it doesn't necessarily mean the end of all + /// the data in this CodedInputStream; it may be the end of the logical stream + /// for an embedded message, for example. + /// + /// The next field tag, or 0 for end of stream. (0 is never a valid tag.) + public uint ReadTag() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseTag(ref span, ref state); + } + + /// + /// Skips the data for the field with the tag we've just read. + /// This should be called directly after , when + /// the caller wishes to skip an unknown field. + /// + /// + /// This method throws if the last-read tag was an end-group tag. + /// If a caller wishes to skip a group, they should skip the whole group, by calling this method after reading the + /// start-group tag. This behavior allows callers to call this method on any field they don't understand, correctly + /// resulting in an error if an end-group tag has not been paired with an earlier start-group tag. + /// + /// The last tag was an end-group tag + /// The last read operation read to the end of the logical stream + public void SkipLastField() + { + var span = new ReadOnlySpan(buffer); + ParsingPrimitivesMessages.SkipLastField(ref span, ref state); + } + + /// + /// Skip a group. + /// + internal void SkipGroup(uint startGroupTag) + { + var span = new ReadOnlySpan(buffer); + ParsingPrimitivesMessages.SkipGroup(ref span, ref state, startGroupTag); + } + + /// + /// Reads a double field from the stream. + /// + public double ReadDouble() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseDouble(ref span, ref state); + } + + /// + /// Reads a float field from the stream. + /// + public float ReadFloat() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseFloat(ref span, ref state); + } + + /// + /// Reads a uint64 field from the stream. + /// + public ulong ReadUInt64() + { + return ReadRawVarint64(); + } + + /// + /// Reads an int64 field from the stream. + /// + public long ReadInt64() + { + return (long) ReadRawVarint64(); + } + + /// + /// Reads an int32 field from the stream. + /// + public int ReadInt32() + { + return (int) ReadRawVarint32(); + } + + /// + /// Reads a fixed64 field from the stream. + /// + public ulong ReadFixed64() + { + return ReadRawLittleEndian64(); + } + + /// + /// Reads a fixed32 field from the stream. + /// + public uint ReadFixed32() + { + return ReadRawLittleEndian32(); + } + + /// + /// Reads a bool field from the stream. + /// + public bool ReadBool() + { + return ReadRawVarint64() != 0; + } + + /// + /// Reads a string field from the stream. + /// + public string ReadString() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ReadString(ref span, ref state); + } + + /// + /// Reads an embedded message field value from the stream. + /// + public void ReadMessage(IMessage builder) + { + // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalMergeFrom method), + // what we're doing here works fine, but could be more efficient. + // What happends is that we first initialize a ParseContext from the current coded input stream only to parse the length of the message, at which point + // we will need to switch back again to CodedInputStream-based parsing (which involves copying and storing the state) to be able to + // invoke the legacy MergeFrom(CodedInputStream) method. + // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it). + var span = new ReadOnlySpan(buffer); + ParseContext.Initialize(ref span, ref state, out ParseContext ctx); + try + { + ParsingPrimitivesMessages.ReadMessage(ref ctx, builder); + } + finally + { + ctx.CopyStateTo(this); + } + } + + /// + /// Reads an embedded group field from the stream. + /// + public void ReadGroup(IMessage builder) + { + ParseContext.Initialize(this, out ParseContext ctx); + try + { + ParsingPrimitivesMessages.ReadGroup(ref ctx, builder); + } + finally + { + ctx.CopyStateTo(this); + } + } + + /// + /// Reads a bytes field value from the stream. + /// + public ByteString ReadBytes() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ReadBytes(ref span, ref state); + } + + /// + /// Reads a uint32 field value from the stream. + /// + public uint ReadUInt32() + { + return ReadRawVarint32(); + } + + /// + /// Reads an enum field value from the stream. + /// + public int ReadEnum() + { + // Currently just a pass-through, but it's nice to separate it logically from WriteInt32. + return (int) ReadRawVarint32(); + } + + /// + /// Reads an sfixed32 field value from the stream. + /// + public int ReadSFixed32() + { + return (int) ReadRawLittleEndian32(); + } + + /// + /// Reads an sfixed64 field value from the stream. + /// + public long ReadSFixed64() + { + return (long) ReadRawLittleEndian64(); + } + + /// + /// Reads an sint32 field value from the stream. + /// + public int ReadSInt32() + { + return ParsingPrimitives.DecodeZigZag32(ReadRawVarint32()); + } + + /// + /// Reads an sint64 field value from the stream. + /// + public long ReadSInt64() + { + return ParsingPrimitives.DecodeZigZag64(ReadRawVarint64()); + } + + /// + /// Reads a length for length-delimited data. + /// + /// + /// This is internally just reading a varint, but this method exists + /// to make the calling code clearer. + /// + public int ReadLength() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseLength(ref span, ref state); + } + + /// + /// Peeks at the next tag in the stream. If it matches , + /// the tag is consumed and the method returns true; otherwise, the + /// stream is left in the original position and the method returns false. + /// + public bool MaybeConsumeTag(uint tag) + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.MaybeConsumeTag(ref span, ref state, tag); + } + +#endregion + + #region Underlying reading primitives + + /// + /// Reads a raw Varint from the stream. If larger than 32 bits, discard the upper bits. + /// This method is optimised for the case where we've got lots of data in the buffer. + /// That means we can check the size just once, then just read directly from the buffer + /// without constant rechecking of the buffer length. + /// + internal uint ReadRawVarint32() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseRawVarint32(ref span, ref state); + } + + /// + /// Reads a varint from the input one byte at a time, so that it does not + /// read any bytes after the end of the varint. If you simply wrapped the + /// stream in a CodedInputStream and used ReadRawVarint32(Stream) + /// then you would probably end up reading past the end of the varint since + /// CodedInputStream buffers its input. + /// + /// + /// + internal static uint ReadRawVarint32(Stream input) + { + return ParsingPrimitives.ReadRawVarint32(input); + } + + /// + /// Reads a raw varint from the stream. + /// + internal ulong ReadRawVarint64() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseRawVarint64(ref span, ref state); + } + + /// + /// Reads a 32-bit little-endian integer from the stream. + /// + internal uint ReadRawLittleEndian32() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseRawLittleEndian32(ref span, ref state); + } + + /// + /// Reads a 64-bit little-endian integer from the stream. + /// + internal ulong ReadRawLittleEndian64() + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ParseRawLittleEndian64(ref span, ref state); + } + #endregion + + #region Internal reading and buffer management + + /// + /// Sets currentLimit to (current position) + byteLimit. This is called + /// when descending into a length-delimited embedded message. The previous + /// limit is returned. + /// + /// The old limit. + internal int PushLimit(int byteLimit) + { + return SegmentedBufferHelper.PushLimit(ref state, byteLimit); + } + + /// + /// Discards the current limit, returning the previous limit. + /// + internal void PopLimit(int oldLimit) + { + SegmentedBufferHelper.PopLimit(ref state, oldLimit); + } + + /// + /// Returns whether or not all the data before the limit has been read. + /// + /// + internal bool ReachedLimit + { + get + { + return SegmentedBufferHelper.IsReachedLimit(ref state); + } + } + + /// + /// Returns true if the stream has reached the end of the input. This is the + /// case if either the end of the underlying input source has been reached or + /// the stream has reached a limit created using PushLimit. + /// + public bool IsAtEnd + { + get + { + var span = new ReadOnlySpan(buffer); + return SegmentedBufferHelper.IsAtEnd(ref span, ref state); + } + } + + /// + /// Called when buffer is empty to read more bytes from the + /// input. If is true, RefillBuffer() guarantees that + /// either there will be at least one byte in the buffer when it returns + /// or it will throw an exception. If is false, + /// RefillBuffer() returns false if no more bytes were available. + /// + /// + /// + private bool RefillBuffer(bool mustSucceed) + { + var span = new ReadOnlySpan(buffer); + return state.segmentedBufferHelper.RefillBuffer(ref span, ref state, mustSucceed); + } + + /// + /// Reads a fixed size of bytes from the input. + /// + /// + /// the end of the stream or the current limit was reached + /// + internal byte[] ReadRawBytes(int size) + { + var span = new ReadOnlySpan(buffer); + return ParsingPrimitives.ReadRawBytes(ref span, ref state, size); + } + + /// + /// Reads a top-level message or a nested message after the limits for this message have been pushed. + /// (parser will proceed until the end of the current limit) + /// NOTE: this method needs to be public because it's invoked by the generated code - e.g. msg.MergeFrom(CodedInputStream input) method + /// + public void ReadRawMessage(IMessage message) + { + ParseContext.Initialize(this, out ParseContext ctx); + try + { + ParsingPrimitivesMessages.ReadRawMessage(ref ctx, message); + } + finally + { + ctx.CopyStateTo(this); + } + } +#endregion + } +} diff --git a/Libs/Google.Protobuf/CodedOutputStream.ComputeSize.cs b/Libs/Google.Protobuf/CodedOutputStream.ComputeSize.cs new file mode 100644 index 0000000..f6992be --- /dev/null +++ b/Libs/Google.Protobuf/CodedOutputStream.ComputeSize.cs @@ -0,0 +1,308 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf +{ + // This part of CodedOutputStream provides all the static entry points that are used + // by generated code and internally to compute the size of messages prior to being + // written to an instance of CodedOutputStream. + public sealed partial class CodedOutputStream + { + private const int LittleEndian64Size = 8; + private const int LittleEndian32Size = 4; + + internal const int DoubleSize = LittleEndian64Size; + internal const int FloatSize = LittleEndian32Size; + internal const int BoolSize = 1; + + /// + /// Computes the number of bytes that would be needed to encode a + /// double field, including the tag. + /// + public static int ComputeDoubleSize(double value) + { + return DoubleSize; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// float field, including the tag. + /// + public static int ComputeFloatSize(float value) + { + return FloatSize; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// uint64 field, including the tag. + /// + public static int ComputeUInt64Size(ulong value) + { + return ComputeRawVarint64Size(value); + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// int64 field, including the tag. + /// + public static int ComputeInt64Size(long value) + { + return ComputeRawVarint64Size((ulong) value); + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// int32 field, including the tag. + /// + public static int ComputeInt32Size(int value) + { + if (value >= 0) + { + return ComputeRawVarint32Size((uint) value); + } + else + { + // Must sign-extend. + return 10; + } + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// fixed64 field, including the tag. + /// + public static int ComputeFixed64Size(ulong value) + { + return LittleEndian64Size; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// fixed32 field, including the tag. + /// + public static int ComputeFixed32Size(uint value) + { + return LittleEndian32Size; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// bool field, including the tag. + /// + public static int ComputeBoolSize(bool value) + { + return BoolSize; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// string field, including the tag. + /// + public static int ComputeStringSize(String value) + { + int byteArraySize = WritingPrimitives.Utf8Encoding.GetByteCount(value); + return ComputeLengthSize(byteArraySize) + byteArraySize; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// group field, including the tag. + /// + public static int ComputeGroupSize(IMessage value) + { + return value.CalculateSize(); + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// embedded message field, including the tag. + /// + public static int ComputeMessageSize(IMessage value) + { + int size = value.CalculateSize(); + return ComputeLengthSize(size) + size; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// bytes field, including the tag. + /// + public static int ComputeBytesSize(ByteString value) + { + return ComputeLengthSize(value.Length) + value.Length; + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// uint32 field, including the tag. + /// + public static int ComputeUInt32Size(uint value) + { + return ComputeRawVarint32Size(value); + } + + /// + /// Computes the number of bytes that would be needed to encode a + /// enum field, including the tag. The caller is responsible for + /// converting the enum value to its numeric value. + /// + public static int ComputeEnumSize(int value) + { + // Currently just a pass-through, but it's nice to separate it logically. + return ComputeInt32Size(value); + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// sfixed32 field, including the tag. + /// + public static int ComputeSFixed32Size(int value) + { + return LittleEndian32Size; + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// sfixed64 field, including the tag. + /// + public static int ComputeSFixed64Size(long value) + { + return LittleEndian64Size; + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// sint32 field, including the tag. + /// + public static int ComputeSInt32Size(int value) + { + return ComputeRawVarint32Size(WritingPrimitives.EncodeZigZag32(value)); + } + + /// + /// Computes the number of bytes that would be needed to encode an + /// sint64 field, including the tag. + /// + public static int ComputeSInt64Size(long value) + { + return ComputeRawVarint64Size(WritingPrimitives.EncodeZigZag64(value)); + } + + /// + /// Computes the number of bytes that would be needed to encode a length, + /// as written by . + /// + public static int ComputeLengthSize(int length) + { + return ComputeRawVarint32Size((uint) length); + } + + /// + /// Computes the number of bytes that would be needed to encode a varint. + /// + public static int ComputeRawVarint32Size(uint value) + { + if ((value & (0xffffffff << 7)) == 0) + { + return 1; + } + if ((value & (0xffffffff << 14)) == 0) + { + return 2; + } + if ((value & (0xffffffff << 21)) == 0) + { + return 3; + } + if ((value & (0xffffffff << 28)) == 0) + { + return 4; + } + return 5; + } + + /// + /// Computes the number of bytes that would be needed to encode a varint. + /// + public static int ComputeRawVarint64Size(ulong value) + { + if ((value & (0xffffffffffffffffL << 7)) == 0) + { + return 1; + } + if ((value & (0xffffffffffffffffL << 14)) == 0) + { + return 2; + } + if ((value & (0xffffffffffffffffL << 21)) == 0) + { + return 3; + } + if ((value & (0xffffffffffffffffL << 28)) == 0) + { + return 4; + } + if ((value & (0xffffffffffffffffL << 35)) == 0) + { + return 5; + } + if ((value & (0xffffffffffffffffL << 42)) == 0) + { + return 6; + } + if ((value & (0xffffffffffffffffL << 49)) == 0) + { + return 7; + } + if ((value & (0xffffffffffffffffL << 56)) == 0) + { + return 8; + } + if ((value & (0xffffffffffffffffL << 63)) == 0) + { + return 9; + } + return 10; + } + + /// + /// Computes the number of bytes that would be needed to encode a tag. + /// + public static int ComputeTagSize(int fieldNumber) + { + return ComputeRawVarint32Size(WireFormat.MakeTag(fieldNumber, 0)); + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/CodedOutputStream.cs b/Libs/Google.Protobuf/CodedOutputStream.cs new file mode 100644 index 0000000..e717806 --- /dev/null +++ b/Libs/Google.Protobuf/CodedOutputStream.cs @@ -0,0 +1,607 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; +using System.IO; +using System.Security; +using System.Text; + +namespace LC.Google.Protobuf +{ + /// + /// Encodes and writes protocol message fields. + /// + /// + /// + /// This class is generally used by generated code to write appropriate + /// primitives to the stream. It effectively encapsulates the lowest + /// levels of protocol buffer format. Unlike some other implementations, + /// this does not include combined "write tag and value" methods. Generated + /// code knows the exact byte representations of the tags they're going to write, + /// so there's no need to re-encode them each time. Manually-written code calling + /// this class should just call one of the WriteTag overloads before each value. + /// + /// + /// Repeated fields and map fields are not handled by this class; use RepeatedField<T> + /// and MapField<TKey, TValue> to serialize such fields. + /// + /// + [SecuritySafeCritical] + public sealed partial class CodedOutputStream : IDisposable + { + /// + /// The buffer size used by CreateInstance(Stream). + /// + public static readonly int DefaultBufferSize = 4096; + + private readonly bool leaveOpen; + private readonly byte[] buffer; + private WriterInternalState state; + + private readonly Stream output; + + #region Construction + /// + /// Creates a new CodedOutputStream that writes directly to the given + /// byte array. If more bytes are written than fit in the array, + /// OutOfSpaceException will be thrown. + /// + public CodedOutputStream(byte[] flatArray) : this(flatArray, 0, flatArray.Length) + { + } + + /// + /// Creates a new CodedOutputStream that writes directly to the given + /// byte array slice. If more bytes are written than fit in the array, + /// OutOfSpaceException will be thrown. + /// + private CodedOutputStream(byte[] buffer, int offset, int length) + { + this.output = null; + this.buffer = ProtoPreconditions.CheckNotNull(buffer, nameof(buffer)); + this.state.position = offset; + this.state.limit = offset + length; + WriteBufferHelper.Initialize(this, out this.state.writeBufferHelper); + leaveOpen = true; // Simple way of avoiding trying to dispose of a null reference + } + + private CodedOutputStream(Stream output, byte[] buffer, bool leaveOpen) + { + this.output = ProtoPreconditions.CheckNotNull(output, nameof(output)); + this.buffer = buffer; + this.state.position = 0; + this.state.limit = buffer.Length; + WriteBufferHelper.Initialize(this, out this.state.writeBufferHelper); + this.leaveOpen = leaveOpen; + } + + /// + /// Creates a new which write to the given stream, and disposes of that + /// stream when the returned CodedOutputStream is disposed. + /// + /// The stream to write to. It will be disposed when the returned CodedOutputStream is disposed. + public CodedOutputStream(Stream output) : this(output, DefaultBufferSize, false) + { + } + + /// + /// Creates a new CodedOutputStream which write to the given stream and uses + /// the specified buffer size. + /// + /// The stream to write to. It will be disposed when the returned CodedOutputStream is disposed. + /// The size of buffer to use internally. + public CodedOutputStream(Stream output, int bufferSize) : this(output, new byte[bufferSize], false) + { + } + + /// + /// Creates a new CodedOutputStream which write to the given stream. + /// + /// The stream to write to. + /// If true, is left open when the returned CodedOutputStream is disposed; + /// if false, the provided stream is disposed as well. + public CodedOutputStream(Stream output, bool leaveOpen) : this(output, DefaultBufferSize, leaveOpen) + { + } + + /// + /// Creates a new CodedOutputStream which write to the given stream and uses + /// the specified buffer size. + /// + /// The stream to write to. + /// The size of buffer to use internally. + /// If true, is left open when the returned CodedOutputStream is disposed; + /// if false, the provided stream is disposed as well. + public CodedOutputStream(Stream output, int bufferSize, bool leaveOpen) : this(output, new byte[bufferSize], leaveOpen) + { + } + #endregion + + /// + /// Returns the current position in the stream, or the position in the output buffer + /// + public long Position + { + get + { + if (output != null) + { + return output.Position + state.position; + } + return state.position; + } + } + + #region Writing of values (not including tags) + + /// + /// Writes a double field value, without a tag, to the stream. + /// + /// The value to write + public void WriteDouble(double value) + { + var span = new Span(buffer); + WritingPrimitives.WriteDouble(ref span, ref state, value); + } + + /// + /// Writes a float field value, without a tag, to the stream. + /// + /// The value to write + public void WriteFloat(float value) + { + var span = new Span(buffer); + WritingPrimitives.WriteFloat(ref span, ref state, value); + } + + /// + /// Writes a uint64 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteUInt64(ulong value) + { + var span = new Span(buffer); + WritingPrimitives.WriteUInt64(ref span, ref state, value); + } + + /// + /// Writes an int64 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteInt64(long value) + { + var span = new Span(buffer); + WritingPrimitives.WriteInt64(ref span, ref state, value); + } + + /// + /// Writes an int32 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteInt32(int value) + { + var span = new Span(buffer); + WritingPrimitives.WriteInt32(ref span, ref state, value); + } + + /// + /// Writes a fixed64 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteFixed64(ulong value) + { + var span = new Span(buffer); + WritingPrimitives.WriteFixed64(ref span, ref state, value); + } + + /// + /// Writes a fixed32 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteFixed32(uint value) + { + var span = new Span(buffer); + WritingPrimitives.WriteFixed32(ref span, ref state, value); + } + + /// + /// Writes a bool field value, without a tag, to the stream. + /// + /// The value to write + public void WriteBool(bool value) + { + var span = new Span(buffer); + WritingPrimitives.WriteBool(ref span, ref state, value); + } + + /// + /// Writes a string field value, without a tag, to the stream. + /// The data is length-prefixed. + /// + /// The value to write + public void WriteString(string value) + { + var span = new Span(buffer); + WritingPrimitives.WriteString(ref span, ref state, value); + } + + /// + /// Writes a message, without a tag, to the stream. + /// The data is length-prefixed. + /// + /// The value to write + public void WriteMessage(IMessage value) + { + // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalWriteTo method), + // what we're doing here works fine, but could be more efficient. + // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it). + var span = new Span(buffer); + WriteContext.Initialize(ref span, ref state, out WriteContext ctx); + try + { + WritingPrimitivesMessages.WriteMessage(ref ctx, value); + } + finally + { + ctx.CopyStateTo(this); + } + } + + /// + /// Writes a message, without a tag, to the stream. + /// Only the message data is written, without a length-delimiter. + /// + /// The value to write + public void WriteRawMessage(IMessage value) + { + // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalWriteTo method), + // what we're doing here works fine, but could be more efficient. + // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it). + var span = new Span(buffer); + WriteContext.Initialize(ref span, ref state, out WriteContext ctx); + try + { + WritingPrimitivesMessages.WriteRawMessage(ref ctx, value); + } + finally + { + ctx.CopyStateTo(this); + } + } + + /// + /// Writes a group, without a tag, to the stream. + /// + /// The value to write + public void WriteGroup(IMessage value) + { + var span = new Span(buffer); + WriteContext.Initialize(ref span, ref state, out WriteContext ctx); + try + { + WritingPrimitivesMessages.WriteGroup(ref ctx, value); + } + finally + { + ctx.CopyStateTo(this); + } + } + + /// + /// Write a byte string, without a tag, to the stream. + /// The data is length-prefixed. + /// + /// The value to write + public void WriteBytes(ByteString value) + { + var span = new Span(buffer); + WritingPrimitives.WriteBytes(ref span, ref state, value); + } + + /// + /// Writes a uint32 value, without a tag, to the stream. + /// + /// The value to write + public void WriteUInt32(uint value) + { + var span = new Span(buffer); + WritingPrimitives.WriteUInt32(ref span, ref state, value); + } + + /// + /// Writes an enum value, without a tag, to the stream. + /// + /// The value to write + public void WriteEnum(int value) + { + var span = new Span(buffer); + WritingPrimitives.WriteEnum(ref span, ref state, value); + } + + /// + /// Writes an sfixed32 value, without a tag, to the stream. + /// + /// The value to write. + public void WriteSFixed32(int value) + { + var span = new Span(buffer); + WritingPrimitives.WriteSFixed32(ref span, ref state, value); + } + + /// + /// Writes an sfixed64 value, without a tag, to the stream. + /// + /// The value to write + public void WriteSFixed64(long value) + { + var span = new Span(buffer); + WritingPrimitives.WriteSFixed64(ref span, ref state, value); + } + + /// + /// Writes an sint32 value, without a tag, to the stream. + /// + /// The value to write + public void WriteSInt32(int value) + { + var span = new Span(buffer); + WritingPrimitives.WriteSInt32(ref span, ref state, value); + } + + /// + /// Writes an sint64 value, without a tag, to the stream. + /// + /// The value to write + public void WriteSInt64(long value) + { + var span = new Span(buffer); + WritingPrimitives.WriteSInt64(ref span, ref state, value); + } + + /// + /// Writes a length (in bytes) for length-delimited data. + /// + /// + /// This method simply writes a rawint, but exists for clarity in calling code. + /// + /// Length value, in bytes. + public void WriteLength(int length) + { + var span = new Span(buffer); + WritingPrimitives.WriteLength(ref span, ref state, length); + } + + #endregion + + #region Raw tag writing + /// + /// Encodes and writes a tag. + /// + /// The number of the field to write the tag for + /// The wire format type of the tag to write + public void WriteTag(int fieldNumber, WireFormat.WireType type) + { + var span = new Span(buffer); + WritingPrimitives.WriteTag(ref span, ref state, fieldNumber, type); + } + + /// + /// Writes an already-encoded tag. + /// + /// The encoded tag + public void WriteTag(uint tag) + { + var span = new Span(buffer); + WritingPrimitives.WriteTag(ref span, ref state, tag); + } + + /// + /// Writes the given single-byte tag directly to the stream. + /// + /// The encoded tag + public void WriteRawTag(byte b1) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawTag(ref span, ref state, b1); + } + + /// + /// Writes the given two-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + public void WriteRawTag(byte b1, byte b2) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2); + } + + /// + /// Writes the given three-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + /// The third byte of the encoded tag + public void WriteRawTag(byte b1, byte b2, byte b3) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2, b3); + } + + /// + /// Writes the given four-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + /// The third byte of the encoded tag + /// The fourth byte of the encoded tag + public void WriteRawTag(byte b1, byte b2, byte b3, byte b4) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2, b3, b4); + } + + /// + /// Writes the given five-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + /// The third byte of the encoded tag + /// The fourth byte of the encoded tag + /// The fifth byte of the encoded tag + public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2, b3, b4, b5); + } + #endregion + + #region Underlying writing primitives + + /// + /// Writes a 32 bit value as a varint. The fast route is taken when + /// there's enough buffer space left to whizz through without checking + /// for each byte; otherwise, we resort to calling WriteRawByte each time. + /// + internal void WriteRawVarint32(uint value) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawVarint32(ref span, ref state, value); + } + + internal void WriteRawVarint64(ulong value) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawVarint64(ref span, ref state, value); + } + + internal void WriteRawLittleEndian32(uint value) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawLittleEndian32(ref span, ref state, value); + } + + internal void WriteRawLittleEndian64(ulong value) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawLittleEndian64(ref span, ref state, value); + } + + /// + /// Writes out an array of bytes. + /// + internal void WriteRawBytes(byte[] value) + { + WriteRawBytes(value, 0, value.Length); + } + + /// + /// Writes out part of an array of bytes. + /// + internal void WriteRawBytes(byte[] value, int offset, int length) + { + var span = new Span(buffer); + WritingPrimitives.WriteRawBytes(ref span, ref state, value, offset, length); + } + + #endregion + + /// + /// Indicates that a CodedOutputStream wrapping a flat byte array + /// ran out of space. + /// + public sealed class OutOfSpaceException : IOException + { + internal OutOfSpaceException() + : base("CodedOutputStream was writing to a flat byte array and ran out of space.") + { + } + } + + /// + /// Flushes any buffered data and optionally closes the underlying stream, if any. + /// + /// + /// + /// By default, any underlying stream is closed by this method. To configure this behaviour, + /// use a constructor overload with a leaveOpen parameter. If this instance does not + /// have an underlying stream, this method does nothing. + /// + /// + /// For the sake of efficiency, calling this method does not prevent future write calls - but + /// if a later write ends up writing to a stream which has been disposed, that is likely to + /// fail. It is recommend that you not call any other methods after this. + /// + /// + public void Dispose() + { + Flush(); + if (!leaveOpen) + { + output.Dispose(); + } + } + + /// + /// Flushes any buffered data to the underlying stream (if there is one). + /// + public void Flush() + { + var span = new Span(buffer); + WriteBufferHelper.Flush(ref span, ref state); + } + + /// + /// Verifies that SpaceLeft returns zero. It's common to create a byte array + /// that is exactly big enough to hold a message, then write to it with + /// a CodedOutputStream. Calling CheckNoSpaceLeft after writing verifies that + /// the message was actually as big as expected, which can help finding bugs. + /// + public void CheckNoSpaceLeft() + { + WriteBufferHelper.CheckNoSpaceLeft(ref state); + } + + /// + /// If writing to a flat array, returns the space left in the array. Otherwise, + /// throws an InvalidOperationException. + /// + public int SpaceLeft => WriteBufferHelper.GetSpaceLeft(ref state); + + internal byte[] InternalBuffer => buffer; + + internal Stream InternalOutputStream => output; + + internal ref WriterInternalState InternalState => ref state; + } +} diff --git a/Libs/Google.Protobuf/Collections/Lists.cs b/Libs/Google.Protobuf/Collections/Lists.cs new file mode 100644 index 0000000..5790294 --- /dev/null +++ b/Libs/Google.Protobuf/Collections/Lists.cs @@ -0,0 +1,89 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2017 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.Collections.Generic; +using System.Collections.ObjectModel; + +namespace LC.Google.Protobuf.Collections +{ + /// + /// Utility to compare if two Lists are the same, and the hash code + /// of a List. + /// + public static class Lists + { + /// + /// Checks if two lists are equal. + /// + public static bool Equals(List left, List right) + { + if (left == right) + { + return true; + } + if (left == null || right == null) + { + return false; + } + if (left.Count != right.Count) + { + return false; + } + IEqualityComparer comparer = EqualityComparer.Default; + for (int i = 0; i < left.Count; i++) + { + if (!comparer.Equals(left[i], right[i])) + { + return false; + } + } + return true; + } + + /// + /// Gets the list's hash code. + /// + public static int GetHashCode(List list) + { + if (list == null) + { + return 0; + } + int hash = 31; + foreach (T element in list) + { + hash = hash * 29 + element.GetHashCode(); + } + return hash; + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Collections/MapField.cs b/Libs/Google.Protobuf/Collections/MapField.cs new file mode 100644 index 0000000..07ada24 --- /dev/null +++ b/Libs/Google.Protobuf/Collections/MapField.cs @@ -0,0 +1,762 @@ +#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 LC.Google.Protobuf.Compatibility; +using LC.Google.Protobuf.Reflection; +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security; + +namespace LC.Google.Protobuf.Collections +{ + /// + /// Representation of a map field in a Protocol Buffer message. + /// + /// 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. + /// + /// + /// For string keys, the equality comparison is provided by . + /// + /// + /// Null values are not permitted in the map, either for wrapper types or regular messages. + /// If a map is deserialized from a data stream and the value is missing from an entry, a default value + /// is created instead. For primitive types, that is the regular default value (0, the empty string and so + /// on); for message types, an empty instance of the message is created, as if the map entry contained a 0-length + /// encoded value for the field. + /// + /// + /// This implementation does not generally prohibit the use of key/value types which are not + /// supported by Protocol Buffers (e.g. using a key type of byte) but nor does it guarantee + /// that all operations will work in such cases. + /// + /// + /// The order in which entries are returned when iterating over this object is undefined, and may change + /// in future versions. + /// + /// + public sealed class MapField : IDeepCloneable>, IDictionary, IEquatable>, IDictionary +#if !NET35 + , IReadOnlyDictionary +#endif + { + private static readonly EqualityComparer ValueEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); + private static readonly EqualityComparer KeyEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); + + // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.) + private readonly Dictionary>> map = + new Dictionary>>(KeyEqualityComparer); + private readonly LinkedList> list = new LinkedList>(); + + /// + /// Creates a deep clone of this object. + /// + /// + /// A deep clone of this object. + /// + 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, ((IDeepCloneable)pair.Value).Clone()); + } + } + else + { + // Nothing is cloneable, so we don't need to worry. + clone.Add(this); + } + return clone; + } + + /// + /// Adds the specified key/value pair to the map. + /// + /// + /// This operation fails if the key already exists in the map. To replace an existing entry, use the indexer. + /// + /// The key to add + /// The value to add. + /// The given key already exists in map. + public void Add(TKey key, TValue value) + { + // Validation of arguments happens in ContainsKey and the indexer + if (ContainsKey(key)) + { + throw new ArgumentException("Key already exists in map", nameof(key)); + } + this[key] = value; + } + + /// + /// Determines whether the specified key is present in the map. + /// + /// The key to check. + /// true if the map contains the given key; false otherwise. + public bool ContainsKey(TKey key) + { + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); + return map.ContainsKey(key); + } + + private bool ContainsValue(TValue value) => + list.Any(pair => ValueEqualityComparer.Equals(pair.Value, value)); + + /// + /// Removes the entry identified by the given key from the map. + /// + /// The key indicating the entry to remove from the map. + /// true if the map contained the given key before the entry was removed; false otherwise. + public bool Remove(TKey key) + { + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); + LinkedListNode> node; + if (map.TryGetValue(key, out node)) + { + map.Remove(key); + node.List.Remove(node); + return true; + } + else + { + return false; + } + } + + /// + /// Gets the value associated with the specified key. + /// + /// The key whose value to get. + /// When this method returns, the value associated with the specified key, if the key is found; + /// otherwise, the default value for the type of the parameter. + /// This parameter is passed uninitialized. + /// true if the map contains an element with the specified key; otherwise, 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; + } + } + + /// + /// Gets or sets the value associated with the specified key. + /// + /// The key of the value to get or set. + /// The property is retrieved and key does not exist in the collection. + /// The value associated with the specified key. If the specified key is not found, + /// a get operation throws a , and a set operation creates a new element with the specified key. + public TValue this[TKey key] + { + get + { + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); + TValue value; + if (TryGetValue(key, out value)) + { + return value; + } + throw new KeyNotFoundException(); + } + set + { + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); + // value == null check here is redundant, but avoids boxing. + if (value == null) + { + ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value)); + } + 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; + } + } + } + + /// + /// Gets a collection containing the keys in the map. + /// + public ICollection Keys { get { return new MapView(this, pair => pair.Key, ContainsKey); } } + + /// + /// Gets a collection containing the values in the map. + /// + public ICollection Values { get { return new MapView(this, pair => pair.Value, ContainsValue); } } + + /// + /// Adds the specified entries to the map. The keys and values are not automatically cloned. + /// + /// The entries to add to the map. + public void Add(IDictionary entries) + { + ProtoPreconditions.CheckNotNull(entries, nameof(entries)); + foreach (var pair in entries) + { + Add(pair.Key, pair.Value); + } + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// + /// An enumerator that can be used to iterate through the collection. + /// + public IEnumerator> GetEnumerator() + { + return list.GetEnumerator(); + } + + /// + /// Returns an enumerator that iterates through a collection. + /// + /// + /// An object that can be used to iterate through the collection. + /// + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Adds the specified item to the map. + /// + /// The item to add to the map. + void ICollection>.Add(KeyValuePair item) + { + Add(item.Key, item.Value); + } + + /// + /// Removes all items from the map. + /// + public void Clear() + { + list.Clear(); + map.Clear(); + } + + /// + /// Determines whether map contains an entry equivalent to the given key/value pair. + /// + /// The key/value pair to find. + /// + bool ICollection>.Contains(KeyValuePair item) + { + TValue value; + return TryGetValue(item.Key, out value) && ValueEqualityComparer.Equals(item.Value, value); + } + + /// + /// Copies the key/value pairs in this map to an array. + /// + /// The array to copy the entries into. + /// The index of the array at which to start copying values. + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); + } + + /// + /// Removes the specified key/value pair from the map. + /// + /// Both the key and the value must be found for the entry to be removed. + /// The key/value pair to remove. + /// true if the key/value pair was found and removed; false otherwise. + bool ICollection>.Remove(KeyValuePair item) + { + if (item.Key == null) + { + throw new ArgumentException("Key is null", nameof(item)); + } + LinkedListNode> node; + if (map.TryGetValue(item.Key, out node) && + EqualityComparer.Default.Equals(item.Value, node.Value.Value)) + { + map.Remove(item.Key); + node.List.Remove(node); + return true; + } + else + { + return false; + } + } + + /// + /// Gets the number of elements contained in the map. + /// + public int Count { get { return list.Count; } } + + /// + /// Gets a value indicating whether the map is read-only. + /// + public bool IsReadOnly { get { return false; } } + + /// + /// Determines whether the specified , is equal to this instance. + /// + /// The to compare with this instance. + /// + /// true if the specified is equal to this instance; otherwise, false. + /// + public override bool Equals(object other) + { + return Equals(other as MapField); + } + + /// + /// Returns a hash code for this instance. + /// + /// + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// + public override int GetHashCode() + { + var keyComparer = KeyEqualityComparer; + var valueComparer = ValueEqualityComparer; + int hash = 0; + foreach (var pair in list) + { + hash ^= keyComparer.GetHashCode(pair.Key) * 31 + valueComparer.GetHashCode(pair.Value); + } + return hash; + } + + /// + /// Compares this map with another for equality. + /// + /// + /// The order of the key/value pairs in the maps is not deemed significant in this comparison. + /// + /// The map to compare this with. + /// true if refers to an equal map; false otherwise. + public bool Equals(MapField other) + { + if (other == null) + { + return false; + } + if (other == this) + { + return true; + } + if (other.Count != this.Count) + { + return false; + } + var valueComparer = ValueEqualityComparer; + 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; + } + + /// + /// Adds entries to the map from the given stream. + /// + /// + /// It is assumed that the stream is initially positioned after the tag specified by the codec. + /// This method will continue reading entries from the stream until the end is reached, or + /// a different tag is encountered. + /// + /// Stream to read from + /// Codec describing how the key/value pairs are encoded + public void AddEntriesFrom(CodedInputStream input, Codec codec) + { + ParseContext.Initialize(input, out ParseContext ctx); + try + { + AddEntriesFrom(ref ctx, codec); + } + finally + { + ctx.CopyStateTo(input); + } + } + + /// + /// Adds entries to the map from the given parse context. + /// + /// + /// It is assumed that the input is initially positioned after the tag specified by the codec. + /// This method will continue reading entries from the input until the end is reached, or + /// a different tag is encountered. + /// + /// Input to read from + /// Codec describing how the key/value pairs are encoded + [SecuritySafeCritical] + public void AddEntriesFrom(ref ParseContext ctx, Codec codec) + { + do + { + KeyValuePair entry = ParsingPrimitivesMessages.ReadMapEntry(ref ctx, codec); + this[entry.Key] = entry.Value; + } while (ParsingPrimitives.MaybeConsumeTag(ref ctx.buffer, ref ctx.state, codec.MapTag)); + } + + /// + /// Writes the contents of this map to the given coded output stream, using the specified codec + /// to encode each entry. + /// + /// The output stream to write to. + /// The codec to use for each entry. + public void WriteTo(CodedOutputStream output, Codec codec) + { + WriteContext.Initialize(output, out WriteContext ctx); + try + { + WriteTo(ref ctx, codec); + } + finally + { + ctx.CopyStateTo(output); + } + } + + /// + /// Writes the contents of this map to the given write context, using the specified codec + /// to encode each entry. + /// + /// The write context to write to. + /// The codec to use for each entry. + [SecuritySafeCritical] + public void WriteTo(ref WriteContext ctx, Codec codec) + { + foreach (var entry in list) + { + ctx.WriteTag(codec.MapTag); + + WritingPrimitives.WriteLength(ref ctx.buffer, ref ctx.state, CalculateEntrySize(codec, entry)); + codec.KeyCodec.WriteTagAndValue(ref ctx, entry.Key); + codec.ValueCodec.WriteTagAndValue(ref ctx, entry.Value); + } + } + + /// + /// Calculates the size of this map based on the given entry codec. + /// + /// The codec to use to encode each entry. + /// + public int CalculateSize(Codec codec) + { + if (Count == 0) + { + return 0; + } + int size = 0; + foreach (var entry in list) + { + int entrySize = CalculateEntrySize(codec, entry); + + size += CodedOutputStream.ComputeRawVarint32Size(codec.MapTag); + size += CodedOutputStream.ComputeLengthSize(entrySize) + entrySize; + } + return size; + } + + private static int CalculateEntrySize(Codec codec, KeyValuePair entry) + { + return codec.KeyCodec.CalculateSizeWithTag(entry.Key) + codec.ValueCodec.CalculateSizeWithTag(entry.Value); + } + + /// + /// Returns a string representation of this repeated field, in the same + /// way as it would be represented by the default JSON formatter. + /// + public override string ToString() + { + var writer = new StringWriter(); + JsonFormatter.Default.WriteDictionary(writer, this); + return writer.ToString(); + } + + #region IDictionary explicit interface implementation + void IDictionary.Add(object key, object value) + { + Add((TKey)key, (TValue)value); + } + + bool IDictionary.Contains(object key) + { + if (!(key is TKey)) + { + return false; + } + return ContainsKey((TKey)key); + } + + IDictionaryEnumerator IDictionary.GetEnumerator() + { + return new DictionaryEnumerator(GetEnumerator()); + } + + void IDictionary.Remove(object key) + { + ProtoPreconditions.CheckNotNull(key, nameof(key)); + if (!(key is TKey)) + { + return; + } + Remove((TKey)key); + } + + void ICollection.CopyTo(Array array, int index) + { + // This is ugly and slow as heck, but with any luck it will never be used anyway. + ICollection temp = this.Select(pair => new DictionaryEntry(pair.Key, pair.Value)).ToList(); + temp.CopyTo(array, index); + } + + bool IDictionary.IsFixedSize { get { return false; } } + + ICollection IDictionary.Keys { get { return (ICollection)Keys; } } + + ICollection IDictionary.Values { get { return (ICollection)Values; } } + + bool ICollection.IsSynchronized { get { return false; } } + + object ICollection.SyncRoot { get { return this; } } + + object IDictionary.this[object key] + { + get + { + ProtoPreconditions.CheckNotNull(key, nameof(key)); + if (!(key is TKey)) + { + return null; + } + TValue value; + TryGetValue((TKey)key, out value); + return value; + } + + set + { + this[(TKey)key] = (TValue)value; + } + } + #endregion + + #region IReadOnlyDictionary explicit interface implementation +#if !NET35 + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; +#endif + #endregion + + private class DictionaryEnumerator : IDictionaryEnumerator + { + private readonly IEnumerator> enumerator; + + internal DictionaryEnumerator(IEnumerator> enumerator) + { + this.enumerator = enumerator; + } + + public bool MoveNext() + { + return enumerator.MoveNext(); + } + + public void Reset() + { + enumerator.Reset(); + } + + public object Current { get { return Entry; } } + public DictionaryEntry Entry { get { return new DictionaryEntry(Key, Value); } } + public object Key { get { return enumerator.Current.Key; } } + public object Value { get { return enumerator.Current.Value; } } + } + + /// + /// A codec for a specific map field. This contains all the information required to encode and + /// decode the nested messages. + /// + public sealed class Codec + { + private readonly FieldCodec keyCodec; + private readonly FieldCodec valueCodec; + private readonly uint mapTag; + + /// + /// Creates a new entry codec based on a separate key codec and value codec, + /// and the tag to use for each map entry. + /// + /// The key codec. + /// The value codec. + /// The map tag to use to introduce each map entry. + public Codec(FieldCodec keyCodec, FieldCodec valueCodec, uint mapTag) + { + this.keyCodec = keyCodec; + this.valueCodec = valueCodec; + this.mapTag = mapTag; + } + + /// + /// The key codec. + /// + internal FieldCodec KeyCodec => keyCodec; + + /// + /// The value codec. + /// + internal FieldCodec ValueCodec => valueCodec; + + /// + /// The tag used in the enclosing message to indicate map entries. + /// + internal uint MapTag => mapTag; + } + + private class MapView : ICollection, ICollection + { + private readonly MapField parent; + private readonly Func, T> projection; + private readonly Func containsCheck; + + internal MapView( + MapField parent, + Func, T> projection, + Func containsCheck) + { + this.parent = parent; + this.projection = projection; + this.containsCheck = containsCheck; + } + + public int Count { get { return parent.Count; } } + + public bool IsReadOnly { get { return true; } } + + public bool IsSynchronized { get { return false; } } + + public object SyncRoot { get { return parent; } } + + public void Add(T item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(T item) + { + return containsCheck(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (arrayIndex < 0) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + if (arrayIndex + Count > array.Length) + { + throw new ArgumentException("Not enough space in the array", nameof(array)); + } + foreach (var item in this) + { + array[arrayIndex++] = item; + } + } + + public IEnumerator GetEnumerator() + { + return parent.list.Select(projection).GetEnumerator(); + } + + public bool Remove(T item) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void CopyTo(Array array, int index) + { + if (index < 0) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + if (index + Count > array.Length) + { + throw new ArgumentException("Not enough space in the array", nameof(array)); + } + foreach (var item in this) + { + array.SetValue(item, index++); + } + } + } + } +} diff --git a/Libs/Google.Protobuf/Collections/ProtobufEqualityComparers.cs b/Libs/Google.Protobuf/Collections/ProtobufEqualityComparers.cs new file mode 100644 index 0000000..830b0f5 --- /dev/null +++ b/Libs/Google.Protobuf/Collections/ProtobufEqualityComparers.cs @@ -0,0 +1,130 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2017 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.Generic; + +namespace LC.Google.Protobuf.Collections +{ + /// + /// Provides a central place to implement equality comparisons, primarily for bitwise float/double equality. + /// + public static class ProtobufEqualityComparers + { + /// + /// Returns an equality comparer for suitable for Protobuf equality comparisons. + /// This is usually just the default equality comparer for the type, but floating point numbers are compared + /// bitwise. + /// + /// The type of equality comparer to return. + /// The equality comparer. + public static EqualityComparer GetEqualityComparer() + { + return typeof(T) == typeof(double) ? (EqualityComparer) (object) BitwiseDoubleEqualityComparer + : typeof(T) == typeof(float) ? (EqualityComparer) (object) BitwiseSingleEqualityComparer + : typeof(T) == typeof(double?) ? (EqualityComparer) (object) BitwiseNullableDoubleEqualityComparer + : typeof(T) == typeof(float?) ? (EqualityComparer) (object) BitwiseNullableSingleEqualityComparer + : EqualityComparer.Default; + } + + /// + /// Returns an equality comparer suitable for comparing 64-bit floating point values, by bitwise comparison. + /// (NaN values are considered equal, but only when they have the same representation.) + /// + public static EqualityComparer BitwiseDoubleEqualityComparer { get; } = new BitwiseDoubleEqualityComparerImpl(); + + /// + /// Returns an equality comparer suitable for comparing 32-bit floating point values, by bitwise comparison. + /// (NaN values are considered equal, but only when they have the same representation.) + /// + public static EqualityComparer BitwiseSingleEqualityComparer { get; } = new BitwiseSingleEqualityComparerImpl(); + + /// + /// Returns an equality comparer suitable for comparing nullable 64-bit floating point values, by bitwise comparison. + /// (NaN values are considered equal, but only when they have the same representation.) + /// + public static EqualityComparer BitwiseNullableDoubleEqualityComparer { get; } = new BitwiseNullableDoubleEqualityComparerImpl(); + + /// + /// Returns an equality comparer suitable for comparing nullable 32-bit floating point values, by bitwise comparison. + /// (NaN values are considered equal, but only when they have the same representation.) + /// + public static EqualityComparer BitwiseNullableSingleEqualityComparer { get; } = new BitwiseNullableSingleEqualityComparerImpl(); + + private class BitwiseDoubleEqualityComparerImpl : EqualityComparer + { + public override bool Equals(double x, double y) => + BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y); + + public override int GetHashCode(double obj) => + BitConverter.DoubleToInt64Bits(obj).GetHashCode(); + } + + private class BitwiseSingleEqualityComparerImpl : EqualityComparer + { + // Just promote values to double and use BitConverter.DoubleToInt64Bits, + // as there's no BitConverter.SingleToInt32Bits, unfortunately. + + public override bool Equals(float x, float y) => + BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y); + + public override int GetHashCode(float obj) => + BitConverter.DoubleToInt64Bits(obj).GetHashCode(); + } + + private class BitwiseNullableDoubleEqualityComparerImpl : EqualityComparer + { + public override bool Equals(double? x, double? y) => + x == null && y == null ? true + : x == null || y == null ? false + : BitwiseDoubleEqualityComparer.Equals(x.Value, y.Value); + + // The hash code for null is just a constant which is at least *unlikely* to be used + // elsewhere. (Compared with 0, say.) + public override int GetHashCode(double? obj) => + obj == null ? 293864 : BitwiseDoubleEqualityComparer.GetHashCode(obj.Value); + } + + private class BitwiseNullableSingleEqualityComparerImpl : EqualityComparer + { + public override bool Equals(float? x, float? y) => + x == null && y == null ? true + : x == null || y == null ? false + : BitwiseSingleEqualityComparer.Equals(x.Value, y.Value); + + // The hash code for null is just a constant which is at least *unlikely* to be used + // elsewhere. (Compared with 0, say.) + public override int GetHashCode(float? obj) => + obj == null ? 293864 : BitwiseSingleEqualityComparer.GetHashCode(obj.Value); + } + } +} diff --git a/Libs/Google.Protobuf/Collections/ReadOnlyDictionary.cs b/Libs/Google.Protobuf/Collections/ReadOnlyDictionary.cs new file mode 100644 index 0000000..e589b89 --- /dev/null +++ b/Libs/Google.Protobuf/Collections/ReadOnlyDictionary.cs @@ -0,0 +1,147 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace LC.Google.Protobuf.Collections +{ + /// + /// Read-only wrapper around another dictionary. + /// + internal sealed class ReadOnlyDictionary : IDictionary + { + private readonly IDictionary wrapped; + + public ReadOnlyDictionary(IDictionary wrapped) + { + this.wrapped = wrapped; + } + + public void Add(TKey key, TValue value) + { + throw new InvalidOperationException(); + } + + public bool ContainsKey(TKey key) + { + return wrapped.ContainsKey(key); + } + + public ICollection Keys + { + get { return wrapped.Keys; } + } + + public bool Remove(TKey key) + { + throw new InvalidOperationException(); + } + + public bool TryGetValue(TKey key, out TValue value) + { + return wrapped.TryGetValue(key, out value); + } + + public ICollection Values + { + get { return wrapped.Values; } + } + + public TValue this[TKey key] + { + get { return wrapped[key]; } + set { throw new InvalidOperationException(); } + } + + public void Add(KeyValuePair item) + { + throw new InvalidOperationException(); + } + + public void Clear() + { + throw new InvalidOperationException(); + } + + public bool Contains(KeyValuePair item) + { + return wrapped.Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + wrapped.CopyTo(array, arrayIndex); + } + + public int Count + { + get { return wrapped.Count; } + } + + public bool IsReadOnly + { + get { return true; } + } + + public bool Remove(KeyValuePair item) + { + throw new InvalidOperationException(); + } + + public IEnumerator> GetEnumerator() + { + return wrapped.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable) wrapped).GetEnumerator(); + } + + public override bool Equals(object obj) + { + return wrapped.Equals(obj); + } + + public override int GetHashCode() + { + return wrapped.GetHashCode(); + } + + public override string ToString() + { + return wrapped.ToString(); + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Collections/RepeatedField.cs b/Libs/Google.Protobuf/Collections/RepeatedField.cs new file mode 100644 index 0000000..30e2e57 --- /dev/null +++ b/Libs/Google.Protobuf/Collections/RepeatedField.cs @@ -0,0 +1,698 @@ +#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.IO; +using System.Security; +using System.Threading; + +namespace LC.Google.Protobuf.Collections +{ + /// + /// The contents of a repeated field: essentially, a collection with some extra + /// restrictions (no null values) and capabilities (deep cloning). + /// + /// + /// This implementation does not generally prohibit the use of types which are not + /// supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases. + /// + /// The element type of the repeated field. + public sealed class RepeatedField : IList, IList, IDeepCloneable>, IEquatable> +#if !NET35 + , IReadOnlyList +#endif + { + private static readonly EqualityComparer EqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); + private static readonly T[] EmptyArray = new T[0]; + private const int MinArraySize = 8; + + private T[] array = EmptyArray; + private int count = 0; + + /// + /// Creates a deep clone of this repeated field. + /// + /// + /// If the field type is + /// a message type, each element is also cloned; otherwise, it is + /// assumed that the field type is primitive (including string and + /// bytes, both of which are immutable) and so a simple copy is + /// equivalent to a deep clone. + /// + /// A deep clone of this repeated field. + public RepeatedField Clone() + { + RepeatedField clone = new RepeatedField(); + if (array != EmptyArray) + { + clone.array = (T[])array.Clone(); + IDeepCloneable[] cloneableArray = clone.array as IDeepCloneable[]; + if (cloneableArray != null) + { + for (int i = 0; i < count; i++) + { + clone.array[i] = cloneableArray[i].Clone(); + } + } + } + clone.count = count; + return clone; + } + + /// + /// Adds the entries from the given input stream, decoding them with the specified codec. + /// + /// The input stream to read from. + /// The codec to use in order to read each entry. + public void AddEntriesFrom(CodedInputStream input, FieldCodec codec) + { + ParseContext.Initialize(input, out ParseContext ctx); + try + { + AddEntriesFrom(ref ctx, codec); + } + finally + { + ctx.CopyStateTo(input); + } + } + + /// + /// Adds the entries from the given parse context, decoding them with the specified codec. + /// + /// The input to read from. + /// The codec to use in order to read each entry. + [SecuritySafeCritical] + public void AddEntriesFrom(ref ParseContext ctx, FieldCodec codec) + { + // TODO: Inline some of the Add code, so we can avoid checking the size on every + // iteration. + uint tag = ctx.state.lastTag; + var reader = codec.ValueReader; + // Non-nullable value types can be packed or not. + if (FieldCodec.IsPackedRepeatedField(tag)) + { + int length = ctx.ReadLength(); + if (length > 0) + { + int oldLimit = SegmentedBufferHelper.PushLimit(ref ctx.state, length); + + // If the content is fixed size then we can calculate the length + // of the repeated field and pre-initialize the underlying collection. + // + // Check that the supplied length doesn't exceed the underlying buffer. + // That prevents a malicious length from initializing a very large collection. + if (codec.FixedSize > 0 && length % codec.FixedSize == 0 && ParsingPrimitives.IsDataAvailable(ref ctx.state, length)) + { + EnsureSize(count + (length / codec.FixedSize)); + + while (!SegmentedBufferHelper.IsReachedLimit(ref ctx.state)) + { + // Only FieldCodecs with a fixed size can reach here, and they are all known + // types that don't allow the user to specify a custom reader action. + // reader action will never return null. + array[count++] = reader(ref ctx); + } + } + else + { + // Content is variable size so add until we reach the limit. + while (!SegmentedBufferHelper.IsReachedLimit(ref ctx.state)) + { + Add(reader(ref ctx)); + } + } + SegmentedBufferHelper.PopLimit(ref ctx.state, oldLimit); + } + // Empty packed field. Odd, but valid - just ignore. + } + else + { + // Not packed... (possibly not packable) + do + { + Add(reader(ref ctx)); + } while (ParsingPrimitives.MaybeConsumeTag(ref ctx.buffer, ref ctx.state, tag)); + } + } + + /// + /// Calculates the size of this collection based on the given codec. + /// + /// The codec to use when encoding each field. + /// The number of bytes that would be written to an output by one of the WriteTo methods, + /// using the same codec. + public int CalculateSize(FieldCodec codec) + { + if (count == 0) + { + return 0; + } + uint tag = codec.Tag; + if (codec.PackedRepeatedField) + { + int dataSize = CalculatePackedDataSize(codec); + return CodedOutputStream.ComputeRawVarint32Size(tag) + + CodedOutputStream.ComputeLengthSize(dataSize) + + dataSize; + } + else + { + var sizeCalculator = codec.ValueSizeCalculator; + int size = count * CodedOutputStream.ComputeRawVarint32Size(tag); + if (codec.EndTag != 0) + { + size += count * CodedOutputStream.ComputeRawVarint32Size(codec.EndTag); + } + for (int i = 0; i < count; i++) + { + size += sizeCalculator(array[i]); + } + return size; + } + } + + private int CalculatePackedDataSize(FieldCodec codec) + { + int fixedSize = codec.FixedSize; + if (fixedSize == 0) + { + var calculator = codec.ValueSizeCalculator; + int tmp = 0; + for (int i = 0; i < count; i++) + { + tmp += calculator(array[i]); + } + return tmp; + } + else + { + return fixedSize * Count; + } + } + + /// + /// Writes the contents of this collection to the given , + /// encoding each value using the specified codec. + /// + /// The output stream to write to. + /// The codec to use when encoding each value. + public void WriteTo(CodedOutputStream output, FieldCodec codec) + { + WriteContext.Initialize(output, out WriteContext ctx); + try + { + WriteTo(ref ctx, codec); + } + finally + { + ctx.CopyStateTo(output); + } + } + + /// + /// Writes the contents of this collection to the given write context, + /// encoding each value using the specified codec. + /// + /// The write context to write to. + /// The codec to use when encoding each value. + [SecuritySafeCritical] + public void WriteTo(ref WriteContext ctx, FieldCodec codec) + { + if (count == 0) + { + return; + } + var writer = codec.ValueWriter; + var tag = codec.Tag; + if (codec.PackedRepeatedField) + { + // Packed primitive type + int size = CalculatePackedDataSize(codec); + ctx.WriteTag(tag); + ctx.WriteLength(size); + for (int i = 0; i < count; i++) + { + writer(ref ctx, array[i]); + } + } + else + { + // Not packed: a simple tag/value pair for each value. + // Can't use codec.WriteTagAndValue, as that omits default values. + for (int i = 0; i < count; i++) + { + ctx.WriteTag(tag); + writer(ref ctx, array[i]); + if (codec.EndTag != 0) + { + ctx.WriteTag(codec.EndTag); + } + } + } + } + + /// + /// Gets and sets the capacity of the RepeatedField's internal array. WHen set, the internal array is reallocated to the given capacity. + /// The new value is less than Count -or- when Count is less than 0. + /// + public int Capacity + { + get { return array.Length; } + set + { + if (value < count) + { + throw new ArgumentOutOfRangeException("Capacity", value, + $"Cannot set Capacity to a value smaller than the current item count, {count}"); + } + + if (value >= 0 && value != array.Length) + { + SetSize(value); + } + } + } + + // May increase the size of the internal array, but will never shrink it. + private void EnsureSize(int size) + { + if (array.Length < size) + { + size = Math.Max(size, MinArraySize); + int newSize = Math.Max(array.Length * 2, size); + SetSize(newSize); + } + } + + // Sets the internal array to an exact size. + private void SetSize(int size) + { + if (size != array.Length) + { + var tmp = new T[size]; + Array.Copy(array, 0, tmp, 0, count); + array = tmp; + } + } + + /// + /// Adds the specified item to the collection. + /// + /// The item to add. + public void Add(T item) + { + ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item)); + EnsureSize(count + 1); + array[count++] = item; + } + + /// + /// Removes all items from the collection. + /// + public void Clear() + { + array = EmptyArray; + count = 0; + } + + /// + /// Determines whether this collection contains the given item. + /// + /// The item to find. + /// true if this collection contains the given item; false otherwise. + public bool Contains(T item) + { + return IndexOf(item) != -1; + } + + /// + /// Copies this collection to the given array. + /// + /// The array to copy to. + /// The first index of the array to copy to. + public void CopyTo(T[] array, int arrayIndex) + { + Array.Copy(this.array, 0, array, arrayIndex, count); + } + + /// + /// Removes the specified item from the collection + /// + /// The item to remove. + /// true if the item was found and removed; false otherwise. + public bool Remove(T item) + { + int index = IndexOf(item); + if (index == -1) + { + return false; + } + Array.Copy(array, index + 1, array, index, count - index - 1); + count--; + array[count] = default(T); + return true; + } + + /// + /// Gets the number of elements contained in the collection. + /// + public int Count => count; + + /// + /// Gets a value indicating whether the collection is read-only. + /// + public bool IsReadOnly => false; + + /// + /// Adds all of the specified values into this collection. + /// + /// The values to add to this collection. + public void AddRange(IEnumerable values) + { + ProtoPreconditions.CheckNotNull(values, nameof(values)); + + // Optimization 1: If the collection we're adding is already a RepeatedField, + // we know the values are valid. + var otherRepeatedField = values as RepeatedField; + if (otherRepeatedField != null) + { + EnsureSize(count + otherRepeatedField.count); + Array.Copy(otherRepeatedField.array, 0, array, count, otherRepeatedField.count); + count += otherRepeatedField.count; + return; + } + + // Optimization 2: The collection is an ICollection, so we can expand + // just once and ask the collection to copy itself into the array. + var collection = values as ICollection; + if (collection != null) + { + var extraCount = collection.Count; + // For reference types and nullable value types, we need to check that there are no nulls + // present. (This isn't a thread-safe approach, but we don't advertise this is thread-safe.) + // We expect the JITter to optimize this test to true/false, so it's effectively conditional + // specialization. + if (default(T) == null) + { + // TODO: Measure whether iterating once to check and then letting the collection copy + // itself is faster or slower than iterating and adding as we go. For large + // collections this will not be great in terms of cache usage... but the optimized + // copy may be significantly faster than doing it one at a time. + foreach (var item in collection) + { + if (item == null) + { + throw new ArgumentException("Sequence contained null element", nameof(values)); + } + } + } + EnsureSize(count + extraCount); + collection.CopyTo(array, count); + count += extraCount; + return; + } + + // We *could* check for ICollection as well, but very very few collections implement + // ICollection but not ICollection. (HashSet does, for one...) + + // Fall back to a slower path of adding items one at a time. + foreach (T item in values) + { + Add(item); + } + } + + /// + /// Adds all of the specified values into this collection. This method is present to + /// allow repeated fields to be constructed from queries within collection initializers. + /// Within non-collection-initializer code, consider using the equivalent + /// method instead for clarity. + /// + /// The values to add to this collection. + public void Add(IEnumerable values) + { + AddRange(values); + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// + /// An enumerator that can be used to iterate through the collection. + /// + public IEnumerator GetEnumerator() + { + for (int i = 0; i < count; i++) + { + yield return array[i]; + } + } + + /// + /// Determines whether the specified , is equal to this instance. + /// + /// The to compare with this instance. + /// + /// true if the specified is equal to this instance; otherwise, false. + /// + public override bool Equals(object obj) + { + return Equals(obj as RepeatedField); + } + + /// + /// Returns an enumerator that iterates through a collection. + /// + /// + /// An object that can be used to iterate through the collection. + /// + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Returns a hash code for this instance. + /// + /// + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// + public override int GetHashCode() + { + int hash = 0; + for (int i = 0; i < count; i++) + { + hash = hash * 31 + array[i].GetHashCode(); + } + return hash; + } + + /// + /// Compares this repeated field with another for equality. + /// + /// The repeated field to compare this with. + /// true if refers to an equal repeated field; false otherwise. + public bool Equals(RepeatedField other) + { + if (ReferenceEquals(other, null)) + { + return false; + } + if (ReferenceEquals(other, this)) + { + return true; + } + if (other.Count != this.Count) + { + return false; + } + EqualityComparer comparer = EqualityComparer; + for (int i = 0; i < count; i++) + { + if (!comparer.Equals(array[i], other.array[i])) + { + return false; + } + } + return true; + } + + /// + /// Returns the index of the given item within the collection, or -1 if the item is not + /// present. + /// + /// The item to find in the collection. + /// The zero-based index of the item, or -1 if it is not found. + public int IndexOf(T item) + { + ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item)); + EqualityComparer comparer = EqualityComparer; + for (int i = 0; i < count; i++) + { + if (comparer.Equals(array[i], item)) + { + return i; + } + } + return -1; + } + + /// + /// Inserts the given item at the specified index. + /// + /// The index at which to insert the item. + /// The item to insert. + public void Insert(int index, T item) + { + ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item)); + if (index < 0 || index > count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureSize(count + 1); + Array.Copy(array, index, array, index + 1, count - index); + array[index] = item; + count++; + } + + /// + /// Removes the item at the given index. + /// + /// The zero-based index of the item to remove. + public void RemoveAt(int index) + { + if (index < 0 || index >= count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + Array.Copy(array, index + 1, array, index, count - index - 1); + count--; + array[count] = default(T); + } + + /// + /// Returns a string representation of this repeated field, in the same + /// way as it would be represented by the default JSON formatter. + /// + public override string ToString() + { + var writer = new StringWriter(); + JsonFormatter.Default.WriteList(writer, this); + return writer.ToString(); + } + + /// + /// Gets or sets the item at the specified index. + /// + /// + /// The element at the specified index. + /// + /// The zero-based index of the element to get or set. + /// The item at the specified index. + public T this[int index] + { + get + { + if (index < 0 || index >= count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return array[index]; + } + set + { + if (index < 0 || index >= count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value)); + array[index] = value; + } + } + + #region Explicit interface implementation for IList and ICollection. + bool IList.IsFixedSize => false; + + void ICollection.CopyTo(Array array, int index) + { + Array.Copy(this.array, 0, array, index, count); + } + + bool ICollection.IsSynchronized => false; + + object ICollection.SyncRoot => this; + + object IList.this[int index] + { + get { return this[index]; } + set { this[index] = (T)value; } + } + + int IList.Add(object value) + { + Add((T) value); + return count - 1; + } + + bool IList.Contains(object value) + { + return (value is T && Contains((T)value)); + } + + int IList.IndexOf(object value) + { + if (!(value is T)) + { + return -1; + } + return IndexOf((T)value); + } + + void IList.Insert(int index, object value) + { + Insert(index, (T) value); + } + + void IList.Remove(object value) + { + if (!(value is T)) + { + return; + } + Remove((T)value); + } + #endregion + } +} diff --git a/Libs/Google.Protobuf/Compatibility/MethodInfoExtensions.cs b/Libs/Google.Protobuf/Compatibility/MethodInfoExtensions.cs new file mode 100644 index 0000000..0fe73ee --- /dev/null +++ b/Libs/Google.Protobuf/Compatibility/MethodInfoExtensions.cs @@ -0,0 +1,47 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2017 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 + +#if NET35 +using System; +using System.Reflection; + +namespace LC.Google.Protobuf.Compatibility +{ + // .NET Core (at least netstandard1.0) doesn't have Delegate.CreateDelegate, and .NET 3.5 doesn't have + // MethodInfo.CreateDelegate. Proxy from one to the other on .NET 3.5... + internal static class MethodInfoExtensions + { + internal static Delegate CreateDelegate(this MethodInfo method, Type type) => + Delegate.CreateDelegate(type, method); + } +} +#endif diff --git a/Libs/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs b/Libs/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs new file mode 100644 index 0000000..aa4c4dd --- /dev/null +++ b/Libs/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs @@ -0,0 +1,72 @@ +#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.Reflection; + +namespace LC.Google.Protobuf.Compatibility +{ + /// + /// Extension methods for , effectively providing + /// the familiar members from previous desktop framework versions while + /// targeting the newer releases, .NET Core etc. + /// + internal static class PropertyInfoExtensions + { + /// + /// Returns the public getter of a property, or null if there is no such getter + /// (either because it's read-only, or the getter isn't public). + /// + internal static MethodInfo GetGetMethod(this PropertyInfo target) + { +#if NET35 + var method = target.GetGetMethod(); +#else + var method = target.GetMethod; +#endif + return method != null && method.IsPublic ? method : null; + } + + /// + /// Returns the public setter of a property, or null if there is no such setter + /// (either because it's write-only, or the setter isn't public). + /// + internal static MethodInfo GetSetMethod(this PropertyInfo target) + { +#if NET35 + var method = target.GetSetMethod(); +#else + var method = target.SetMethod; +#endif + return method != null && method.IsPublic ? method : null; + } + } +} diff --git a/Libs/Google.Protobuf/Compatibility/StreamExtensions.cs b/Libs/Google.Protobuf/Compatibility/StreamExtensions.cs new file mode 100644 index 0000000..f475c94 --- /dev/null +++ b/Libs/Google.Protobuf/Compatibility/StreamExtensions.cs @@ -0,0 +1,66 @@ +#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 + +#if NET35 +using System; +using System.IO; + +namespace LC.Google.Protobuf.Compatibility +{ + /// + /// Extension methods for in order to provide + /// backwards compatibility with .NET 3.5 + /// + public static class StreamExtensions + { + // 81920 seems to be the default buffer size used in .NET 4.5.1 + private const int BUFFER_SIZE = 81920; + + /// + /// Write the contents of the current stream to the destination stream + /// + public static void CopyTo(this Stream source, Stream destination) + { + if (destination == null) + { + throw new ArgumentNullException(nameof(destination)); + } + + byte[] buffer = new byte[BUFFER_SIZE]; + int numBytesRead; + while ((numBytesRead = source.Read(buffer, 0, buffer.Length)) > 0) { + destination.Write(buffer, 0, numBytesRead); + } + } + } +} +#endif diff --git a/Libs/Google.Protobuf/Compatibility/TypeExtensions.cs b/Libs/Google.Protobuf/Compatibility/TypeExtensions.cs new file mode 100644 index 0000000..be67850 --- /dev/null +++ b/Libs/Google.Protobuf/Compatibility/TypeExtensions.cs @@ -0,0 +1,106 @@ +#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.Reflection; + +#if !NET35 +namespace LC.Google.Protobuf.Compatibility +{ + /// + /// Provides extension methods on Type that just proxy to TypeInfo. + /// These are used to support the new type system from .NET 4.5, without + /// having calls to GetTypeInfo all over the place. While the methods here are meant to be + /// broadly compatible with the desktop framework, there are some subtle differences in behaviour - but + /// they're not expected to affect our use cases. While the class is internal, that should be fine: we can + /// evaluate each new use appropriately. + /// + internal static class TypeExtensions + { + /// + /// See https://msdn.microsoft.com/en-us/library/system.type.isassignablefrom + /// + internal static bool IsAssignableFrom(this Type target, Type c) + { + return target.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo()); + } + + /// + /// Returns a representation of the public property associated with the given name in the given type, + /// including inherited properties or null if there is no such public property. + /// Here, "public property" means a property where either the getter, or the setter, or both, is public. + /// + internal static PropertyInfo GetProperty(this Type target, string name) + { + // GetDeclaredProperty only returns properties declared in the given type, so we need to recurse. + while (target != null) + { + var typeInfo = target.GetTypeInfo(); + var ret = typeInfo.GetDeclaredProperty(name); + if (ret != null && ((ret.CanRead && ret.GetMethod.IsPublic) || (ret.CanWrite && ret.SetMethod.IsPublic))) + { + return ret; + } + target = typeInfo.BaseType; + } + return null; + } + + /// + /// Returns a representation of the public method associated with the given name in the given type, + /// including inherited methods. + /// + /// + /// This has a few differences compared with Type.GetMethod in the desktop framework. It will throw + /// if there is an ambiguous match even between a private method and a public one, but it *won't* throw + /// if there are two overloads at different levels in the type hierarchy (e.g. class Base declares public void Foo(int) and + /// class Child : Base declares public void Foo(long)). + /// + /// One type in the hierarchy declared more than one method with the same name + internal static MethodInfo GetMethod(this Type target, string name) + { + // GetDeclaredMethod only returns methods declared in the given type, so we need to recurse. + while (target != null) + { + var typeInfo = target.GetTypeInfo(); + var ret = typeInfo.GetDeclaredMethod(name); + if (ret != null && ret.IsPublic) + { + return ret; + } + target = typeInfo.BaseType; + } + return null; + } + } +} +#endif diff --git a/Libs/Google.Protobuf/Extension.cs b/Libs/Google.Protobuf/Extension.cs new file mode 100644 index 0000000..8feee04 --- /dev/null +++ b/Libs/Google.Protobuf/Extension.cs @@ -0,0 +1,119 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf +{ + /// + /// Represents a non-generic extension definition. This API is experimental and subject to change. + /// + public abstract class Extension + { + internal abstract Type TargetType { get; } + + /// + /// Internal use. Creates a new extension with the specified field number. + /// + protected Extension(int fieldNumber) + { + FieldNumber = fieldNumber; + } + + internal abstract IExtensionValue CreateValue(); + + /// + /// Gets the field number of this extension + /// + public int FieldNumber { get; } + + internal abstract bool IsRepeated { get; } + } + + /// + /// Represents a type-safe extension identifier used for getting and setting single extension values in instances. + /// This API is experimental and subject to change. + /// + /// The message type this field applies to + /// The field value type of this extension + public sealed class Extension : Extension where TTarget : IExtendableMessage + { + private readonly FieldCodec codec; + + /// + /// Creates a new extension identifier with the specified field number and codec + /// + public Extension(int fieldNumber, FieldCodec codec) : base(fieldNumber) + { + this.codec = codec; + } + + internal TValue DefaultValue => codec.DefaultValue; + + internal override Type TargetType => typeof(TTarget); + + internal override bool IsRepeated => false; + + internal override IExtensionValue CreateValue() + { + return new ExtensionValue(codec); + } + } + + /// + /// Represents a type-safe extension identifier used for getting repeated extension values in instances. + /// This API is experimental and subject to change. + /// + /// The message type this field applies to + /// The repeated field value type of this extension + public sealed class RepeatedExtension : Extension where TTarget : IExtendableMessage + { + private readonly FieldCodec codec; + + /// + /// Creates a new repeated extension identifier with the specified field number and codec + /// + public RepeatedExtension(int fieldNumber, FieldCodec codec) : base(fieldNumber) + { + this.codec = codec; + } + + internal override Type TargetType => typeof(TTarget); + + internal override bool IsRepeated => true; + + internal override IExtensionValue CreateValue() + { + return new RepeatedExtensionValue(codec); + } + } +} diff --git a/Libs/Google.Protobuf/ExtensionRegistry.cs b/Libs/Google.Protobuf/ExtensionRegistry.cs new file mode 100644 index 0000000..44667db --- /dev/null +++ b/Libs/Google.Protobuf/ExtensionRegistry.cs @@ -0,0 +1,184 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace LC.Google.Protobuf +{ + /// + /// Provides extensions to messages while parsing. This API is experimental and subject to change. + /// + public sealed class ExtensionRegistry : ICollection, IDeepCloneable + { + internal sealed class ExtensionComparer : IEqualityComparer + { + public bool Equals(Extension a, Extension b) + { + return new ObjectIntPair(a.TargetType, a.FieldNumber).Equals(new ObjectIntPair(b.TargetType, b.FieldNumber)); + } + public int GetHashCode(Extension a) + { + return new ObjectIntPair(a.TargetType, a.FieldNumber).GetHashCode(); + } + + internal static ExtensionComparer Instance = new ExtensionComparer(); + } + private IDictionary, Extension> extensions; + + /// + /// Creates a new empty extension registry + /// + public ExtensionRegistry() + { + extensions = new Dictionary, Extension>(); + } + + private ExtensionRegistry(IDictionary, Extension> collection) + { + extensions = collection.ToDictionary(k => k.Key, v => v.Value); + } + + /// + /// Gets the total number of extensions in this extension registry + /// + public int Count => extensions.Count; + + /// + /// Returns whether the registry is readonly + /// + bool ICollection.IsReadOnly => false; + + internal bool ContainsInputField(uint lastTag, Type target, out Extension extension) + { + return extensions.TryGetValue(new ObjectIntPair(target, WireFormat.GetTagFieldNumber(lastTag)), out extension); + } + + /// + /// Adds the specified extension to the registry + /// + public void Add(Extension extension) + { + ProtoPreconditions.CheckNotNull(extension, nameof(extension)); + + extensions.Add(new ObjectIntPair(extension.TargetType, extension.FieldNumber), extension); + } + + /// + /// Adds the specified extensions to the registry + /// + public void AddRange(IEnumerable extensions) + { + ProtoPreconditions.CheckNotNull(extensions, nameof(extensions)); + + foreach (var extension in extensions) + { + Add(extension); + } + } + + /// + /// Clears the registry of all values + /// + public void Clear() + { + extensions.Clear(); + } + + /// + /// Gets whether the extension registry contains the specified extension + /// + public bool Contains(Extension item) + { + ProtoPreconditions.CheckNotNull(item, nameof(item)); + + return extensions.ContainsKey(new ObjectIntPair(item.TargetType, item.FieldNumber)); + } + + /// + /// Copies the arrays in the registry set to the specified array at the specified index + /// + /// The array to copy to + /// The array index to start at + void ICollection.CopyTo(Extension[] array, int arrayIndex) + { + ProtoPreconditions.CheckNotNull(array, nameof(array)); + if (arrayIndex < 0 || arrayIndex >= array.Length) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + if (array.Length - arrayIndex < Count) + { + throw new ArgumentException("The provided array is shorter than the number of elements in the registry"); + } + + for (int i = 0; i < array.Length; i++) + { + Extension extension = array[i]; + extensions.Add(new ObjectIntPair(extension.TargetType, extension.FieldNumber), extension); + } + } + + /// + /// Returns an enumerator to enumerate through the items in the registry + /// + /// Returns an enumerator for the extensions in this registry + public IEnumerator GetEnumerator() + { + return extensions.Values.GetEnumerator(); + } + + /// + /// Removes the specified extension from the set + /// + /// The extension + /// true if the extension was removed, otherwise false + public bool Remove(Extension item) + { + ProtoPreconditions.CheckNotNull(item, nameof(item)); + + return extensions.Remove(new ObjectIntPair(item.TargetType, item.FieldNumber)); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// + /// Clones the registry into a new registry + /// + public ExtensionRegistry Clone() + { + return new ExtensionRegistry(extensions); + } + } +} diff --git a/Libs/Google.Protobuf/ExtensionSet.cs b/Libs/Google.Protobuf/ExtensionSet.cs new file mode 100644 index 0000000..1f1917b --- /dev/null +++ b/Libs/Google.Protobuf/ExtensionSet.cs @@ -0,0 +1,377 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// Methods for managing s with null checking. + /// + /// Most users will not use this class directly and its API is experimental and subject to change. + /// + public static class ExtensionSet + { + private static bool TryGetValue(ref ExtensionSet set, Extension extension, out IExtensionValue value) where TTarget : IExtendableMessage + { + if (set == null) + { + value = null; + return false; + } + return set.ValuesByNumber.TryGetValue(extension.FieldNumber, out value); + } + + /// + /// Gets the value of the specified extension + /// + public static TValue Get(ref ExtensionSet set, Extension extension) where TTarget : IExtendableMessage + { + IExtensionValue value; + if (TryGetValue(ref set, extension, out value)) + { + return ((ExtensionValue)value).GetValue(); + } + else + { + return extension.DefaultValue; + } + } + + /// + /// Gets the value of the specified repeated extension or null if it doesn't exist in this set + /// + public static RepeatedField Get(ref ExtensionSet set, RepeatedExtension extension) where TTarget : IExtendableMessage + { + IExtensionValue value; + if (TryGetValue(ref set, extension, out value)) + { + return ((RepeatedExtensionValue)value).GetValue(); + } + else + { + return null; + } + } + + /// + /// Gets the value of the specified repeated extension, registering it if it doesn't exist + /// + public static RepeatedField GetOrInitialize(ref ExtensionSet set, RepeatedExtension extension) where TTarget : IExtendableMessage + { + IExtensionValue value; + if (set == null) + { + value = extension.CreateValue(); + set = new ExtensionSet(); + set.ValuesByNumber.Add(extension.FieldNumber, value); + } + else + { + if (!set.ValuesByNumber.TryGetValue(extension.FieldNumber, out value)) + { + value = extension.CreateValue(); + set.ValuesByNumber.Add(extension.FieldNumber, value); + } + } + + return ((RepeatedExtensionValue)value).GetValue(); + } + + /// + /// Sets the value of the specified extension. This will make a new instance of ExtensionSet if the set is null. + /// + public static void Set(ref ExtensionSet set, Extension extension, TValue value) where TTarget : IExtendableMessage + { + ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value)); + + IExtensionValue extensionValue; + if (set == null) + { + extensionValue = extension.CreateValue(); + set = new ExtensionSet(); + set.ValuesByNumber.Add(extension.FieldNumber, extensionValue); + } + else + { + if (!set.ValuesByNumber.TryGetValue(extension.FieldNumber, out extensionValue)) + { + extensionValue = extension.CreateValue(); + set.ValuesByNumber.Add(extension.FieldNumber, extensionValue); + } + } + + ((ExtensionValue)extensionValue).SetValue(value); + } + + /// + /// Gets whether the value of the specified extension is set + /// + public static bool Has(ref ExtensionSet set, Extension extension) where TTarget : IExtendableMessage + { + IExtensionValue value; + return TryGetValue(ref set, extension, out value); + } + + /// + /// Clears the value of the specified extension + /// + public static void Clear(ref ExtensionSet set, Extension extension) where TTarget : IExtendableMessage + { + if (set == null) + { + return; + } + set.ValuesByNumber.Remove(extension.FieldNumber); + if (set.ValuesByNumber.Count == 0) + { + set = null; + } + } + + /// + /// Clears the value of the specified extension + /// + public static void Clear(ref ExtensionSet set, RepeatedExtension extension) where TTarget : IExtendableMessage + { + if (set == null) + { + return; + } + set.ValuesByNumber.Remove(extension.FieldNumber); + if (set.ValuesByNumber.Count == 0) + { + set = null; + } + } + + /// + /// Tries to merge a field from the coded input, returning true if the field was merged. + /// If the set is null or the field was not otherwise merged, this returns false. + /// + public static bool TryMergeFieldFrom(ref ExtensionSet set, CodedInputStream stream) where TTarget : IExtendableMessage + { + ParseContext.Initialize(stream, out ParseContext ctx); + try + { + return TryMergeFieldFrom(ref set, ref ctx); + } + finally + { + ctx.CopyStateTo(stream); + } + } + + /// + /// Tries to merge a field from the coded input, returning true if the field was merged. + /// If the set is null or the field was not otherwise merged, this returns false. + /// + public static bool TryMergeFieldFrom(ref ExtensionSet set, ref ParseContext ctx) where TTarget : IExtendableMessage + { + Extension extension; + int lastFieldNumber = WireFormat.GetTagFieldNumber(ctx.LastTag); + + IExtensionValue extensionValue; + if (set != null && set.ValuesByNumber.TryGetValue(lastFieldNumber, out extensionValue)) + { + extensionValue.MergeFrom(ref ctx); + return true; + } + else if (ctx.ExtensionRegistry != null && ctx.ExtensionRegistry.ContainsInputField(ctx.LastTag, typeof(TTarget), out extension)) + { + IExtensionValue value = extension.CreateValue(); + value.MergeFrom(ref ctx); + set = (set ?? new ExtensionSet()); + set.ValuesByNumber.Add(extension.FieldNumber, value); + return true; + } + else + { + return false; + } + } + + /// + /// Merges the second set into the first set, creating a new instance if first is null + /// + public static void MergeFrom(ref ExtensionSet first, ExtensionSet second) where TTarget : IExtendableMessage + { + if (second == null) + { + return; + } + if (first == null) + { + first = new ExtensionSet(); + } + foreach (var pair in second.ValuesByNumber) + { + IExtensionValue value; + if (first.ValuesByNumber.TryGetValue(pair.Key, out value)) + { + value.MergeFrom(pair.Value); + } + else + { + var cloned = pair.Value.Clone(); + first.ValuesByNumber[pair.Key] = cloned; + } + } + } + + /// + /// Clones the set into a new set. If the set is null, this returns null + /// + public static ExtensionSet Clone(ExtensionSet set) where TTarget : IExtendableMessage + { + if (set == null) + { + return null; + } + + var newSet = new ExtensionSet(); + foreach (var pair in set.ValuesByNumber) + { + var cloned = pair.Value.Clone(); + newSet.ValuesByNumber[pair.Key] = cloned; + } + return newSet; + } + } + + /// + /// Used for keeping track of extensions in messages. + /// methods route to this set. + /// + /// Most users will not need to use this class directly + /// + /// The message type that extensions in this set target + public sealed class ExtensionSet where TTarget : IExtendableMessage + { + internal Dictionary ValuesByNumber { get; } = new Dictionary(); + + /// + /// Gets a hash code of the set + /// + public override int GetHashCode() + { + int ret = typeof(TTarget).GetHashCode(); + foreach (KeyValuePair field in ValuesByNumber) + { + // Use ^ here to make the field order irrelevant. + int hash = field.Key.GetHashCode() ^ field.Value.GetHashCode(); + ret ^= hash; + } + return ret; + } + + /// + /// Returns whether this set is equal to the other object + /// + public override bool Equals(object other) + { + if (ReferenceEquals(this, other)) + { + return true; + } + ExtensionSet otherSet = other as ExtensionSet; + if (ValuesByNumber.Count != otherSet.ValuesByNumber.Count) + { + return false; + } + foreach (var pair in ValuesByNumber) + { + IExtensionValue secondValue; + if (!otherSet.ValuesByNumber.TryGetValue(pair.Key, out secondValue)) + { + return false; + } + if (!pair.Value.Equals(secondValue)) + { + return false; + } + } + return true; + } + + /// + /// Calculates the size of this extension set + /// + public int CalculateSize() + { + int size = 0; + foreach (var value in ValuesByNumber.Values) + { + size += value.CalculateSize(); + } + return size; + } + + /// + /// Writes the extension values in this set to the output stream + /// + public void WriteTo(CodedOutputStream stream) + { + + WriteContext.Initialize(stream, out WriteContext ctx); + try + { + WriteTo(ref ctx); + } + finally + { + ctx.CopyStateTo(stream); + } + } + + /// + /// Writes the extension values in this set to the write context + /// + [SecuritySafeCritical] + public void WriteTo(ref WriteContext ctx) + { + foreach (var value in ValuesByNumber.Values) + { + value.WriteTo(ref ctx); + } + } + + internal bool IsInitialized() + { + return ValuesByNumber.Values.All(v => v.IsInitialized()); + } + } +} diff --git a/Libs/Google.Protobuf/ExtensionValue.cs b/Libs/Google.Protobuf/ExtensionValue.cs new file mode 100644 index 0000000..2b35159 --- /dev/null +++ b/Libs/Google.Protobuf/ExtensionValue.cs @@ -0,0 +1,225 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; +using System.Linq; + +namespace LC.Google.Protobuf +{ + internal interface IExtensionValue : IEquatable, IDeepCloneable + { + void MergeFrom(ref ParseContext ctx); + + void MergeFrom(IExtensionValue value); + void WriteTo(ref WriteContext ctx); + int CalculateSize(); + bool IsInitialized(); + } + + internal sealed class ExtensionValue : IExtensionValue + { + private T field; + private FieldCodec codec; + + internal ExtensionValue(FieldCodec codec) + { + this.codec = codec; + field = codec.DefaultValue; + } + + public int CalculateSize() + { + return codec.CalculateUnconditionalSizeWithTag(field); + } + + public IExtensionValue Clone() + { + return new ExtensionValue(codec) + { + field = field is IDeepCloneable ? (field as IDeepCloneable).Clone() : field + }; + } + + public bool Equals(IExtensionValue other) + { + if (ReferenceEquals(this, other)) + return true; + + return other is ExtensionValue + && codec.Equals((other as ExtensionValue).codec) + && Equals(field, (other as ExtensionValue).field); + // we check for equality in the codec since we could have equal field values however the values could be written in different ways + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 31 + field.GetHashCode(); + hash = hash * 31 + codec.GetHashCode(); + return hash; + } + } + + public void MergeFrom(ref ParseContext ctx) + { + codec.ValueMerger(ref ctx, ref field); + } + + public void MergeFrom(IExtensionValue value) + { + if (value is ExtensionValue) + { + var extensionValue = value as ExtensionValue; + codec.FieldMerger(ref field, extensionValue.field); + } + } + + public void WriteTo(ref WriteContext ctx) + { + ctx.WriteTag(codec.Tag); + codec.ValueWriter(ref ctx, field); + if (codec.EndTag != 0) + { + ctx.WriteTag(codec.EndTag); + } + } + + public T GetValue() => field; + + public void SetValue(T value) + { + field = value; + } + + public bool IsInitialized() + { + if (field is IMessage) + { + return (field as IMessage).IsInitialized(); + } + else + { + return true; + } + } + } + + internal sealed class RepeatedExtensionValue : IExtensionValue + { + private RepeatedField field; + private readonly FieldCodec codec; + + internal RepeatedExtensionValue(FieldCodec codec) + { + this.codec = codec; + field = new RepeatedField(); + } + + public int CalculateSize() + { + return field.CalculateSize(codec); + } + + public IExtensionValue Clone() + { + return new RepeatedExtensionValue(codec) + { + field = field.Clone() + }; + } + + public bool Equals(IExtensionValue other) + { + if (ReferenceEquals(this, other)) + return true; + + return other is RepeatedExtensionValue + && field.Equals((other as RepeatedExtensionValue).field) + && codec.Equals((other as RepeatedExtensionValue).codec); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 31 + field.GetHashCode(); + hash = hash * 31 + codec.GetHashCode(); + return hash; + } + } + + public void MergeFrom(ref ParseContext ctx) + { + field.AddEntriesFrom(ref ctx, codec); + } + + public void MergeFrom(IExtensionValue value) + { + if (value is RepeatedExtensionValue) + { + field.Add((value as RepeatedExtensionValue).field); + } + } + + public void WriteTo(ref WriteContext ctx) + { + field.WriteTo(ref ctx, codec); + } + + public RepeatedField GetValue() => field; + + public bool IsInitialized() + { + for (int i = 0; i < field.Count; i++) + { + var element = field[i]; + if (element is IMessage) + { + if (!(element as IMessage).IsInitialized()) + { + return false; + } + } + else + { + break; + } + } + + return true; + } + } +} diff --git a/Libs/Google.Protobuf/FieldCodec.cs b/Libs/Google.Protobuf/FieldCodec.cs new file mode 100644 index 0000000..b2447ac --- /dev/null +++ b/Libs/Google.Protobuf/FieldCodec.cs @@ -0,0 +1,887 @@ +#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 LC.Google.Protobuf.Collections; +using LC.Google.Protobuf.Compatibility; +using LC.Google.Protobuf.WellKnownTypes; +using System; +using System.Collections.Generic; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// Factory methods for . + /// + public static class FieldCodec + { + // TODO: Avoid the "dual hit" of lambda expressions: create open delegates instead. (At least test...) + + /// + /// Retrieves a codec suitable for a string field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForString(uint tag) + { + return FieldCodec.ForString(tag, ""); + } + + /// + /// Retrieves a codec suitable for a bytes field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForBytes(uint tag) + { + return FieldCodec.ForBytes(tag, ByteString.Empty); + } + + /// + /// Retrieves a codec suitable for a bool field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForBool(uint tag) + { + return FieldCodec.ForBool(tag, false); + } + + /// + /// Retrieves a codec suitable for an int32 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForInt32(uint tag) + { + return FieldCodec.ForInt32(tag, 0); + } + + /// + /// Retrieves a codec suitable for an sint32 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForSInt32(uint tag) + { + return FieldCodec.ForSInt32(tag, 0); + } + + /// + /// Retrieves a codec suitable for a fixed32 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForFixed32(uint tag) + { + return FieldCodec.ForFixed32(tag, 0); + } + + /// + /// Retrieves a codec suitable for an sfixed32 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForSFixed32(uint tag) + { + return FieldCodec.ForSFixed32(tag, 0); + } + + /// + /// Retrieves a codec suitable for a uint32 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForUInt32(uint tag) + { + return FieldCodec.ForUInt32(tag, 0); + } + + /// + /// Retrieves a codec suitable for an int64 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForInt64(uint tag) + { + return FieldCodec.ForInt64(tag, 0); + } + + /// + /// Retrieves a codec suitable for an sint64 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForSInt64(uint tag) + { + return FieldCodec.ForSInt64(tag, 0); + } + + /// + /// Retrieves a codec suitable for a fixed64 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForFixed64(uint tag) + { + return FieldCodec.ForFixed64(tag, 0); + } + + /// + /// Retrieves a codec suitable for an sfixed64 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForSFixed64(uint tag) + { + return FieldCodec.ForSFixed64(tag, 0); + } + + /// + /// Retrieves a codec suitable for a uint64 field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForUInt64(uint tag) + { + return FieldCodec.ForUInt64(tag, 0); + } + + /// + /// Retrieves a codec suitable for a float field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForFloat(uint tag) + { + return FieldCodec.ForFloat(tag, 0); + } + + /// + /// Retrieves a codec suitable for a double field with the given tag. + /// + /// The tag. + /// A codec for the given tag. + public static FieldCodec ForDouble(uint tag) + { + return FieldCodec.ForDouble(tag, 0); + } + + // Enums are tricky. We can probably use expression trees to build these delegates automatically, + // but it's easy to generate the code for it. + + /// + /// Retrieves a codec suitable for an enum field with the given tag. + /// + /// The tag. + /// A conversion function from to the enum type. + /// A conversion function from the enum type to . + /// A codec for the given tag. + public static FieldCodec ForEnum(uint tag, Func toInt32, Func fromInt32) + { + return FieldCodec.ForEnum(tag, toInt32, fromInt32, default(T)); + } + + /// + /// Retrieves a codec suitable for a string field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForString(uint tag, string defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadString(), (ref WriteContext ctx, string value) => ctx.WriteString(value), CodedOutputStream.ComputeStringSize, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a bytes field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForBytes(uint tag, ByteString defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadBytes(), (ref WriteContext ctx, ByteString value) => ctx.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a bool field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForBool(uint tag, bool defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadBool(), (ref WriteContext ctx, bool value) => ctx.WriteBool(value), CodedOutputStream.BoolSize, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for an int32 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForInt32(uint tag, int defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadInt32(), (ref WriteContext output, int value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for an sint32 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForSInt32(uint tag, int defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadSInt32(), (ref WriteContext output, int value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a fixed32 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForFixed32(uint tag, uint defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadFixed32(), (ref WriteContext output, uint value) => output.WriteFixed32(value), 4, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for an sfixed32 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForSFixed32(uint tag, int defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadSFixed32(), (ref WriteContext output, int value) => output.WriteSFixed32(value), 4, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a uint32 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForUInt32(uint tag, uint defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadUInt32(), (ref WriteContext output, uint value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for an int64 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForInt64(uint tag, long defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadInt64(), (ref WriteContext output, long value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for an sint64 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForSInt64(uint tag, long defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadSInt64(), (ref WriteContext output, long value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a fixed64 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForFixed64(uint tag, ulong defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadFixed64(), (ref WriteContext output, ulong value) => output.WriteFixed64(value), 8, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for an sfixed64 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForSFixed64(uint tag, long defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadSFixed64(), (ref WriteContext output, long value) => output.WriteSFixed64(value), 8, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a uint64 field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForUInt64(uint tag, ulong defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadUInt64(), (ref WriteContext output, ulong value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a float field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForFloat(uint tag, float defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadFloat(), (ref WriteContext output, float value) => output.WriteFloat(value), CodedOutputStream.FloatSize, tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a double field with the given tag. + /// + /// The tag. + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForDouble(uint tag, double defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => ctx.ReadDouble(), (ref WriteContext output, double value) => output.WriteDouble(value), CodedOutputStream.DoubleSize, tag, defaultValue); + } + + // Enums are tricky. We can probably use expression trees to build these delegates automatically, + // but it's easy to generate the code for it. + + /// + /// Retrieves a codec suitable for an enum field with the given tag. + /// + /// The tag. + /// A conversion function from to the enum type. + /// A conversion function from the enum type to . + /// The default value. + /// A codec for the given tag. + public static FieldCodec ForEnum(uint tag, Func toInt32, Func fromInt32, T defaultValue) + { + return new FieldCodec((ref ParseContext ctx) => fromInt32( + ctx.ReadEnum()), + (ref WriteContext output, T value) => output.WriteEnum(toInt32(value)), + value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag, defaultValue); + } + + /// + /// Retrieves a codec suitable for a message field with the given tag. + /// + /// The tag. + /// A parser to use for the message type. + /// A codec for the given tag. + public static FieldCodec ForMessage(uint tag, MessageParser parser) where T : class, IMessage + { + return new FieldCodec( + (ref ParseContext ctx) => + { + T message = parser.CreateTemplate(); + ctx.ReadMessage(message); + return message; + }, + (ref WriteContext output, T value) => output.WriteMessage(value), + (ref ParseContext ctx, ref T v) => + { + if (v == null) + { + v = parser.CreateTemplate(); + } + + ctx.ReadMessage(v); + }, + (ref T v, T v2) => + { + if (v2 == null) + { + return false; + } + else if (v == null) + { + v = v2.Clone(); + } + else + { + v.MergeFrom(v2); + } + return true; + }, + message => CodedOutputStream.ComputeMessageSize(message), tag); + } + + /// + /// Retrieves a codec suitable for a group field with the given tag. + /// + /// The start group tag. + /// The end group tag. + /// A parser to use for the group message type. + /// A codec for given tag + public static FieldCodec ForGroup(uint startTag, uint endTag, MessageParser parser) where T : class, IMessage + { + return new FieldCodec( + (ref ParseContext ctx) => + { + T message = parser.CreateTemplate(); + ctx.ReadGroup(message); + return message; + }, + (ref WriteContext output, T value) => output.WriteGroup(value), + (ref ParseContext ctx, ref T v) => + { + if (v == null) + { + v = parser.CreateTemplate(); + } + + ctx.ReadGroup(v); + }, + (ref T v, T v2) => + { + if (v2 == null) + { + return v == null; + } + else if (v == null) + { + v = v2.Clone(); + } + else + { + v.MergeFrom(v2); + } + return true; + }, + message => CodedOutputStream.ComputeGroupSize(message), startTag, endTag); + } + + /// + /// Creates a codec for a wrapper type of a class - which must be string or ByteString. + /// + public static FieldCodec ForClassWrapper(uint tag) where T : class + { + var nestedCodec = WrapperCodecs.GetCodec(); + return new FieldCodec( + (ref ParseContext ctx) => WrapperCodecs.Read(ref ctx, nestedCodec), + (ref WriteContext output, T value) => WrapperCodecs.Write(ref output, value, nestedCodec), + (ref ParseContext ctx, ref T v) => v = WrapperCodecs.Read(ref ctx, nestedCodec), + (ref T v, T v2) => { v = v2; return v == null; }, + value => WrapperCodecs.CalculateSize(value, nestedCodec), + tag, 0, + null); // Default value for the wrapper + } + + /// + /// Creates a codec for a wrapper type of a struct - which must be Int32, Int64, UInt32, UInt64, + /// Bool, Single or Double. + /// + public static FieldCodec ForStructWrapper(uint tag) where T : struct + { + var nestedCodec = WrapperCodecs.GetCodec(); + return new FieldCodec( + WrapperCodecs.GetReader(), + (ref WriteContext output, T? value) => WrapperCodecs.Write(ref output, value.Value, nestedCodec), + (ref ParseContext ctx, ref T? v) => v = WrapperCodecs.Read(ref ctx, nestedCodec), + (ref T? v, T? v2) => { if (v2.HasValue) { v = v2; } return v.HasValue; }, + value => value == null ? 0 : WrapperCodecs.CalculateSize(value.Value, nestedCodec), + tag, 0, + null); // Default value for the wrapper + } + + /// + /// Helper code to create codecs for wrapper types. + /// + /// + /// Somewhat ugly with all the static methods, but the conversions involved to/from nullable types make it + /// slightly tricky to improve. So long as we keep the public API (ForClassWrapper, ForStructWrapper) in place, + /// we can refactor later if we come up with something cleaner. + /// + private static class WrapperCodecs + { + private static readonly Dictionary Codecs = new Dictionary + { + { typeof(bool), ForBool(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) }, + { typeof(int), ForInt32(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) }, + { typeof(long), ForInt64(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) }, + { typeof(uint), ForUInt32(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) }, + { typeof(ulong), ForUInt64(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) }, + { typeof(float), ForFloat(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Fixed32)) }, + { typeof(double), ForDouble(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Fixed64)) }, + { typeof(string), ForString(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) }, + { typeof(ByteString), ForBytes(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) } + }; + + private static readonly Dictionary Readers = new Dictionary + { + // TODO: Provide more optimized readers. + { typeof(bool), (ValueReader)ParsingPrimitivesWrappers.ReadBoolWrapper }, + { typeof(int), (ValueReader)ParsingPrimitivesWrappers.ReadInt32Wrapper }, + { typeof(long), (ValueReader)ParsingPrimitivesWrappers.ReadInt64Wrapper }, + { typeof(uint), (ValueReader)ParsingPrimitivesWrappers.ReadUInt32Wrapper }, + { typeof(ulong), (ValueReader)ParsingPrimitivesWrappers.ReadUInt64Wrapper }, + { typeof(float), BitConverter.IsLittleEndian ? + (ValueReader)ParsingPrimitivesWrappers.ReadFloatWrapperLittleEndian : + (ValueReader)ParsingPrimitivesWrappers.ReadFloatWrapperSlow }, + { typeof(double), BitConverter.IsLittleEndian ? + (ValueReader)ParsingPrimitivesWrappers.ReadDoubleWrapperLittleEndian : + (ValueReader)ParsingPrimitivesWrappers.ReadDoubleWrapperSlow }, + // `string` and `ByteString` less performance-sensitive. Do not implement for now. + { typeof(string), null }, + { typeof(ByteString), null }, + }; + + /// + /// Returns a field codec which effectively wraps a value of type T in a message. + /// + /// + internal static FieldCodec GetCodec() + { + object value; + if (!Codecs.TryGetValue(typeof(T), out value)) + { + throw new InvalidOperationException("Invalid type argument requested for wrapper codec: " + typeof(T)); + } + return (FieldCodec) value; + } + + internal static ValueReader GetReader() where T : struct + { + object value; + if (!Readers.TryGetValue(typeof(T), out value)) + { + throw new InvalidOperationException("Invalid type argument requested for wrapper reader: " + typeof(T)); + } + if (value == null) + { + // Return default unoptimized reader for the wrapper type. + var nestedCoded = GetCodec(); + return (ref ParseContext ctx) => Read(ref ctx, nestedCoded); + } + // Return optimized read for the wrapper type. + return (ValueReader)value; + } + + [SecuritySafeCritical] + internal static T Read(ref ParseContext ctx, FieldCodec codec) + { + int length = ctx.ReadLength(); + int oldLimit = SegmentedBufferHelper.PushLimit(ref ctx.state, length); + + uint tag; + T value = codec.DefaultValue; + while ((tag = ctx.ReadTag()) != 0) + { + if (tag == codec.Tag) + { + value = codec.Read(ref ctx); + } + else + { + ParsingPrimitivesMessages.SkipLastField(ref ctx.buffer, ref ctx.state); + } + + } + ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref ctx.state); + SegmentedBufferHelper.PopLimit(ref ctx.state, oldLimit); + + return value; + } + + internal static void Write(ref WriteContext ctx, T value, FieldCodec codec) + { + ctx.WriteLength(codec.CalculateSizeWithTag(value)); + codec.WriteTagAndValue(ref ctx, value); + } + + internal static int CalculateSize(T value, FieldCodec codec) + { + int fieldLength = codec.CalculateSizeWithTag(value); + return CodedOutputStream.ComputeLengthSize(fieldLength) + fieldLength; + } + } + } + + internal delegate TValue ValueReader(ref ParseContext ctx); + internal delegate void ValueWriter(ref WriteContext ctx, T value); + + /// + /// + /// 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 class is public and has to be as it is used by generated code, but its public + /// API is very limited - just what the generated code needs to call directly. + /// + /// + /// + /// This never writes default values to the stream, and does not address "packedness" + /// in repeated fields itself, other than to know whether or not the field *should* be packed. + /// + public sealed class FieldCodec + { + private static readonly EqualityComparer EqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); + private static readonly T DefaultDefault; + // Only non-nullable value types support packing. This is the simplest way of detecting that. + private static readonly bool TypeSupportsPacking = default(T) != null; + + /// + /// Merges an input stream into a value + /// + internal delegate void InputMerger(ref ParseContext ctx, ref T value); + + /// + /// Merges a value into a reference to another value, returning a boolean if the value was set + /// + internal delegate bool ValuesMerger(ref T value, T other); + + static FieldCodec() + { + if (typeof(T) == typeof(string)) + { + DefaultDefault = (T)(object)""; + } + else if (typeof(T) == typeof(ByteString)) + { + DefaultDefault = (T)(object)ByteString.Empty; + } + // Otherwise it's the default value of the CLR type + } + + internal static bool IsPackedRepeatedField(uint tag) => + TypeSupportsPacking && WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited; + + internal bool PackedRepeatedField { get; } + + /// + /// Returns a delegate to write a value (unconditionally) to a coded output stream. + /// + internal ValueWriter ValueWriter { get; } + + /// + /// Returns the size calculator for just a value. + /// + internal Func ValueSizeCalculator { get; } + + /// + /// Returns a delegate to read a value from a coded input stream. It is assumed that + /// the stream is already positioned on the appropriate tag. + /// + internal ValueReader ValueReader { get; } + + /// + /// Returns a delegate to merge a value from a coded input stream. + /// It is assumed that the stream is already positioned on the appropriate tag + /// + internal InputMerger ValueMerger { get; } + + /// + /// Returns a delegate to merge two values together. + /// + internal ValuesMerger FieldMerger { get; } + + /// + /// Returns the fixed size for an entry, or 0 if sizes vary. + /// + internal int FixedSize { get; } + + /// + /// Gets the tag of the codec. + /// + /// + /// The tag of the codec. + /// + internal uint Tag { get; } + + /// + /// Gets the end tag of the codec or 0 if there is no end tag + /// + /// + /// The end tag of the codec. + /// + internal uint EndTag { get; } + + /// + /// Default value for this codec. Usually the same for every instance of the same type, but + /// for string/ByteString wrapper fields the codec's default value is null, whereas for + /// other string/ByteString fields it's "" or ByteString.Empty. + /// + /// + /// The default value of the codec's type. + /// + internal T DefaultValue { get; } + + private readonly int tagSize; + + internal FieldCodec( + ValueReader reader, + ValueWriter writer, + int fixedSize, + uint tag, + T defaultValue) : this(reader, writer, _ => fixedSize, tag, defaultValue) + { + FixedSize = fixedSize; + } + + internal FieldCodec( + ValueReader reader, + ValueWriter writer, + Func sizeCalculator, + uint tag, + T defaultValue) : this(reader, writer, (ref ParseContext ctx, ref T v) => v = reader(ref ctx), (ref T v, T v2) => { v = v2; return true; }, sizeCalculator, tag, 0, defaultValue) + { + } + + internal FieldCodec( + ValueReader reader, + ValueWriter writer, + InputMerger inputMerger, + ValuesMerger valuesMerger, + Func sizeCalculator, + uint tag, + uint endTag = 0) : this(reader, writer, inputMerger, valuesMerger, sizeCalculator, tag, endTag, DefaultDefault) + { + } + + internal FieldCodec( + ValueReader reader, + ValueWriter writer, + InputMerger inputMerger, + ValuesMerger valuesMerger, + Func sizeCalculator, + uint tag, + uint endTag, + T defaultValue) + { + ValueReader = reader; + ValueWriter = writer; + ValueMerger = inputMerger; + FieldMerger = valuesMerger; + ValueSizeCalculator = sizeCalculator; + FixedSize = 0; + Tag = tag; + EndTag = endTag; + DefaultValue = defaultValue; + tagSize = CodedOutputStream.ComputeRawVarint32Size(tag); + if (endTag != 0) + tagSize += CodedOutputStream.ComputeRawVarint32Size(endTag); + // Detect packed-ness once, so we can check for it within RepeatedField. + PackedRepeatedField = IsPackedRepeatedField(tag); + } + + /// + /// Write a tag and the given value, *if* the value is not the default. + /// + public void WriteTagAndValue(CodedOutputStream output, T value) + { + WriteContext.Initialize(output, out WriteContext ctx); + try + { + WriteTagAndValue(ref ctx, value); + } + finally + { + ctx.CopyStateTo(output); + } + + + //if (!IsDefault(value)) + //{ + // output.WriteTag(Tag); + // ValueWriter(output, value); + // if (EndTag != 0) + // { + // output.WriteTag(EndTag); + // } + //} + } + + /// + /// Write a tag and the given value, *if* the value is not the default. + /// + public void WriteTagAndValue(ref WriteContext ctx, T value) + { + if (!IsDefault(value)) + { + ctx.WriteTag(Tag); + ValueWriter(ref ctx, value); + if (EndTag != 0) + { + ctx.WriteTag(EndTag); + } + } + } + + /// + /// Reads a value of the codec type from the given . + /// + /// The input stream to read from. + /// The value read from the stream. + public T Read(CodedInputStream input) + { + ParseContext.Initialize(input, out ParseContext ctx); + try + { + return ValueReader(ref ctx); + } + finally + { + ctx.CopyStateTo(input); + } + } + + /// + /// Reads a value of the codec type from the given . + /// + /// The parse context to read from. + /// The value read. + public T Read(ref ParseContext ctx) + { + return ValueReader(ref ctx); + } + + /// + /// Calculates the size required to write the given value, with a tag, + /// if the value is not the default. + /// + public int CalculateSizeWithTag(T value) => IsDefault(value) ? 0 : ValueSizeCalculator(value) + tagSize; + + /// + /// Calculates the size required to write the given value, with a tag, even + /// if the value is the default. + /// + internal int CalculateUnconditionalSizeWithTag(T value) => ValueSizeCalculator(value) + tagSize; + + private bool IsDefault(T value) => EqualityComparer.Equals(value, DefaultValue); + } +} diff --git a/Libs/Google.Protobuf/FieldMaskTree.cs b/Libs/Google.Protobuf/FieldMaskTree.cs new file mode 100644 index 0000000..068efa1 --- /dev/null +++ b/Libs/Google.Protobuf/FieldMaskTree.cs @@ -0,0 +1,365 @@ +#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.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using LC.Google.Protobuf.Reflection; +using LC.Google.Protobuf.WellKnownTypes; + +namespace LC.Google.Protobuf +{ + /// + /// A tree representation of a FieldMask. Each leaf node in this tree represent + /// a field path in the FieldMask. + /// + /// For example, FieldMask "foo.bar,foo.baz,bar.baz" as a tree will be: + /// + /// [root] -+- foo -+- bar + /// | | + /// | +- baz + /// | + /// +- bar --- baz + /// + /// + /// By representing FieldMasks with this tree structure we can easily convert + /// a FieldMask to a canonical form, merge two FieldMasks, calculate the + /// intersection to two FieldMasks and traverse all fields specified by the + /// FieldMask in a message tree. + /// + internal sealed class FieldMaskTree + { + private const char FIELD_PATH_SEPARATOR = '.'; + + internal sealed class Node + { + public Dictionary Children { get; } = new Dictionary(); + } + + private readonly Node root = new Node(); + + /// + /// Creates an empty FieldMaskTree. + /// + public FieldMaskTree() + { + } + + /// + /// Creates a FieldMaskTree for a given FieldMask. + /// + public FieldMaskTree(FieldMask mask) + { + MergeFromFieldMask(mask); + } + + public override string ToString() + { + return ToFieldMask().ToString(); + } + + /// + /// Adds a field path to the tree. In a FieldMask, every field path matches the + /// specified field as well as all its sub-fields. For example, a field path + /// "foo.bar" matches field "foo.bar" and also "foo.bar.baz", etc. When adding + /// a field path to the tree, redundant sub-paths will be removed. That is, + /// after adding "foo.bar" to the tree, "foo.bar.baz" will be removed if it + /// exists, which will turn the tree node for "foo.bar" to a leaf node. + /// Likewise, if the field path to add is a sub-path of an existing leaf node, + /// nothing will be changed in the tree. + /// + public FieldMaskTree AddFieldPath(string path) + { + var parts = path.Split(FIELD_PATH_SEPARATOR); + if (parts.Length == 0) + { + return this; + } + + var node = root; + var createNewBranch = false; + + // Find the matching node in the tree. + foreach (var part in parts) + { + // Check whether the path matches an existing leaf node. + if (!createNewBranch + && node != root + && node.Children.Count == 0) + { + // The path to add is a sub-path of an existing leaf node. + return this; + } + + Node childNode; + if (!node.Children.TryGetValue(part, out childNode)) + { + createNewBranch = true; + childNode = new Node(); + node.Children.Add(part, childNode); + } + node = childNode; + } + + // Turn the matching node into a leaf node (i.e., remove sub-paths). + node.Children.Clear(); + return this; + } + + /// + /// Merges all field paths in a FieldMask into this tree. + /// + public FieldMaskTree MergeFromFieldMask(FieldMask mask) + { + foreach (var path in mask.Paths) + { + AddFieldPath(path); + } + + return this; + } + + /// + /// Converts this tree to a FieldMask. + /// + public FieldMask ToFieldMask() + { + var mask = new FieldMask(); + if (root.Children.Count != 0) + { + var paths = new List(); + GetFieldPaths(root, "", paths); + mask.Paths.AddRange(paths); + } + + return mask; + } + + /// + /// Gathers all field paths in a sub-tree. + /// + private void GetFieldPaths(Node node, string path, List paths) + { + if (node.Children.Count == 0) + { + paths.Add(path); + return; + } + + foreach (var entry in node.Children) + { + var childPath = path.Length == 0 ? entry.Key : path + "." + entry.Key; + GetFieldPaths(entry.Value, childPath, paths); + } + } + + /// + /// Adds the intersection of this tree with the given to . + /// + public void IntersectFieldPath(string path, FieldMaskTree output) + { + if (root.Children.Count == 0) + { + return; + } + + var parts = path.Split(FIELD_PATH_SEPARATOR); + if (parts.Length == 0) + { + return; + } + + var node = root; + foreach (var part in parts) + { + if (node != root + && node.Children.Count == 0) + { + // The given path is a sub-path of an existing leaf node in the tree. + output.AddFieldPath(path); + return; + } + + if (!node.Children.TryGetValue(part, out node)) + { + return; + } + } + + // We found a matching node for the path. All leaf children of this matching + // node is in the intersection. + var paths = new List(); + GetFieldPaths(node, path, paths); + foreach (var value in paths) + { + output.AddFieldPath(value); + } + } + + /// + /// Merges all fields specified by this FieldMaskTree from to . + /// + public void Merge(IMessage source, IMessage destination, FieldMask.MergeOptions options) + { + if (source.Descriptor != destination.Descriptor) + { + throw new InvalidProtocolBufferException("Cannot merge messages of different types."); + } + + if (root.Children.Count == 0) + { + return; + } + + Merge(root, "", source, destination, options); + } + + /// + /// Merges all fields specified by a sub-tree from to . + /// + private void Merge( + Node node, + string path, + IMessage source, + IMessage destination, + FieldMask.MergeOptions options) + { + if (source.Descriptor != destination.Descriptor) + { + throw new InvalidProtocolBufferException($"source ({source.Descriptor}) and destination ({destination.Descriptor}) descriptor must be equal"); + } + + var descriptor = source.Descriptor; + foreach (var entry in node.Children) + { + var field = descriptor.FindFieldByName(entry.Key); + if (field == null) + { + Debug.WriteLine($"Cannot find field \"{entry.Key}\" in message type \"{descriptor.FullName}\""); + continue; + } + + if (entry.Value.Children.Count != 0) + { + if (field.IsRepeated + || field.FieldType != FieldType.Message) + { + Debug.WriteLine($"Field \"{field.FullName}\" is not a singular message field and cannot have sub-fields."); + continue; + } + + var sourceField = field.Accessor.GetValue(source); + var destinationField = field.Accessor.GetValue(destination); + if (sourceField == null + && destinationField == null) + { + // If the message field is not present in both source and destination, skip recursing + // so we don't create unnecessary empty messages. + continue; + } + + if (destinationField == null) + { + // If we have to merge but the destination does not contain the field, create it. + destinationField = field.MessageType.Parser.CreateTemplate(); + field.Accessor.SetValue(destination, destinationField); + } + + var childPath = path.Length == 0 ? entry.Key : path + "." + entry.Key; + Merge(entry.Value, childPath, (IMessage)sourceField, (IMessage)destinationField, options); + continue; + } + + if (field.IsRepeated) + { + if (options.ReplaceRepeatedFields) + { + field.Accessor.Clear(destination); + } + + var sourceField = (IList)field.Accessor.GetValue(source); + var destinationField = (IList)field.Accessor.GetValue(destination); + foreach (var element in sourceField) + { + destinationField.Add(element); + } + } + else + { + var sourceField = field.Accessor.GetValue(source); + if (field.FieldType == FieldType.Message) + { + if (options.ReplaceMessageFields) + { + if (sourceField == null) + { + field.Accessor.Clear(destination); + } + else + { + field.Accessor.SetValue(destination, sourceField); + } + } + else + { + if (sourceField != null) + { + var sourceByteString = ((IMessage)sourceField).ToByteString(); + var destinationValue = (IMessage)field.Accessor.GetValue(destination); + if (destinationValue != null) + { + destinationValue.MergeFrom(sourceByteString); + } + else + { + field.Accessor.SetValue(destination, field.MessageType.Parser.ParseFrom(sourceByteString)); + } + } + } + } + else + { + if (sourceField != null + || !options.ReplacePrimitiveFields) + { + field.Accessor.SetValue(destination, sourceField); + } + else + { + field.Accessor.Clear(destination); + } + } + } + } + } + } +} diff --git a/Libs/Google.Protobuf/FrameworkPortability.cs b/Libs/Google.Protobuf/FrameworkPortability.cs new file mode 100644 index 0000000..e931031 --- /dev/null +++ b/Libs/Google.Protobuf/FrameworkPortability.cs @@ -0,0 +1,49 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Text.RegularExpressions; + +namespace LC.Google.Protobuf +{ + /// + /// Class containing helpful workarounds for various platform compatibility + /// + internal static class FrameworkPortability + { + // The value of RegexOptions.Compiled is 8. We can test for the presence at + // execution time using Enum.IsDefined, so a single build will do the right thing + // on each platform. (RegexOptions.Compiled isn't supported by PCLs.) + internal static readonly RegexOptions CompiledRegexWhereAvailable = + Enum.IsDefined(typeof(RegexOptions), 8) ? (RegexOptions)8 : RegexOptions.None; + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/IBufferMessage.cs b/Libs/Google.Protobuf/IBufferMessage.cs new file mode 100644 index 0000000..7bd62d4 --- /dev/null +++ b/Libs/Google.Protobuf/IBufferMessage.cs @@ -0,0 +1,53 @@ +#region Copyright notice and license +// 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. +#endregion + +namespace LC.Google.Protobuf +{ + /// + /// Interface for a Protocol Buffers message, supporting + /// parsing from and writing to . + /// + public interface IBufferMessage : IMessage + { + /// + /// Internal implementation of merging data from given parse context into this message. + /// Users should never invoke this method directly. + /// + void InternalMergeFrom(ref ParseContext ctx); + + /// + /// Internal implementation of writing this message to a given write context. + /// Users should never invoke this method directly. + /// + void InternalWriteTo(ref WriteContext ctx); + } +} diff --git a/Libs/Google.Protobuf/ICustomDiagnosticMessage.cs b/Libs/Google.Protobuf/ICustomDiagnosticMessage.cs new file mode 100644 index 0000000..976688f --- /dev/null +++ b/Libs/Google.Protobuf/ICustomDiagnosticMessage.cs @@ -0,0 +1,69 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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 + +namespace LC.Google.Protobuf +{ + /// + /// A message type that has a custom string format for diagnostic purposes. + /// + /// + /// + /// Calling on a generated message type normally + /// returns the JSON representation. If a message type implements this interface, + /// then the method will be called instead of the regular + /// JSON formatting code, but only when ToString() is called either on the message itself + /// or on another message which contains it. This does not affect the normal JSON formatting of + /// the message. + /// + /// + /// For example, if you create a proto message representing a GUID, the internal + /// representation may be a bytes field or four fixed32 fields. However, when debugging + /// it may be more convenient to see a result in the same format as provides. + /// + /// This interface extends to avoid it accidentally being implemented + /// on types other than messages, where it would not be used by anything in the framework. + /// + public interface ICustomDiagnosticMessage : IMessage + { + /// + /// Returns a string representation of this object, for diagnostic purposes. + /// + /// + /// This method is called when a message is formatted as part of a + /// call. It does not affect the JSON representation used by other than + /// in calls to . While it is recommended + /// that the result is valid JSON, this is never assumed by the Protobuf library. + /// + /// A string representation of this object, for diagnostic purposes. + string ToDiagnosticString(); + } +} diff --git a/Libs/Google.Protobuf/IDeepCloneable.cs b/Libs/Google.Protobuf/IDeepCloneable.cs new file mode 100644 index 0000000..183571d --- /dev/null +++ b/Libs/Google.Protobuf/IDeepCloneable.cs @@ -0,0 +1,54 @@ +#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 + +namespace LC.Google.Protobuf +{ + /// + /// Generic interface for a deeply cloneable type. + /// + /// + /// + /// All generated messages implement this interface, but so do some non-message types. + /// Additionally, due to the type constraint on T in , + /// it is simpler to keep this as a separate interface. + /// + /// + /// The type itself, returned by the method. + public interface IDeepCloneable + { + /// + /// Creates a deep clone of this object. + /// + /// A deep clone of this object. + T Clone(); + } +} diff --git a/Libs/Google.Protobuf/IExtendableMessage.cs b/Libs/Google.Protobuf/IExtendableMessage.cs new file mode 100644 index 0000000..b5e1adc --- /dev/null +++ b/Libs/Google.Protobuf/IExtendableMessage.cs @@ -0,0 +1,79 @@ +#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 LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + /// + /// Generic interface for a Protocol Buffers message containing one or more extensions, where the type parameter is expected to be the same type as the implementation class. + /// This interface is experiemental and is subject to change. + /// + public interface IExtendableMessage : IMessage where T : IExtendableMessage + { + /// + /// Gets the value of the specified extension + /// + TValue GetExtension(Extension extension); + + /// + /// Gets the value of the specified repeated extension or null if the extension isn't registered in this set. + /// For a version of this method that never returns null, use + /// + RepeatedField GetExtension(RepeatedExtension extension); + + /// + /// Gets the value of the specified repeated extension, registering it if it hasn't already been registered. + /// + RepeatedField GetOrInitializeExtension(RepeatedExtension extension); + + /// + /// Sets the value of the specified extension + /// + void SetExtension(Extension extension, TValue value); + + /// + /// Gets whether the value of the specified extension is set + /// + bool HasExtension(Extension extension); + + /// + /// Clears the value of the specified extension + /// + void ClearExtension(Extension extension); + + /// + /// Clears the value of the specified repeated extension + /// + void ClearExtension(RepeatedExtension extension); + } +} diff --git a/Libs/Google.Protobuf/IMessage.cs b/Libs/Google.Protobuf/IMessage.cs new file mode 100644 index 0000000..d4c3b36 --- /dev/null +++ b/Libs/Google.Protobuf/IMessage.cs @@ -0,0 +1,87 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using LC.Google.Protobuf.Reflection; + +namespace LC.Google.Protobuf +{ + /// + /// Interface for a Protocol Buffers message, supporting + /// basic operations required for serialization. + /// + public interface IMessage + { + /// + /// Merges the data from the specified coded input stream with the current message. + /// + /// See the user guide for precise merge semantics. + /// + void MergeFrom(CodedInputStream input); + + /// + /// Writes the data to the given coded output stream. + /// + /// Coded output stream to write the data to. Must not be null. + void WriteTo(CodedOutputStream output); + + /// + /// Calculates the size of this message in Protocol Buffer wire format, in bytes. + /// + /// The number of bytes required to write this message + /// to a coded output stream. + int CalculateSize(); + + /// + /// Descriptor for this message. All instances are expected to return the same descriptor, + /// and for generated types this will be an explicitly-implemented member, returning the + /// same value as the static property declared on the type. + /// + MessageDescriptor Descriptor { get; } + } + + /// + /// Generic interface for a Protocol Buffers message, + /// where the type parameter is expected to be the same type as + /// the implementation class. + /// + /// The message type. + public interface IMessage : IMessage, IEquatable, IDeepCloneable where T : IMessage + { + /// + /// Merges the given message into this one. + /// + /// See the user guide for precise merge semantics. + /// The message to merge with this one. Must not be null. + void MergeFrom(T message); + } +} diff --git a/Libs/Google.Protobuf/InvalidJsonException.cs b/Libs/Google.Protobuf/InvalidJsonException.cs new file mode 100644 index 0000000..8a8c242 --- /dev/null +++ b/Libs/Google.Protobuf/InvalidJsonException.cs @@ -0,0 +1,53 @@ +#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.IO; + +namespace LC.Google.Protobuf +{ + /// + /// Thrown when an attempt is made to parse invalid JSON, e.g. using + /// a non-string property key, or including a redundant comma. Parsing a protocol buffer + /// message represented in JSON using can throw both this + /// exception and depending on the situation. This + /// exception is only thrown for "pure JSON" errors, whereas InvalidProtocolBufferException + /// is thrown when the JSON may be valid in and of itself, but cannot be parsed as a protocol buffer + /// message. + /// + public sealed class InvalidJsonException : IOException + { + internal InvalidJsonException(string message) + : base(message) + { + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/InvalidProtocolBufferException.cs b/Libs/Google.Protobuf/InvalidProtocolBufferException.cs new file mode 100644 index 0000000..22dc559 --- /dev/null +++ b/Libs/Google.Protobuf/InvalidProtocolBufferException.cs @@ -0,0 +1,140 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.IO; + +namespace LC.Google.Protobuf +{ + /// + /// Thrown when a protocol message being parsed is invalid in some way, + /// e.g. it contains a malformed varint or a negative byte length. + /// + public sealed class InvalidProtocolBufferException : IOException + { + internal InvalidProtocolBufferException(string message) + : base(message) + { + } + + internal InvalidProtocolBufferException(string message, Exception innerException) + : base(message, innerException) + { + } + + internal static InvalidProtocolBufferException MoreDataAvailable() + { + return new InvalidProtocolBufferException( + "Completed reading a message while more data was available in the stream."); + } + + internal static InvalidProtocolBufferException TruncatedMessage() + { + return new InvalidProtocolBufferException( + "While parsing a protocol message, the input ended unexpectedly " + + "in the middle of a field. This could mean either that the " + + "input has been truncated or that an embedded message " + + "misreported its own length."); + } + + internal static InvalidProtocolBufferException NegativeSize() + { + return new InvalidProtocolBufferException( + "CodedInputStream encountered an embedded string or message " + + "which claimed to have negative size."); + } + + internal static InvalidProtocolBufferException MalformedVarint() + { + return new InvalidProtocolBufferException( + "CodedInputStream encountered a malformed varint."); + } + + /// + /// Creates an exception for an error condition of an invalid tag being encountered. + /// + internal static InvalidProtocolBufferException InvalidTag() + { + return new InvalidProtocolBufferException( + "Protocol message contained an invalid tag (zero)."); + } + + internal static InvalidProtocolBufferException InvalidWireType() + { + return new InvalidProtocolBufferException( + "Protocol message contained a tag with an invalid wire type."); + } + + internal static InvalidProtocolBufferException InvalidBase64(Exception innerException) + { + return new InvalidProtocolBufferException("Invalid base64 data", innerException); + } + + internal static InvalidProtocolBufferException InvalidEndTag() + { + return new InvalidProtocolBufferException( + "Protocol message end-group tag did not match expected tag."); + } + + internal static InvalidProtocolBufferException RecursionLimitExceeded() + { + return new InvalidProtocolBufferException( + "Protocol message had too many levels of nesting. May be malicious. " + + "Use CodedInputStream.SetRecursionLimit() to increase the depth limit."); + } + + internal static InvalidProtocolBufferException JsonRecursionLimitExceeded() + { + return new InvalidProtocolBufferException( + "Protocol message had too many levels of nesting. May be malicious. " + + "Use JsonParser.Settings to increase the depth limit."); + } + + internal static InvalidProtocolBufferException SizeLimitExceeded() + { + return new InvalidProtocolBufferException( + "Protocol message was too large. May be malicious. " + + "Use CodedInputStream.SetSizeLimit() to increase the size limit."); + } + + internal static InvalidProtocolBufferException InvalidMessageStreamTag() + { + return new InvalidProtocolBufferException( + "Stream of protocol messages had invalid tag. Expected tag is length-delimited field 1."); + } + + internal static InvalidProtocolBufferException MissingFields() + { + return new InvalidProtocolBufferException("Message was missing required fields"); + } +} +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/JsonFormatter.cs b/Libs/Google.Protobuf/JsonFormatter.cs new file mode 100644 index 0000000..9d39fd2 --- /dev/null +++ b/Libs/Google.Protobuf/JsonFormatter.cs @@ -0,0 +1,927 @@ +#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.Globalization; +using System.Text; +using LC.Google.Protobuf.Reflection; +using LC.Google.Protobuf.WellKnownTypes; +using System.IO; +using System.Linq; +using System.Collections.Generic; +using System.Reflection; + +namespace LC.Google.Protobuf +{ + /// + /// Reflection-based converter from messages to JSON. + /// + /// + /// + /// Instances of this class are thread-safe, with no mutable state. + /// + /// + /// This is a simple start to get JSON formatting working. As it's reflection-based, + /// it's not as quick as baking calls into generated messages - but is a simpler implementation. + /// (This code is generally not heavily optimized.) + /// + /// + public sealed class JsonFormatter + { + internal const string AnyTypeUrlField = "@type"; + internal const string AnyDiagnosticValueField = "@value"; + internal const string AnyWellKnownTypeValueField = "value"; + private const string TypeUrlPrefix = "type.googleapis.com"; + private const string NameValueSeparator = ": "; + private const string PropertySeparator = ", "; + + /// + /// Returns a formatter using the default settings. + /// + public static JsonFormatter Default { get; } = new JsonFormatter(Settings.Default); + + // A JSON formatter which *only* exists + private static readonly JsonFormatter diagnosticFormatter = new JsonFormatter(Settings.Default); + + /// + /// The JSON representation of the first 160 characters of Unicode. + /// Empty strings are replaced by the static constructor. + /// + private static readonly string[] CommonRepresentations = { + // C0 (ASCII and derivatives) control characters + "\\u0000", "\\u0001", "\\u0002", "\\u0003", // 0x00 + "\\u0004", "\\u0005", "\\u0006", "\\u0007", + "\\b", "\\t", "\\n", "\\u000b", + "\\f", "\\r", "\\u000e", "\\u000f", + "\\u0010", "\\u0011", "\\u0012", "\\u0013", // 0x10 + "\\u0014", "\\u0015", "\\u0016", "\\u0017", + "\\u0018", "\\u0019", "\\u001a", "\\u001b", + "\\u001c", "\\u001d", "\\u001e", "\\u001f", + // Escaping of " and \ are required by www.json.org string definition. + // Escaping of < and > are required for HTML security. + "", "", "\\\"", "", "", "", "", "", // 0x20 + "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", // 0x30 + "", "", "", "", "\\u003c", "", "\\u003e", "", + "", "", "", "", "", "", "", "", // 0x40 + "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", // 0x50 + "", "", "", "", "\\\\", "", "", "", + "", "", "", "", "", "", "", "", // 0x60 + "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", // 0x70 + "", "", "", "", "", "", "", "\\u007f", + // C1 (ISO 8859 and Unicode) extended control characters + "\\u0080", "\\u0081", "\\u0082", "\\u0083", // 0x80 + "\\u0084", "\\u0085", "\\u0086", "\\u0087", + "\\u0088", "\\u0089", "\\u008a", "\\u008b", + "\\u008c", "\\u008d", "\\u008e", "\\u008f", + "\\u0090", "\\u0091", "\\u0092", "\\u0093", // 0x90 + "\\u0094", "\\u0095", "\\u0096", "\\u0097", + "\\u0098", "\\u0099", "\\u009a", "\\u009b", + "\\u009c", "\\u009d", "\\u009e", "\\u009f" + }; + + static JsonFormatter() + { + for (int i = 0; i < CommonRepresentations.Length; i++) + { + if (CommonRepresentations[i] == "") + { + CommonRepresentations[i] = ((char) i).ToString(); + } + } + } + + private readonly Settings settings; + + private bool DiagnosticOnly => ReferenceEquals(this, diagnosticFormatter); + + /// + /// Creates a new formatted with the given settings. + /// + /// The settings. + public JsonFormatter(Settings settings) + { + this.settings = ProtoPreconditions.CheckNotNull(settings, nameof(settings)); + } + + /// + /// Formats the specified message as JSON. + /// + /// The message to format. + /// The formatted message. + public string Format(IMessage message) + { + var writer = new StringWriter(); + Format(message, writer); + return writer.ToString(); + } + + /// + /// Formats the specified message as JSON. + /// + /// The message to format. + /// The TextWriter to write the formatted message to. + /// The formatted message. + public void Format(IMessage message, TextWriter writer) + { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + ProtoPreconditions.CheckNotNull(writer, nameof(writer)); + + if (message.Descriptor.IsWellKnownType) + { + WriteWellKnownTypeValue(writer, message.Descriptor, message); + } + else + { + WriteMessage(writer, message); + } + } + + /// + /// Converts a message to JSON for diagnostic purposes with no extra context. + /// + /// + /// + /// This differs from calling on the default JSON + /// formatter in its handling of . As no type registry is available + /// in calls, the normal way of resolving the type of + /// an Any message cannot be applied. Instead, a JSON property named @value + /// is included with the base64 data from the property of the message. + /// + /// The value returned by this method is only designed to be used for diagnostic + /// purposes. It may not be parsable by , and may not be parsable + /// by other Protocol Buffer implementations. + /// + /// The message to format for diagnostic purposes. + /// The diagnostic-only JSON representation of the message + public static string ToDiagnosticString(IMessage message) + { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + return diagnosticFormatter.Format(message); + } + + private void WriteMessage(TextWriter writer, IMessage message) + { + if (message == null) + { + WriteNull(writer); + return; + } + if (DiagnosticOnly) + { + ICustomDiagnosticMessage customDiagnosticMessage = message as ICustomDiagnosticMessage; + if (customDiagnosticMessage != null) + { + writer.Write(customDiagnosticMessage.ToDiagnosticString()); + return; + } + } + writer.Write("{ "); + bool writtenFields = WriteMessageFields(writer, message, false); + writer.Write(writtenFields ? " }" : "}"); + } + + private bool WriteMessageFields(TextWriter writer, IMessage message, bool assumeFirstFieldWritten) + { + var fields = message.Descriptor.Fields; + bool first = !assumeFirstFieldWritten; + // First non-oneof fields + foreach (var field in fields.InFieldNumberOrder()) + { + var accessor = field.Accessor; + var value = accessor.GetValue(message); + if (!ShouldFormatFieldValue(message, field, value)) + { + continue; + } + + if (!first) + { + writer.Write(PropertySeparator); + } + + WriteString(writer, accessor.Descriptor.JsonName); + writer.Write(NameValueSeparator); + WriteValue(writer, value); + + first = false; + } + return !first; + } + + /// + /// Determines whether or not a field value should be serialized according to the field, + /// its value in the message, and the settings of this formatter. + /// + private bool ShouldFormatFieldValue(IMessage message, FieldDescriptor field, object value) => + field.HasPresence + // Fields that support presence *just* use that + ? field.Accessor.HasValue(message) + // Otherwise, format if either we've been asked to format default values, or if it's + // not a default value anyway. + : settings.FormatDefaultValues || !IsDefaultValue(field, value); + + // Converted from java/core/src/main/java/com/google/protobuf/Descriptors.java + internal static string ToJsonName(string name) + { + StringBuilder result = new StringBuilder(name.Length); + bool isNextUpperCase = false; + foreach (char ch in name) + { + if (ch == '_') + { + isNextUpperCase = true; + } + else if (isNextUpperCase) + { + result.Append(char.ToUpperInvariant(ch)); + isNextUpperCase = false; + } + else + { + result.Append(ch); + } + } + return result.ToString(); + } + + internal static string FromJsonName(string name) + { + StringBuilder result = new StringBuilder(name.Length); + foreach (char ch in name) + { + if (char.IsUpper(ch)) + { + result.Append('_'); + result.Append(char.ToLowerInvariant(ch)); + } + else + { + result.Append(ch); + } + } + return result.ToString(); + } + + private static void WriteNull(TextWriter writer) + { + writer.Write("null"); + } + + private static bool IsDefaultValue(FieldDescriptor descriptor, object value) + { + if (descriptor.IsMap) + { + IDictionary dictionary = (IDictionary) value; + return dictionary.Count == 0; + } + if (descriptor.IsRepeated) + { + IList list = (IList) value; + return list.Count == 0; + } + switch (descriptor.FieldType) + { + case FieldType.Bool: + return (bool) value == false; + case FieldType.Bytes: + return (ByteString) value == ByteString.Empty; + case FieldType.String: + return (string) value == ""; + case FieldType.Double: + return (double) value == 0.0; + case FieldType.SInt32: + case FieldType.Int32: + case FieldType.SFixed32: + case FieldType.Enum: + return (int) value == 0; + case FieldType.Fixed32: + case FieldType.UInt32: + return (uint) value == 0; + case FieldType.Fixed64: + case FieldType.UInt64: + return (ulong) value == 0; + case FieldType.SFixed64: + case FieldType.Int64: + case FieldType.SInt64: + return (long) value == 0; + case FieldType.Float: + return (float) value == 0f; + case FieldType.Message: + case FieldType.Group: // Never expect to get this, but... + return value == null; + default: + throw new ArgumentException("Invalid field type"); + } + } + + /// + /// Writes a single value to the given writer as JSON. Only types understood by + /// Protocol Buffers can be written in this way. This method is only exposed for + /// advanced use cases; most users should be using + /// or . + /// + /// The writer to write the value to. Must not be null. + /// The value to write. May be null. + public void WriteValue(TextWriter writer, object value) + { + if (value == null || value is NullValue) + { + WriteNull(writer); + } + else if (value is bool) + { + writer.Write((bool)value ? "true" : "false"); + } + else if (value is ByteString) + { + // Nothing in Base64 needs escaping + writer.Write('"'); + writer.Write(((ByteString)value).ToBase64()); + writer.Write('"'); + } + else if (value is string) + { + WriteString(writer, (string)value); + } + else if (value is IDictionary) + { + WriteDictionary(writer, (IDictionary)value); + } + else if (value is IList) + { + WriteList(writer, (IList)value); + } + else if (value is int || value is uint) + { + IFormattable formattable = (IFormattable) value; + writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); + } + else if (value is long || value is ulong) + { + writer.Write('"'); + IFormattable formattable = (IFormattable) value; + writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); + writer.Write('"'); + } + else if (value is System.Enum) + { + if (settings.FormatEnumsAsIntegers) + { + WriteValue(writer, (int)value); + } + else + { + string name = OriginalEnumValueHelper.GetOriginalName(value); + if (name != null) + { + WriteString(writer, name); + } + else + { + WriteValue(writer, (int)value); + } + } + } + else if (value is float || value is double) + { + string text = ((IFormattable) value).ToString("r", CultureInfo.InvariantCulture); + if (text == "NaN" || text == "Infinity" || text == "-Infinity") + { + writer.Write('"'); + writer.Write(text); + writer.Write('"'); + } + else + { + writer.Write(text); + } + } + else if (value is IMessage) + { + Format((IMessage)value, writer); + } + else + { + throw new ArgumentException("Unable to format value of type " + value.GetType()); + } + } + + /// + /// Central interception point for well-known type formatting. Any well-known types which + /// don't need special handling can fall back to WriteMessage. We avoid assuming that the + /// values are using the embedded well-known types, in order to allow for dynamic messages + /// in the future. + /// + private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, object value) + { + // Currently, we can never actually get here, because null values are always handled by the caller. But if we *could*, + // this would do the right thing. + if (value == null) + { + WriteNull(writer); + return; + } + // For wrapper types, the value will either be the (possibly boxed) "native" value, + // or the message itself if we're formatting it at the top level (e.g. just calling ToString on the object itself). + // If it's the message form, we can extract the value first, which *will* be the (possibly boxed) native value, + // and then proceed, writing it as if we were definitely in a field. (We never need to wrap it in an extra string... + // WriteValue will do the right thing.) + if (descriptor.IsWrapperType) + { + if (value is IMessage) + { + var message = (IMessage) value; + value = message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.GetValue(message); + } + WriteValue(writer, value); + return; + } + if (descriptor.FullName == Timestamp.Descriptor.FullName) + { + WriteTimestamp(writer, (IMessage)value); + return; + } + if (descriptor.FullName == Duration.Descriptor.FullName) + { + WriteDuration(writer, (IMessage)value); + return; + } + if (descriptor.FullName == FieldMask.Descriptor.FullName) + { + WriteFieldMask(writer, (IMessage)value); + return; + } + if (descriptor.FullName == Struct.Descriptor.FullName) + { + WriteStruct(writer, (IMessage)value); + return; + } + if (descriptor.FullName == ListValue.Descriptor.FullName) + { + var fieldAccessor = descriptor.Fields[ListValue.ValuesFieldNumber].Accessor; + WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value)); + return; + } + if (descriptor.FullName == Value.Descriptor.FullName) + { + WriteStructFieldValue(writer, (IMessage)value); + return; + } + if (descriptor.FullName == Any.Descriptor.FullName) + { + WriteAny(writer, (IMessage)value); + return; + } + WriteMessage(writer, (IMessage)value); + } + + private void WriteTimestamp(TextWriter writer, IMessage value) + { + // TODO: In the common case where this *is* using the built-in Timestamp type, we could + // avoid all the reflection at this point, by casting to Timestamp. In the interests of + // avoiding subtle bugs, don't do that until we've implemented DynamicMessage so that we can prove + // it still works in that case. + int nanos = (int) value.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.GetValue(value); + long seconds = (long) value.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.GetValue(value); + writer.Write(Timestamp.ToJson(seconds, nanos, DiagnosticOnly)); + } + + private void WriteDuration(TextWriter writer, IMessage value) + { + // TODO: Same as for WriteTimestamp + int nanos = (int) value.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.GetValue(value); + long seconds = (long) value.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.GetValue(value); + writer.Write(Duration.ToJson(seconds, nanos, DiagnosticOnly)); + } + + private void WriteFieldMask(TextWriter writer, IMessage value) + { + var paths = (IList) value.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(value); + writer.Write(FieldMask.ToJson(paths, DiagnosticOnly)); + } + + private void WriteAny(TextWriter writer, IMessage value) + { + if (DiagnosticOnly) + { + WriteDiagnosticOnlyAny(writer, value); + return; + } + + string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); + ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); + string typeName = Any.GetTypeName(typeUrl); + MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName); + if (descriptor == null) + { + throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'"); + } + IMessage message = descriptor.Parser.ParseFrom(data); + writer.Write("{ "); + WriteString(writer, AnyTypeUrlField); + writer.Write(NameValueSeparator); + WriteString(writer, typeUrl); + + if (descriptor.IsWellKnownType) + { + writer.Write(PropertySeparator); + WriteString(writer, AnyWellKnownTypeValueField); + writer.Write(NameValueSeparator); + WriteWellKnownTypeValue(writer, descriptor, message); + } + else + { + WriteMessageFields(writer, message, true); + } + writer.Write(" }"); + } + + private void WriteDiagnosticOnlyAny(TextWriter writer, IMessage value) + { + string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); + ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); + writer.Write("{ "); + WriteString(writer, AnyTypeUrlField); + writer.Write(NameValueSeparator); + WriteString(writer, typeUrl); + writer.Write(PropertySeparator); + WriteString(writer, AnyDiagnosticValueField); + writer.Write(NameValueSeparator); + writer.Write('"'); + writer.Write(data.ToBase64()); + writer.Write('"'); + writer.Write(" }"); + } + + private void WriteStruct(TextWriter writer, IMessage message) + { + writer.Write("{ "); + IDictionary fields = (IDictionary) message.Descriptor.Fields[Struct.FieldsFieldNumber].Accessor.GetValue(message); + bool first = true; + foreach (DictionaryEntry entry in fields) + { + string key = (string) entry.Key; + IMessage value = (IMessage) entry.Value; + if (string.IsNullOrEmpty(key) || value == null) + { + throw new InvalidOperationException("Struct fields cannot have an empty key or a null value."); + } + + if (!first) + { + writer.Write(PropertySeparator); + } + WriteString(writer, key); + writer.Write(NameValueSeparator); + WriteStructFieldValue(writer, value); + first = false; + } + writer.Write(first ? "}" : " }"); + } + + private void WriteStructFieldValue(TextWriter writer, IMessage message) + { + var specifiedField = message.Descriptor.Oneofs[0].Accessor.GetCaseFieldDescriptor(message); + if (specifiedField == null) + { + throw new InvalidOperationException("Value message must contain a value for the oneof."); + } + + object value = specifiedField.Accessor.GetValue(message); + + switch (specifiedField.FieldNumber) + { + case Value.BoolValueFieldNumber: + case Value.StringValueFieldNumber: + case Value.NumberValueFieldNumber: + WriteValue(writer, value); + return; + case Value.StructValueFieldNumber: + case Value.ListValueFieldNumber: + // Structs and ListValues are nested messages, and already well-known types. + var nestedMessage = (IMessage) specifiedField.Accessor.GetValue(message); + WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage); + return; + case Value.NullValueFieldNumber: + WriteNull(writer); + return; + default: + throw new InvalidOperationException("Unexpected case in struct field: " + specifiedField.FieldNumber); + } + } + + internal void WriteList(TextWriter writer, IList list) + { + writer.Write("[ "); + bool first = true; + foreach (var value in list) + { + if (!first) + { + writer.Write(PropertySeparator); + } + WriteValue(writer, value); + first = false; + } + writer.Write(first ? "]" : " ]"); + } + + internal void WriteDictionary(TextWriter writer, IDictionary dictionary) + { + writer.Write("{ "); + bool first = true; + // This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of disposal. + foreach (DictionaryEntry pair in dictionary) + { + if (!first) + { + writer.Write(PropertySeparator); + } + string keyText; + if (pair.Key is string) + { + keyText = (string) pair.Key; + } + else if (pair.Key is bool) + { + keyText = (bool) pair.Key ? "true" : "false"; + } + else if (pair.Key is int || pair.Key is uint | pair.Key is long || pair.Key is ulong) + { + keyText = ((IFormattable) pair.Key).ToString("d", CultureInfo.InvariantCulture); + } + else + { + if (pair.Key == null) + { + throw new ArgumentException("Dictionary has entry with null key"); + } + throw new ArgumentException("Unhandled dictionary key type: " + pair.Key.GetType()); + } + WriteString(writer, keyText); + writer.Write(NameValueSeparator); + WriteValue(writer, pair.Value); + first = false; + } + writer.Write(first ? "}" : " }"); + } + + /// + /// Writes a string (including leading and trailing double quotes) to a builder, escaping as required. + /// + /// + /// Other than surrogate pair handling, this code is mostly taken from src/google/protobuf/util/internal/json_escaping.cc. + /// + internal static void WriteString(TextWriter writer, string text) + { + writer.Write('"'); + for (int i = 0; i < text.Length; i++) + { + char c = text[i]; + if (c < 0xa0) + { + writer.Write(CommonRepresentations[c]); + continue; + } + if (char.IsHighSurrogate(c)) + { + // Encountered first part of a surrogate pair. + // Check that we have the whole pair, and encode both parts as hex. + i++; + if (i == text.Length || !char.IsLowSurrogate(text[i])) + { + throw new ArgumentException("String contains low surrogate not followed by high surrogate"); + } + HexEncodeUtf16CodeUnit(writer, c); + HexEncodeUtf16CodeUnit(writer, text[i]); + continue; + } + else if (char.IsLowSurrogate(c)) + { + throw new ArgumentException("String contains high surrogate not preceded by low surrogate"); + } + switch ((uint) c) + { + // These are not required by json spec + // but used to prevent security bugs in javascript. + case 0xfeff: // Zero width no-break space + case 0xfff9: // Interlinear annotation anchor + case 0xfffa: // Interlinear annotation separator + case 0xfffb: // Interlinear annotation terminator + + case 0x00ad: // Soft-hyphen + case 0x06dd: // Arabic end of ayah + case 0x070f: // Syriac abbreviation mark + case 0x17b4: // Khmer vowel inherent Aq + case 0x17b5: // Khmer vowel inherent Aa + HexEncodeUtf16CodeUnit(writer, c); + break; + + default: + if ((c >= 0x0600 && c <= 0x0603) || // Arabic signs + (c >= 0x200b && c <= 0x200f) || // Zero width etc. + (c >= 0x2028 && c <= 0x202e) || // Separators etc. + (c >= 0x2060 && c <= 0x2064) || // Invisible etc. + (c >= 0x206a && c <= 0x206f)) + { + HexEncodeUtf16CodeUnit(writer, c); + } + else + { + // No handling of surrogates here - that's done earlier + writer.Write(c); + } + break; + } + } + writer.Write('"'); + } + + private const string Hex = "0123456789abcdef"; + private static void HexEncodeUtf16CodeUnit(TextWriter writer, char c) + { + writer.Write("\\u"); + writer.Write(Hex[(c >> 12) & 0xf]); + writer.Write(Hex[(c >> 8) & 0xf]); + writer.Write(Hex[(c >> 4) & 0xf]); + writer.Write(Hex[(c >> 0) & 0xf]); + } + + /// + /// Settings controlling JSON formatting. + /// + public sealed class Settings + { + /// + /// Default settings, as used by + /// + public static Settings Default { get; } + + // Workaround for the Mono compiler complaining about XML comments not being on + // valid language elements. + static Settings() + { + Default = new Settings(false); + } + + /// + /// Whether fields which would otherwise not be included in the formatted data + /// should be formatted even when the value is not present, or has the default value. + /// This option only affects fields which don't support "presence" (e.g. + /// singular non-optional proto3 primitive fields). + /// + public bool FormatDefaultValues { get; } + + /// + /// The type registry used to format messages. + /// + public TypeRegistry TypeRegistry { get; } + + /// + /// Whether to format enums as ints. Defaults to false. + /// + public bool FormatEnumsAsIntegers { get; } + + + /// + /// Creates a new object with the specified formatting of default values + /// and an empty type registry. + /// + /// true if default values (0, empty strings etc) should be formatted; false otherwise. + public Settings(bool formatDefaultValues) : this(formatDefaultValues, TypeRegistry.Empty) + { + } + + /// + /// Creates a new object with the specified formatting of default values + /// and type registry. + /// + /// true if default values (0, empty strings etc) should be formatted; false otherwise. + /// The to use when formatting messages. + public Settings(bool formatDefaultValues, TypeRegistry typeRegistry) : this(formatDefaultValues, typeRegistry, false) + { + } + + /// + /// Creates a new object with the specified parameters. + /// + /// true if default values (0, empty strings etc) should be formatted; false otherwise. + /// The to use when formatting messages. TypeRegistry.Empty will be used if it is null. + /// true to format the enums as integers; false to format enums as enum names. + private Settings(bool formatDefaultValues, + TypeRegistry typeRegistry, + bool formatEnumsAsIntegers) + { + FormatDefaultValues = formatDefaultValues; + TypeRegistry = typeRegistry ?? TypeRegistry.Empty; + FormatEnumsAsIntegers = formatEnumsAsIntegers; + } + + /// + /// Creates a new object with the specified formatting of default values and the current settings. + /// + /// true if default values (0, empty strings etc) should be formatted; false otherwise. + public Settings WithFormatDefaultValues(bool formatDefaultValues) => new Settings(formatDefaultValues, TypeRegistry, FormatEnumsAsIntegers); + + /// + /// Creates a new object with the specified type registry and the current settings. + /// + /// The to use when formatting messages. + public Settings WithTypeRegistry(TypeRegistry typeRegistry) => new Settings(FormatDefaultValues, typeRegistry, FormatEnumsAsIntegers); + + /// + /// Creates a new object with the specified enums formatting option and the current settings. + /// + /// true to format the enums as integers; false to format enums as enum names. + public Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers) => new Settings(FormatDefaultValues, TypeRegistry, formatEnumsAsIntegers); + } + + // Effectively a cache of mapping from enum values to the original name as specified in the proto file, + // fetched by reflection. + // The need for this is unfortunate, as is its unbounded size, but realistically it shouldn't cause issues. + private static class OriginalEnumValueHelper + { + // TODO: In the future we might want to use ConcurrentDictionary, at the point where all + // the platforms we target have it. + private static readonly Dictionary> dictionaries + = new Dictionary>(); + + internal static string GetOriginalName(object value) + { + var enumType = value.GetType(); + Dictionary nameMapping; + lock (dictionaries) + { + if (!dictionaries.TryGetValue(enumType, out nameMapping)) + { + nameMapping = GetNameMapping(enumType); + dictionaries[enumType] = nameMapping; + } + } + + string originalName; + // If this returns false, originalName will be null, which is what we want. + nameMapping.TryGetValue(value, out originalName); + return originalName; + } + +#if NET35 + // TODO: Consider adding functionality to TypeExtensions to avoid this difference. + private static Dictionary GetNameMapping(System.Type enumType) => + enumType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static) + .Where(f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false) + .FirstOrDefault() as OriginalNameAttribute) + ?.PreferredAlias ?? true) + .ToDictionary(f => f.GetValue(null), + f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false) + .FirstOrDefault() as OriginalNameAttribute) + // If the attribute hasn't been applied, fall back to the name of the field. + ?.Name ?? f.Name); +#else + private static Dictionary GetNameMapping(System.Type enumType) => + enumType.GetTypeInfo().DeclaredFields + .Where(f => f.IsStatic) + .Where(f => f.GetCustomAttributes() + .FirstOrDefault()?.PreferredAlias ?? true) + .ToDictionary(f => f.GetValue(null), + f => f.GetCustomAttributes() + .FirstOrDefault() + // If the attribute hasn't been applied, fall back to the name of the field. + ?.Name ?? f.Name); +#endif + } + } +} diff --git a/Libs/Google.Protobuf/JsonParser.cs b/Libs/Google.Protobuf/JsonParser.cs new file mode 100644 index 0000000..504cb46 --- /dev/null +++ b/Libs/Google.Protobuf/JsonParser.cs @@ -0,0 +1,1073 @@ +#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 LC.Google.Protobuf.Reflection; +using LC.Google.Protobuf.WellKnownTypes; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace LC.Google.Protobuf +{ + /// + /// Reflection-based converter from JSON to messages. + /// + /// + /// + /// Instances of this class are thread-safe, with no mutable state. + /// + /// + /// This is a simple start to get JSON parsing working. As it's reflection-based, + /// it's not as quick as baking calls into generated messages - but is a simpler implementation. + /// (This code is generally not heavily optimized.) + /// + /// + public sealed class JsonParser + { + // Note: using 0-9 instead of \d to ensure no non-ASCII digits. + // This regex isn't a complete validator, but will remove *most* invalid input. We rely on parsing to do the rest. + private static readonly Regex TimestampRegex = new Regex(@"^(?[0-9]{4}-[01][0-9]-[0-3][0-9]T[012][0-9]:[0-5][0-9]:[0-5][0-9])(?\.[0-9]{1,9})?(?(Z|[+-][0-1][0-9]:[0-5][0-9]))$", FrameworkPortability.CompiledRegexWhereAvailable); + private static readonly Regex DurationRegex = new Regex(@"^(?-)?(?[0-9]{1,12})(?\.[0-9]{1,9})?s$", FrameworkPortability.CompiledRegexWhereAvailable); + private static readonly int[] SubsecondScalingFactors = { 0, 100000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1 }; + private static readonly char[] FieldMaskPathSeparators = new[] { ',' }; + private static readonly EnumDescriptor NullValueDescriptor = StructReflection.Descriptor.EnumTypes.Single(ed => ed.ClrType == typeof(NullValue)); + + private static readonly JsonParser defaultInstance = new JsonParser(Settings.Default); + + // TODO: Consider introducing a class containing parse state of the parser, tokenizer and depth. That would simplify these handlers + // and the signatures of various methods. + private static readonly Dictionary> + WellKnownTypeHandlers = new Dictionary> + { + { Timestamp.Descriptor.FullName, (parser, message, tokenizer) => MergeTimestamp(message, tokenizer.Next()) }, + { Duration.Descriptor.FullName, (parser, message, tokenizer) => MergeDuration(message, tokenizer.Next()) }, + { Value.Descriptor.FullName, (parser, message, tokenizer) => parser.MergeStructValue(message, tokenizer) }, + { ListValue.Descriptor.FullName, (parser, message, tokenizer) => + parser.MergeRepeatedField(message, message.Descriptor.Fields[ListValue.ValuesFieldNumber], tokenizer) }, + { Struct.Descriptor.FullName, (parser, message, tokenizer) => parser.MergeStruct(message, tokenizer) }, + { Any.Descriptor.FullName, (parser, message, tokenizer) => parser.MergeAny(message, tokenizer) }, + { FieldMask.Descriptor.FullName, (parser, message, tokenizer) => MergeFieldMask(message, tokenizer.Next()) }, + { Int32Value.Descriptor.FullName, MergeWrapperField }, + { Int64Value.Descriptor.FullName, MergeWrapperField }, + { UInt32Value.Descriptor.FullName, MergeWrapperField }, + { UInt64Value.Descriptor.FullName, MergeWrapperField }, + { FloatValue.Descriptor.FullName, MergeWrapperField }, + { DoubleValue.Descriptor.FullName, MergeWrapperField }, + { BytesValue.Descriptor.FullName, MergeWrapperField }, + { StringValue.Descriptor.FullName, MergeWrapperField }, + { BoolValue.Descriptor.FullName, MergeWrapperField } + }; + + // Convenience method to avoid having to repeat the same code multiple times in the above + // dictionary initialization. + private static void MergeWrapperField(JsonParser parser, IMessage message, JsonTokenizer tokenizer) + { + parser.MergeField(message, message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber], tokenizer); + } + + /// + /// Returns a formatter using the default settings. + /// + public static JsonParser Default { get { return defaultInstance; } } + + private readonly Settings settings; + + /// + /// Creates a new formatted with the given settings. + /// + /// The settings. + public JsonParser(Settings settings) + { + this.settings = ProtoPreconditions.CheckNotNull(settings, nameof(settings)); + } + + /// + /// Parses and merges the information into the given message. + /// + /// The message to merge the JSON information into. + /// The JSON to parse. + internal void Merge(IMessage message, string json) + { + Merge(message, new StringReader(json)); + } + + /// + /// Parses JSON read from and merges the information into the given message. + /// + /// The message to merge the JSON information into. + /// Reader providing the JSON to parse. + internal void Merge(IMessage message, TextReader jsonReader) + { + var tokenizer = JsonTokenizer.FromTextReader(jsonReader); + Merge(message, tokenizer); + var lastToken = tokenizer.Next(); + if (lastToken != JsonToken.EndDocument) + { + throw new InvalidProtocolBufferException("Expected end of JSON after object"); + } + } + + /// + /// Merges the given message using data from the given tokenizer. In most cases, the next + /// token should be a "start object" token, but wrapper types and nullity can invalidate + /// that assumption. This is implemented as an LL(1) recursive descent parser over the stream + /// of tokens provided by the tokenizer. This token stream is assumed to be valid JSON, with the + /// tokenizer performing that validation - but not every token stream is valid "protobuf JSON". + /// + private void Merge(IMessage message, JsonTokenizer tokenizer) + { + if (tokenizer.ObjectDepth > settings.RecursionLimit) + { + throw InvalidProtocolBufferException.JsonRecursionLimitExceeded(); + } + if (message.Descriptor.IsWellKnownType) + { + Action handler; + if (WellKnownTypeHandlers.TryGetValue(message.Descriptor.FullName, out handler)) + { + handler(this, message, tokenizer); + return; + } + // Well-known types with no special handling continue in the normal way. + } + var token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.StartObject) + { + throw new InvalidProtocolBufferException("Expected an object"); + } + var descriptor = message.Descriptor; + var jsonFieldMap = descriptor.Fields.ByJsonName(); + // All the oneof fields we've already accounted for - we can only see each of them once. + // The set is created lazily to avoid the overhead of creating a set for every message + // we parsed, when oneofs are relatively rare. + HashSet seenOneofs = null; + while (true) + { + token = tokenizer.Next(); + if (token.Type == JsonToken.TokenType.EndObject) + { + return; + } + if (token.Type != JsonToken.TokenType.Name) + { + throw new InvalidOperationException("Unexpected token type " + token.Type); + } + string name = token.StringValue; + FieldDescriptor field; + if (jsonFieldMap.TryGetValue(name, out field)) + { + if (field.ContainingOneof != null) + { + if (seenOneofs == null) + { + seenOneofs = new HashSet(); + } + if (!seenOneofs.Add(field.ContainingOneof)) + { + throw new InvalidProtocolBufferException($"Multiple values specified for oneof {field.ContainingOneof.Name}"); + } + } + MergeField(message, field, tokenizer); + } + else + { + if (settings.IgnoreUnknownFields) + { + tokenizer.SkipValue(); + } + else + { + throw new InvalidProtocolBufferException("Unknown field: " + name); + } + } + } + } + + private void MergeField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer) + { + var token = tokenizer.Next(); + if (token.Type == JsonToken.TokenType.Null) + { + // Clear the field if we see a null token, unless it's for a singular field of type + // google.protobuf.Value or google.protobuf.NullValue. + // Note: different from Java API, which just ignores it. + // TODO: Bring it more in line? Discuss... + if (field.IsMap || field.IsRepeated || + !(IsGoogleProtobufValueField(field) || IsGoogleProtobufNullValueField(field))) + { + field.Accessor.Clear(message); + return; + } + } + tokenizer.PushBack(token); + + if (field.IsMap) + { + MergeMapField(message, field, tokenizer); + } + else if (field.IsRepeated) + { + MergeRepeatedField(message, field, tokenizer); + } + else + { + var value = ParseSingleValue(field, tokenizer); + field.Accessor.SetValue(message, value); + } + } + + private void MergeRepeatedField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer) + { + var token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.StartArray) + { + throw new InvalidProtocolBufferException("Repeated field value was not an array. Token type: " + token.Type); + } + + IList list = (IList) field.Accessor.GetValue(message); + while (true) + { + token = tokenizer.Next(); + if (token.Type == JsonToken.TokenType.EndArray) + { + return; + } + tokenizer.PushBack(token); + object value = ParseSingleValue(field, tokenizer); + if (value == null) + { + throw new InvalidProtocolBufferException("Repeated field elements cannot be null"); + } + list.Add(value); + } + } + + private void MergeMapField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer) + { + // Map fields are always objects, even if the values are well-known types: ParseSingleValue handles those. + var token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.StartObject) + { + throw new InvalidProtocolBufferException("Expected an object to populate a map"); + } + + var type = field.MessageType; + var keyField = type.FindFieldByNumber(1); + var valueField = type.FindFieldByNumber(2); + if (keyField == null || valueField == null) + { + throw new InvalidProtocolBufferException("Invalid map field: " + field.FullName); + } + IDictionary dictionary = (IDictionary) field.Accessor.GetValue(message); + + while (true) + { + token = tokenizer.Next(); + if (token.Type == JsonToken.TokenType.EndObject) + { + return; + } + object key = ParseMapKey(keyField, token.StringValue); + object value = ParseSingleValue(valueField, tokenizer); + if (value == null) + { + throw new InvalidProtocolBufferException("Map values must not be null"); + } + dictionary[key] = value; + } + } + + private static bool IsGoogleProtobufValueField(FieldDescriptor field) + { + return field.FieldType == FieldType.Message && + field.MessageType.FullName == Value.Descriptor.FullName; + } + + private static bool IsGoogleProtobufNullValueField(FieldDescriptor field) + { + return field.FieldType == FieldType.Enum && + field.EnumType.FullName == NullValueDescriptor.FullName; + } + + private object ParseSingleValue(FieldDescriptor field, JsonTokenizer tokenizer) + { + var token = tokenizer.Next(); + if (token.Type == JsonToken.TokenType.Null) + { + // TODO: In order to support dynamic messages, we should really build this up + // dynamically. + if (IsGoogleProtobufValueField(field)) + { + return Value.ForNull(); + } + if (IsGoogleProtobufNullValueField(field)) + { + return NullValue.NullValue; + } + return null; + } + + var fieldType = field.FieldType; + if (fieldType == FieldType.Message) + { + // Parse wrapper types as their constituent types. + // TODO: What does this mean for null? + if (field.MessageType.IsWrapperType) + { + field = field.MessageType.Fields[WrappersReflection.WrapperValueFieldNumber]; + fieldType = field.FieldType; + } + else + { + // TODO: Merge the current value in message? (Public API currently doesn't make this relevant as we don't expose merging.) + tokenizer.PushBack(token); + IMessage subMessage = NewMessageForField(field); + Merge(subMessage, tokenizer); + return subMessage; + } + } + + switch (token.Type) + { + case JsonToken.TokenType.True: + case JsonToken.TokenType.False: + if (fieldType == FieldType.Bool) + { + return token.Type == JsonToken.TokenType.True; + } + // Fall through to "we don't support this type for this case"; could duplicate the behaviour of the default + // case instead, but this way we'd only need to change one place. + goto default; + case JsonToken.TokenType.StringValue: + return ParseSingleStringValue(field, token.StringValue); + // Note: not passing the number value itself here, as we may end up storing the string value in the token too. + case JsonToken.TokenType.Number: + return ParseSingleNumberValue(field, token); + case JsonToken.TokenType.Null: + throw new NotImplementedException("Haven't worked out what to do for null yet"); + default: + throw new InvalidProtocolBufferException("Unsupported JSON token type " + token.Type + " for field type " + fieldType); + } + } + + /// + /// Parses into a new message. + /// + /// The type of message to create. + /// The JSON to parse. + /// The JSON does not comply with RFC 7159 + /// The JSON does not represent a Protocol Buffers message correctly + public T Parse(string json) where T : IMessage, new() + { + ProtoPreconditions.CheckNotNull(json, nameof(json)); + return Parse(new StringReader(json)); + } + + /// + /// Parses JSON read from into a new message. + /// + /// The type of message to create. + /// Reader providing the JSON to parse. + /// The JSON does not comply with RFC 7159 + /// The JSON does not represent a Protocol Buffers message correctly + public T Parse(TextReader jsonReader) where T : IMessage, new() + { + ProtoPreconditions.CheckNotNull(jsonReader, nameof(jsonReader)); + T message = new T(); + Merge(message, jsonReader); + return message; + } + + /// + /// Parses into a new message. + /// + /// The JSON to parse. + /// Descriptor of message type to parse. + /// The JSON does not comply with RFC 7159 + /// The JSON does not represent a Protocol Buffers message correctly + public IMessage Parse(string json, MessageDescriptor descriptor) + { + ProtoPreconditions.CheckNotNull(json, nameof(json)); + ProtoPreconditions.CheckNotNull(descriptor, nameof(descriptor)); + return Parse(new StringReader(json), descriptor); + } + + /// + /// Parses JSON read from into a new message. + /// + /// Reader providing the JSON to parse. + /// Descriptor of message type to parse. + /// The JSON does not comply with RFC 7159 + /// The JSON does not represent a Protocol Buffers message correctly + public IMessage Parse(TextReader jsonReader, MessageDescriptor descriptor) + { + ProtoPreconditions.CheckNotNull(jsonReader, nameof(jsonReader)); + ProtoPreconditions.CheckNotNull(descriptor, nameof(descriptor)); + IMessage message = descriptor.Parser.CreateTemplate(); + Merge(message, jsonReader); + return message; + } + + private void MergeStructValue(IMessage message, JsonTokenizer tokenizer) + { + var firstToken = tokenizer.Next(); + var fields = message.Descriptor.Fields; + switch (firstToken.Type) + { + case JsonToken.TokenType.Null: + fields[Value.NullValueFieldNumber].Accessor.SetValue(message, 0); + return; + case JsonToken.TokenType.StringValue: + fields[Value.StringValueFieldNumber].Accessor.SetValue(message, firstToken.StringValue); + return; + case JsonToken.TokenType.Number: + fields[Value.NumberValueFieldNumber].Accessor.SetValue(message, firstToken.NumberValue); + return; + case JsonToken.TokenType.False: + case JsonToken.TokenType.True: + fields[Value.BoolValueFieldNumber].Accessor.SetValue(message, firstToken.Type == JsonToken.TokenType.True); + return; + case JsonToken.TokenType.StartObject: + { + var field = fields[Value.StructValueFieldNumber]; + var structMessage = NewMessageForField(field); + tokenizer.PushBack(firstToken); + Merge(structMessage, tokenizer); + field.Accessor.SetValue(message, structMessage); + return; + } + case JsonToken.TokenType.StartArray: + { + var field = fields[Value.ListValueFieldNumber]; + var list = NewMessageForField(field); + tokenizer.PushBack(firstToken); + Merge(list, tokenizer); + field.Accessor.SetValue(message, list); + return; + } + default: + throw new InvalidOperationException("Unexpected token type: " + firstToken.Type); + } + } + + private void MergeStruct(IMessage message, JsonTokenizer tokenizer) + { + var token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.StartObject) + { + throw new InvalidProtocolBufferException("Expected object value for Struct"); + } + tokenizer.PushBack(token); + + var field = message.Descriptor.Fields[Struct.FieldsFieldNumber]; + MergeMapField(message, field, tokenizer); + } + + private void MergeAny(IMessage message, JsonTokenizer tokenizer) + { + // Record the token stream until we see the @type property. At that point, we can take the value, consult + // the type registry for the relevant message, and replay the stream, omitting the @type property. + var tokens = new List(); + + var token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.StartObject) + { + throw new InvalidProtocolBufferException("Expected object value for Any"); + } + int typeUrlObjectDepth = tokenizer.ObjectDepth; + + // The check for the property depth protects us from nested Any values which occur before the type URL + // for *this* Any. + while (token.Type != JsonToken.TokenType.Name || + token.StringValue != JsonFormatter.AnyTypeUrlField || + tokenizer.ObjectDepth != typeUrlObjectDepth) + { + tokens.Add(token); + token = tokenizer.Next(); + + if (tokenizer.ObjectDepth < typeUrlObjectDepth) + { + throw new InvalidProtocolBufferException("Any message with no @type"); + } + } + + // Don't add the @type property or its value to the recorded token list + token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.StringValue) + { + throw new InvalidProtocolBufferException("Expected string value for Any.@type"); + } + string typeUrl = token.StringValue; + string typeName = Any.GetTypeName(typeUrl); + + MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName); + if (descriptor == null) + { + throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'"); + } + + // Now replay the token stream we've already read and anything that remains of the object, just parsing it + // as normal. Our original tokenizer should end up at the end of the object. + var replay = JsonTokenizer.FromReplayedTokens(tokens, tokenizer); + var body = descriptor.Parser.CreateTemplate(); + if (descriptor.IsWellKnownType) + { + MergeWellKnownTypeAnyBody(body, replay); + } + else + { + Merge(body, replay); + } + var data = body.ToByteString(); + + // Now that we have the message data, we can pack it into an Any (the message received as a parameter). + message.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.SetValue(message, typeUrl); + message.Descriptor.Fields[Any.ValueFieldNumber].Accessor.SetValue(message, data); + } + + // Well-known types end up in a property called "value" in the JSON. As there's no longer a @type property + // in the given JSON token stream, we should *only* have tokens of start-object, name("value"), the value + // itself, and then end-object. + private void MergeWellKnownTypeAnyBody(IMessage body, JsonTokenizer tokenizer) + { + var token = tokenizer.Next(); // Definitely start-object; checked in previous method + token = tokenizer.Next(); + // TODO: What about an absent Int32Value, for example? + if (token.Type != JsonToken.TokenType.Name || token.StringValue != JsonFormatter.AnyWellKnownTypeValueField) + { + throw new InvalidProtocolBufferException($"Expected '{JsonFormatter.AnyWellKnownTypeValueField}' property for well-known type Any body"); + } + Merge(body, tokenizer); + token = tokenizer.Next(); + if (token.Type != JsonToken.TokenType.EndObject) + { + throw new InvalidProtocolBufferException($"Expected end-object token after @type/value for well-known type"); + } + } + + #region Utility methods which don't depend on the state (or settings) of the parser. + private static object ParseMapKey(FieldDescriptor field, string keyText) + { + switch (field.FieldType) + { + case FieldType.Bool: + if (keyText == "true") + { + return true; + } + if (keyText == "false") + { + return false; + } + throw new InvalidProtocolBufferException("Invalid string for bool map key: " + keyText); + case FieldType.String: + return keyText; + case FieldType.Int32: + case FieldType.SInt32: + case FieldType.SFixed32: + return ParseNumericString(keyText, int.Parse); + case FieldType.UInt32: + case FieldType.Fixed32: + return ParseNumericString(keyText, uint.Parse); + case FieldType.Int64: + case FieldType.SInt64: + case FieldType.SFixed64: + return ParseNumericString(keyText, long.Parse); + case FieldType.UInt64: + case FieldType.Fixed64: + return ParseNumericString(keyText, ulong.Parse); + default: + throw new InvalidProtocolBufferException("Invalid field type for map: " + field.FieldType); + } + } + + private static object ParseSingleNumberValue(FieldDescriptor field, JsonToken token) + { + double value = token.NumberValue; + checked + { + try + { + switch (field.FieldType) + { + case FieldType.Int32: + case FieldType.SInt32: + case FieldType.SFixed32: + CheckInteger(value); + return (int) value; + case FieldType.UInt32: + case FieldType.Fixed32: + CheckInteger(value); + return (uint) value; + case FieldType.Int64: + case FieldType.SInt64: + case FieldType.SFixed64: + CheckInteger(value); + return (long) value; + case FieldType.UInt64: + case FieldType.Fixed64: + CheckInteger(value); + return (ulong) value; + case FieldType.Double: + return value; + case FieldType.Float: + if (double.IsNaN(value)) + { + return float.NaN; + } + if (value > float.MaxValue || value < float.MinValue) + { + if (double.IsPositiveInfinity(value)) + { + return float.PositiveInfinity; + } + if (double.IsNegativeInfinity(value)) + { + return float.NegativeInfinity; + } + throw new InvalidProtocolBufferException($"Value out of range: {value}"); + } + return (float) value; + case FieldType.Enum: + CheckInteger(value); + // Just return it as an int, and let the CLR convert it. + // Note that we deliberately don't check that it's a known value. + return (int) value; + default: + throw new InvalidProtocolBufferException($"Unsupported conversion from JSON number for field type {field.FieldType}"); + } + } + catch (OverflowException) + { + throw new InvalidProtocolBufferException($"Value out of range: {value}"); + } + } + } + + private static void CheckInteger(double value) + { + if (double.IsInfinity(value) || double.IsNaN(value)) + { + throw new InvalidProtocolBufferException($"Value not an integer: {value}"); + } + if (value != Math.Floor(value)) + { + throw new InvalidProtocolBufferException($"Value not an integer: {value}"); + } + } + + private static object ParseSingleStringValue(FieldDescriptor field, string text) + { + switch (field.FieldType) + { + case FieldType.String: + return text; + case FieldType.Bytes: + try + { + return ByteString.FromBase64(text); + } + catch (FormatException e) + { + throw InvalidProtocolBufferException.InvalidBase64(e); + } + case FieldType.Int32: + case FieldType.SInt32: + case FieldType.SFixed32: + return ParseNumericString(text, int.Parse); + case FieldType.UInt32: + case FieldType.Fixed32: + return ParseNumericString(text, uint.Parse); + case FieldType.Int64: + case FieldType.SInt64: + case FieldType.SFixed64: + return ParseNumericString(text, long.Parse); + case FieldType.UInt64: + case FieldType.Fixed64: + return ParseNumericString(text, ulong.Parse); + case FieldType.Double: + double d = ParseNumericString(text, double.Parse); + ValidateInfinityAndNan(text, double.IsPositiveInfinity(d), double.IsNegativeInfinity(d), double.IsNaN(d)); + return d; + case FieldType.Float: + float f = ParseNumericString(text, float.Parse); + ValidateInfinityAndNan(text, float.IsPositiveInfinity(f), float.IsNegativeInfinity(f), float.IsNaN(f)); + return f; + case FieldType.Enum: + var enumValue = field.EnumType.FindValueByName(text); + if (enumValue == null) + { + throw new InvalidProtocolBufferException($"Invalid enum value: {text} for enum type: {field.EnumType.FullName}"); + } + // Just return it as an int, and let the CLR convert it. + return enumValue.Number; + default: + throw new InvalidProtocolBufferException($"Unsupported conversion from JSON string for field type {field.FieldType}"); + } + } + + /// + /// Creates a new instance of the message type for the given field. + /// + private static IMessage NewMessageForField(FieldDescriptor field) + { + return field.MessageType.Parser.CreateTemplate(); + } + + private static T ParseNumericString(string text, Func parser) + { + // Can't prohibit this with NumberStyles. + if (text.StartsWith("+")) + { + throw new InvalidProtocolBufferException($"Invalid numeric value: {text}"); + } + if (text.StartsWith("0") && text.Length > 1) + { + if (text[1] >= '0' && text[1] <= '9') + { + throw new InvalidProtocolBufferException($"Invalid numeric value: {text}"); + } + } + else if (text.StartsWith("-0") && text.Length > 2) + { + if (text[2] >= '0' && text[2] <= '9') + { + throw new InvalidProtocolBufferException($"Invalid numeric value: {text}"); + } + } + try + { + return parser(text, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture); + } + catch (FormatException) + { + throw new InvalidProtocolBufferException($"Invalid numeric value for type: {text}"); + } + catch (OverflowException) + { + throw new InvalidProtocolBufferException($"Value out of range: {text}"); + } + } + + /// + /// Checks that any infinite/NaN values originated from the correct text. + /// This corrects the lenient whitespace handling of double.Parse/float.Parse, as well as the + /// way that Mono parses out-of-range values as infinity. + /// + private static void ValidateInfinityAndNan(string text, bool isPositiveInfinity, bool isNegativeInfinity, bool isNaN) + { + if ((isPositiveInfinity && text != "Infinity") || + (isNegativeInfinity && text != "-Infinity") || + (isNaN && text != "NaN")) + { + throw new InvalidProtocolBufferException($"Invalid numeric value: {text}"); + } + } + + private static void MergeTimestamp(IMessage message, JsonToken token) + { + if (token.Type != JsonToken.TokenType.StringValue) + { + throw new InvalidProtocolBufferException("Expected string value for Timestamp"); + } + var match = TimestampRegex.Match(token.StringValue); + if (!match.Success) + { + throw new InvalidProtocolBufferException($"Invalid Timestamp value: {token.StringValue}"); + } + var dateTime = match.Groups["datetime"].Value; + var subseconds = match.Groups["subseconds"].Value; + var offset = match.Groups["offset"].Value; + + try + { + DateTime parsed = DateTime.ParseExact( + dateTime, + "yyyy-MM-dd'T'HH:mm:ss", + CultureInfo.InvariantCulture, + DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); + // TODO: It would be nice not to have to create all these objects... easy to optimize later though. + Timestamp timestamp = Timestamp.FromDateTime(parsed); + int nanosToAdd = 0; + if (subseconds != "") + { + // This should always work, as we've got 1-9 digits. + int parsedFraction = int.Parse(subseconds.Substring(1), CultureInfo.InvariantCulture); + nanosToAdd = parsedFraction * SubsecondScalingFactors[subseconds.Length]; + } + int secondsToAdd = 0; + if (offset != "Z") + { + // This is the amount we need to *subtract* from the local time to get to UTC - hence - => +1 and vice versa. + int sign = offset[0] == '-' ? 1 : -1; + int hours = int.Parse(offset.Substring(1, 2), CultureInfo.InvariantCulture); + int minutes = int.Parse(offset.Substring(4, 2)); + int totalMinutes = hours * 60 + minutes; + if (totalMinutes > 18 * 60) + { + throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue); + } + if (totalMinutes == 0 && sign == 1) + { + // This is an offset of -00:00, which means "unknown local offset". It makes no sense for a timestamp. + throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue); + } + // We need to *subtract* the offset from local time to get UTC. + secondsToAdd = sign * totalMinutes * 60; + } + // Ensure we've got the right signs. Currently unnecessary, but easy to do. + if (secondsToAdd < 0 && nanosToAdd > 0) + { + secondsToAdd++; + nanosToAdd = nanosToAdd - Duration.NanosecondsPerSecond; + } + if (secondsToAdd != 0 || nanosToAdd != 0) + { + timestamp += new Duration { Nanos = nanosToAdd, Seconds = secondsToAdd }; + // The resulting timestamp after offset change would be out of our expected range. Currently the Timestamp message doesn't validate this + // anywhere, but we shouldn't parse it. + if (timestamp.Seconds < Timestamp.UnixSecondsAtBclMinValue || timestamp.Seconds > Timestamp.UnixSecondsAtBclMaxValue) + { + throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue); + } + } + message.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.SetValue(message, timestamp.Seconds); + message.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.SetValue(message, timestamp.Nanos); + } + catch (FormatException) + { + throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue); + } + } + + private static void MergeDuration(IMessage message, JsonToken token) + { + if (token.Type != JsonToken.TokenType.StringValue) + { + throw new InvalidProtocolBufferException("Expected string value for Duration"); + } + var match = DurationRegex.Match(token.StringValue); + if (!match.Success) + { + throw new InvalidProtocolBufferException("Invalid Duration value: " + token.StringValue); + } + var sign = match.Groups["sign"].Value; + var secondsText = match.Groups["int"].Value; + // Prohibit leading insignficant zeroes + if (secondsText[0] == '0' && secondsText.Length > 1) + { + throw new InvalidProtocolBufferException("Invalid Duration value: " + token.StringValue); + } + var subseconds = match.Groups["subseconds"].Value; + var multiplier = sign == "-" ? -1 : 1; + + try + { + long seconds = long.Parse(secondsText, CultureInfo.InvariantCulture) * multiplier; + int nanos = 0; + if (subseconds != "") + { + // This should always work, as we've got 1-9 digits. + int parsedFraction = int.Parse(subseconds.Substring(1)); + nanos = parsedFraction * SubsecondScalingFactors[subseconds.Length] * multiplier; + } + if (!Duration.IsNormalized(seconds, nanos)) + { + throw new InvalidProtocolBufferException($"Invalid Duration value: {token.StringValue}"); + } + message.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.SetValue(message, seconds); + message.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.SetValue(message, nanos); + } + catch (FormatException) + { + throw new InvalidProtocolBufferException($"Invalid Duration value: {token.StringValue}"); + } + } + + private static void MergeFieldMask(IMessage message, JsonToken token) + { + if (token.Type != JsonToken.TokenType.StringValue) + { + throw new InvalidProtocolBufferException("Expected string value for FieldMask"); + } + // TODO: Do we *want* to remove empty entries? Probably okay to treat "" as "no paths", but "foo,,bar"? + string[] jsonPaths = token.StringValue.Split(FieldMaskPathSeparators, StringSplitOptions.RemoveEmptyEntries); + IList messagePaths = (IList) message.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(message); + foreach (var path in jsonPaths) + { + messagePaths.Add(ToSnakeCase(path)); + } + } + + // Ported from src/google/protobuf/util/internal/utility.cc + private static string ToSnakeCase(string text) + { + var builder = new StringBuilder(text.Length * 2); + // Note: this is probably unnecessary now, but currently retained to be as close as possible to the + // C++, whilst still throwing an exception on underscores. + bool wasNotUnderscore = false; // Initialize to false for case 1 (below) + bool wasNotCap = false; + + for (int i = 0; i < text.Length; i++) + { + char c = text[i]; + if (c >= 'A' && c <= 'Z') // ascii_isupper + { + // Consider when the current character B is capitalized: + // 1) At beginning of input: "B..." => "b..." + // (e.g. "Biscuit" => "biscuit") + // 2) Following a lowercase: "...aB..." => "...a_b..." + // (e.g. "gBike" => "g_bike") + // 3) At the end of input: "...AB" => "...ab" + // (e.g. "GoogleLAB" => "google_lab") + // 4) Followed by a lowercase: "...ABc..." => "...a_bc..." + // (e.g. "GBike" => "g_bike") + if (wasNotUnderscore && // case 1 out + (wasNotCap || // case 2 in, case 3 out + (i + 1 < text.Length && // case 3 out + (text[i + 1] >= 'a' && text[i + 1] <= 'z')))) // ascii_islower(text[i + 1]) + { // case 4 in + // We add an underscore for case 2 and case 4. + builder.Append('_'); + } + // ascii_tolower, but we already know that c *is* an upper case ASCII character... + builder.Append((char) (c + 'a' - 'A')); + wasNotUnderscore = true; + wasNotCap = false; + } + else + { + builder.Append(c); + if (c == '_') + { + throw new InvalidProtocolBufferException($"Invalid field mask: {text}"); + } + wasNotUnderscore = true; + wasNotCap = true; + } + } + return builder.ToString(); + } + #endregion + + /// + /// Settings controlling JSON parsing. + /// + public sealed class Settings + { + /// + /// Default settings, as used by . This has the same default + /// recursion limit as , and an empty type registry. + /// + public static Settings Default { get; } + + // Workaround for the Mono compiler complaining about XML comments not being on + // valid language elements. + static Settings() + { + Default = new Settings(CodedInputStream.DefaultRecursionLimit); + } + + /// + /// The maximum depth of messages to parse. Note that this limit only applies to parsing + /// messages, not collections - so a message within a collection within a message only counts as + /// depth 2, not 3. + /// + public int RecursionLimit { get; } + + /// + /// The type registry used to parse messages. + /// + public TypeRegistry TypeRegistry { get; } + + /// + /// Whether the parser should ignore unknown fields (true) or throw an exception when + /// they are encountered (false). + /// + public bool IgnoreUnknownFields { get; } + + private Settings(int recursionLimit, TypeRegistry typeRegistry, bool ignoreUnknownFields) + { + RecursionLimit = recursionLimit; + TypeRegistry = ProtoPreconditions.CheckNotNull(typeRegistry, nameof(typeRegistry)); + IgnoreUnknownFields = ignoreUnknownFields; + } + + /// + /// Creates a new object with the specified recursion limit. + /// + /// The maximum depth of messages to parse + public Settings(int recursionLimit) : this(recursionLimit, TypeRegistry.Empty) + { + } + + /// + /// Creates a new object with the specified recursion limit and type registry. + /// + /// The maximum depth of messages to parse + /// The type registry used to parse messages + public Settings(int recursionLimit, TypeRegistry typeRegistry) : this(recursionLimit, typeRegistry, false) + { + } + + /// + /// Creates a new object set to either ignore unknown fields, or throw an exception + /// when unknown fields are encountered. + /// + /// true if unknown fields should be ignored when parsing; false to throw an exception. + public Settings WithIgnoreUnknownFields(bool ignoreUnknownFields) => + new Settings(RecursionLimit, TypeRegistry, ignoreUnknownFields); + + /// + /// Creates a new object based on this one, but with the specified recursion limit. + /// + /// The new recursion limit. + public Settings WithRecursionLimit(int recursionLimit) => + new Settings(recursionLimit, TypeRegistry, IgnoreUnknownFields); + + /// + /// Creates a new object based on this one, but with the specified type registry. + /// + /// The new type registry. Must not be null. + public Settings WithTypeRegistry(TypeRegistry typeRegistry) => + new Settings( + RecursionLimit, + ProtoPreconditions.CheckNotNull(typeRegistry, nameof(typeRegistry)), + IgnoreUnknownFields); + } + } +} diff --git a/Libs/Google.Protobuf/JsonToken.cs b/Libs/Google.Protobuf/JsonToken.cs new file mode 100644 index 0000000..a254ea6 --- /dev/null +++ b/Libs/Google.Protobuf/JsonToken.cs @@ -0,0 +1,166 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf +{ + internal sealed class JsonToken : IEquatable + { + // Tokens with no value can be reused. + private static readonly JsonToken _true = new JsonToken(TokenType.True); + private static readonly JsonToken _false = new JsonToken(TokenType.False); + private static readonly JsonToken _null = new JsonToken(TokenType.Null); + private static readonly JsonToken startObject = new JsonToken(TokenType.StartObject); + private static readonly JsonToken endObject = new JsonToken(TokenType.EndObject); + private static readonly JsonToken startArray = new JsonToken(TokenType.StartArray); + private static readonly JsonToken endArray = new JsonToken(TokenType.EndArray); + private static readonly JsonToken endDocument = new JsonToken(TokenType.EndDocument); + + internal static JsonToken Null { get { return _null; } } + internal static JsonToken False { get { return _false; } } + internal static JsonToken True { get { return _true; } } + internal static JsonToken StartObject{ get { return startObject; } } + internal static JsonToken EndObject { get { return endObject; } } + internal static JsonToken StartArray { get { return startArray; } } + internal static JsonToken EndArray { get { return endArray; } } + internal static JsonToken EndDocument { get { return endDocument; } } + + internal static JsonToken Name(string name) + { + return new JsonToken(TokenType.Name, stringValue: name); + } + + internal static JsonToken Value(string value) + { + return new JsonToken(TokenType.StringValue, stringValue: value); + } + + internal static JsonToken Value(double value) + { + return new JsonToken(TokenType.Number, numberValue: value); + } + + internal enum TokenType + { + Null, + False, + True, + StringValue, + Number, + Name, + StartObject, + EndObject, + StartArray, + EndArray, + EndDocument + } + + // A value is a string, number, array, object, null, true or false + // Arrays and objects have start/end + // A document consists of a value + // Objects are name/value sequences. + + private readonly TokenType type; + private readonly string stringValue; + private readonly double numberValue; + + internal TokenType Type { get { return type; } } + internal string StringValue { get { return stringValue; } } + internal double NumberValue { get { return numberValue; } } + + private JsonToken(TokenType type, string stringValue = null, double numberValue = 0) + { + this.type = type; + this.stringValue = stringValue; + this.numberValue = numberValue; + } + + public override bool Equals(object obj) + { + return Equals(obj as JsonToken); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 31 + (int) type; + hash = hash * 31 + stringValue == null ? 0 : stringValue.GetHashCode(); + hash = hash * 31 + numberValue.GetHashCode(); + return hash; + } + } + + public override string ToString() + { + switch (type) + { + case TokenType.Null: + return "null"; + case TokenType.True: + return "true"; + case TokenType.False: + return "false"; + case TokenType.Name: + return "name (" + stringValue + ")"; + case TokenType.StringValue: + return "value (" + stringValue + ")"; + case TokenType.Number: + return "number (" + numberValue + ")"; + case TokenType.StartObject: + return "start-object"; + case TokenType.EndObject: + return "end-object"; + case TokenType.StartArray: + return "start-array"; + case TokenType.EndArray: + return "end-array"; + case TokenType.EndDocument: + return "end-document"; + default: + throw new InvalidOperationException("Token is of unknown type " + type); + } + } + + public bool Equals(JsonToken other) + { + if (ReferenceEquals(other, null)) + { + return false; + } + // Note use of other.numberValue.Equals rather than ==, so that NaN compares appropriately. + return other.type == type && other.stringValue == stringValue && other.numberValue.Equals(numberValue); + } + } +} diff --git a/Libs/Google.Protobuf/JsonTokenizer.cs b/Libs/Google.Protobuf/JsonTokenizer.cs new file mode 100644 index 0000000..f36d0c7 --- /dev/null +++ b/Libs/Google.Protobuf/JsonTokenizer.cs @@ -0,0 +1,766 @@ +#region Copyright notice and license +// 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. +#endregion +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; + +namespace LC.Google.Protobuf +{ + /// + /// Simple but strict JSON tokenizer, rigidly following RFC 7159. + /// + /// + /// + /// This tokenizer is stateful, and only returns "useful" tokens - names, values etc. + /// It does not create tokens for the separator between names and values, or for the comma + /// between values. It validates the token stream as it goes - so callers can assume that the + /// tokens it produces are appropriate. For example, it would never produce "start object, end array." + /// + /// Implementation details: the base class handles single token push-back and + /// Not thread-safe. + /// + internal abstract class JsonTokenizer + { + private JsonToken bufferedToken; + + /// + /// Creates a tokenizer that reads from the given text reader. + /// + internal static JsonTokenizer FromTextReader(TextReader reader) + { + return new JsonTextTokenizer(reader); + } + + /// + /// Creates a tokenizer that first replays the given list of tokens, then continues reading + /// from another tokenizer. Note that if the returned tokenizer is "pushed back", that does not push back + /// on the continuation tokenizer, or vice versa. Care should be taken when using this method - it was + /// created for the sake of Any parsing. + /// + internal static JsonTokenizer FromReplayedTokens(IList tokens, JsonTokenizer continuation) + { + return new JsonReplayTokenizer(tokens, continuation); + } + + /// + /// Returns the depth of the stack, purely in objects (not collections). + /// Informally, this is the number of remaining unclosed '{' characters we have. + /// + internal int ObjectDepth { get; private set; } + + // TODO: Why do we allow a different token to be pushed back? It might be better to always remember the previous + // token returned, and allow a parameterless Rewind() method (which could only be called once, just like the current PushBack). + internal void PushBack(JsonToken token) + { + if (bufferedToken != null) + { + throw new InvalidOperationException("Can't push back twice"); + } + bufferedToken = token; + if (token.Type == JsonToken.TokenType.StartObject) + { + ObjectDepth--; + } + else if (token.Type == JsonToken.TokenType.EndObject) + { + ObjectDepth++; + } + } + + /// + /// Returns the next JSON token in the stream. An EndDocument token is returned to indicate the end of the stream, + /// after which point Next() should not be called again. + /// + /// This implementation provides single-token buffering, and calls if there is no buffered token. + /// The next token in the stream. This is never null. + /// This method is called after an EndDocument token has been returned + /// The input text does not comply with RFC 7159 + internal JsonToken Next() + { + JsonToken tokenToReturn; + if (bufferedToken != null) + { + tokenToReturn = bufferedToken; + bufferedToken = null; + } + else + { + tokenToReturn = NextImpl(); + } + if (tokenToReturn.Type == JsonToken.TokenType.StartObject) + { + ObjectDepth++; + } + else if (tokenToReturn.Type == JsonToken.TokenType.EndObject) + { + ObjectDepth--; + } + return tokenToReturn; + } + + /// + /// Returns the next JSON token in the stream, when requested by the base class. (The method delegates + /// to this if it doesn't have a buffered token.) + /// + /// This method is called after an EndDocument token has been returned + /// The input text does not comply with RFC 7159 + protected abstract JsonToken NextImpl(); + + /// + /// Skips the value we're about to read. This must only be called immediately after reading a property name. + /// If the value is an object or an array, the complete object/array is skipped. + /// + internal void SkipValue() + { + // We'll assume that Next() makes sure that the end objects and end arrays are all valid. + // All we care about is the total nesting depth we need to close. + int depth = 0; + + // do/while rather than while loop so that we read at least one token. + do + { + var token = Next(); + switch (token.Type) + { + case JsonToken.TokenType.EndArray: + case JsonToken.TokenType.EndObject: + depth--; + break; + case JsonToken.TokenType.StartArray: + case JsonToken.TokenType.StartObject: + depth++; + break; + } + } while (depth != 0); + } + + /// + /// Tokenizer which first exhausts a list of tokens, then consults another tokenizer. + /// + private class JsonReplayTokenizer : JsonTokenizer + { + private readonly IList tokens; + private readonly JsonTokenizer nextTokenizer; + private int nextTokenIndex; + + internal JsonReplayTokenizer(IList tokens, JsonTokenizer nextTokenizer) + { + this.tokens = tokens; + this.nextTokenizer = nextTokenizer; + } + + // FIXME: Object depth not maintained... + protected override JsonToken NextImpl() + { + if (nextTokenIndex >= tokens.Count) + { + return nextTokenizer.Next(); + } + return tokens[nextTokenIndex++]; + } + } + + /// + /// Tokenizer which does all the *real* work of parsing JSON. + /// + private sealed class JsonTextTokenizer : JsonTokenizer + { + // The set of states in which a value is valid next token. + private static readonly State ValueStates = State.ArrayStart | State.ArrayAfterComma | State.ObjectAfterColon | State.StartOfDocument; + + private readonly Stack containerStack = new Stack(); + private readonly PushBackReader reader; + private State state; + + internal JsonTextTokenizer(TextReader reader) + { + this.reader = new PushBackReader(reader); + state = State.StartOfDocument; + containerStack.Push(ContainerType.Document); + } + + /// + /// This method essentially just loops through characters skipping whitespace, validating and + /// changing state (e.g. from ObjectBeforeColon to ObjectAfterColon) + /// until it reaches something which will be a genuine token (e.g. a start object, or a value) at which point + /// it returns the token. Although the method is large, it would be relatively hard to break down further... most + /// of it is the large switch statement, which sometimes returns and sometimes doesn't. + /// + protected override JsonToken NextImpl() + { + if (state == State.ReaderExhausted) + { + throw new InvalidOperationException("Next() called after end of document"); + } + while (true) + { + var next = reader.Read(); + if (next == null) + { + ValidateState(State.ExpectedEndOfDocument, "Unexpected end of document in state: "); + state = State.ReaderExhausted; + return JsonToken.EndDocument; + } + switch (next.Value) + { + // Skip whitespace between tokens + case ' ': + case '\t': + case '\r': + case '\n': + break; + case ':': + ValidateState(State.ObjectBeforeColon, "Invalid state to read a colon: "); + state = State.ObjectAfterColon; + break; + case ',': + ValidateState(State.ObjectAfterProperty | State.ArrayAfterValue, "Invalid state to read a comma: "); + state = state == State.ObjectAfterProperty ? State.ObjectAfterComma : State.ArrayAfterComma; + break; + case '"': + string stringValue = ReadString(); + if ((state & (State.ObjectStart | State.ObjectAfterComma)) != 0) + { + state = State.ObjectBeforeColon; + return JsonToken.Name(stringValue); + } + else + { + ValidateAndModifyStateForValue("Invalid state to read a double quote: "); + return JsonToken.Value(stringValue); + } + case '{': + ValidateState(ValueStates, "Invalid state to read an open brace: "); + state = State.ObjectStart; + containerStack.Push(ContainerType.Object); + return JsonToken.StartObject; + case '}': + ValidateState(State.ObjectAfterProperty | State.ObjectStart, "Invalid state to read a close brace: "); + PopContainer(); + return JsonToken.EndObject; + case '[': + ValidateState(ValueStates, "Invalid state to read an open square bracket: "); + state = State.ArrayStart; + containerStack.Push(ContainerType.Array); + return JsonToken.StartArray; + case ']': + ValidateState(State.ArrayAfterValue | State.ArrayStart, "Invalid state to read a close square bracket: "); + PopContainer(); + return JsonToken.EndArray; + case 'n': // Start of null + ConsumeLiteral("null"); + ValidateAndModifyStateForValue("Invalid state to read a null literal: "); + return JsonToken.Null; + case 't': // Start of true + ConsumeLiteral("true"); + ValidateAndModifyStateForValue("Invalid state to read a true literal: "); + return JsonToken.True; + case 'f': // Start of false + ConsumeLiteral("false"); + ValidateAndModifyStateForValue("Invalid state to read a false literal: "); + return JsonToken.False; + case '-': // Start of a number + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + double number = ReadNumber(next.Value); + ValidateAndModifyStateForValue("Invalid state to read a number token: "); + return JsonToken.Value(number); + default: + throw new InvalidJsonException("Invalid first character of token: " + next.Value); + } + } + } + + private void ValidateState(State validStates, string errorPrefix) + { + if ((validStates & state) == 0) + { + throw reader.CreateException(errorPrefix + state); + } + } + + /// + /// Reads a string token. It is assumed that the opening " has already been read. + /// + private string ReadString() + { + var value = new StringBuilder(); + bool haveHighSurrogate = false; + while (true) + { + char c = reader.ReadOrFail("Unexpected end of text while reading string"); + if (c < ' ') + { + throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in string literal: U+{0:x4}", (int) c)); + } + if (c == '"') + { + if (haveHighSurrogate) + { + throw reader.CreateException("Invalid use of surrogate pair code units"); + } + return value.ToString(); + } + if (c == '\\') + { + c = ReadEscapedCharacter(); + } + // TODO: Consider only allowing surrogate pairs that are either both escaped, + // or both not escaped. It would be a very odd text stream that contained a "lone" high surrogate + // followed by an escaped low surrogate or vice versa... and that couldn't even be represented in UTF-8. + if (haveHighSurrogate != char.IsLowSurrogate(c)) + { + throw reader.CreateException("Invalid use of surrogate pair code units"); + } + haveHighSurrogate = char.IsHighSurrogate(c); + value.Append(c); + } + } + + /// + /// Reads an escaped character. It is assumed that the leading backslash has already been read. + /// + private char ReadEscapedCharacter() + { + char c = reader.ReadOrFail("Unexpected end of text while reading character escape sequence"); + switch (c) + { + case 'n': + return '\n'; + case '\\': + return '\\'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'r': + return '\r'; + case 't': + return '\t'; + case '"': + return '"'; + case '/': + return '/'; + case 'u': + return ReadUnicodeEscape(); + default: + throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in character escape sequence: U+{0:x4}", (int) c)); + } + } + + /// + /// Reads an escaped Unicode 4-nybble hex sequence. It is assumed that the leading \u has already been read. + /// + private char ReadUnicodeEscape() + { + int result = 0; + for (int i = 0; i < 4; i++) + { + char c = reader.ReadOrFail("Unexpected end of text while reading Unicode escape sequence"); + int nybble; + if (c >= '0' && c <= '9') + { + nybble = c - '0'; + } + else if (c >= 'a' && c <= 'f') + { + nybble = c - 'a' + 10; + } + else if (c >= 'A' && c <= 'F') + { + nybble = c - 'A' + 10; + } + else + { + throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in character escape sequence: U+{0:x4}", (int) c)); + } + result = (result << 4) + nybble; + } + return (char) result; + } + + /// + /// Consumes a text-only literal, throwing an exception if the read text doesn't match it. + /// It is assumed that the first letter of the literal has already been read. + /// + private void ConsumeLiteral(string text) + { + for (int i = 1; i < text.Length; i++) + { + char? next = reader.Read(); + if (next == null) + { + throw reader.CreateException("Unexpected end of text while reading literal token " + text); + } + if (next.Value != text[i]) + { + throw reader.CreateException("Unexpected character while reading literal token " + text); + } + } + } + + private double ReadNumber(char initialCharacter) + { + StringBuilder builder = new StringBuilder(); + if (initialCharacter == '-') + { + builder.Append("-"); + } + else + { + reader.PushBack(initialCharacter); + } + // Each method returns the character it read that doesn't belong in that part, + // so we know what to do next, including pushing the character back at the end. + // null is returned for "end of text". + char? next = ReadInt(builder); + if (next == '.') + { + next = ReadFrac(builder); + } + if (next == 'e' || next == 'E') + { + next = ReadExp(builder); + } + // If we read a character which wasn't part of the number, push it back so we can read it again + // to parse the next token. + if (next != null) + { + reader.PushBack(next.Value); + } + + // TODO: What exception should we throw if the value can't be represented as a double? + try + { + return double.Parse(builder.ToString(), + NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, + CultureInfo.InvariantCulture); + } + catch (OverflowException) + { + throw reader.CreateException("Numeric value out of range: " + builder); + } + } + + private char? ReadInt(StringBuilder builder) + { + char first = reader.ReadOrFail("Invalid numeric literal"); + if (first < '0' || first > '9') + { + throw reader.CreateException("Invalid numeric literal"); + } + builder.Append(first); + int digitCount; + char? next = ConsumeDigits(builder, out digitCount); + if (first == '0' && digitCount != 0) + { + throw reader.CreateException("Invalid numeric literal: leading 0 for non-zero value."); + } + return next; + } + + private char? ReadFrac(StringBuilder builder) + { + builder.Append('.'); // Already consumed this + int digitCount; + char? next = ConsumeDigits(builder, out digitCount); + if (digitCount == 0) + { + throw reader.CreateException("Invalid numeric literal: fraction with no trailing digits"); + } + return next; + } + + private char? ReadExp(StringBuilder builder) + { + builder.Append('E'); // Already consumed this (or 'e') + char? next = reader.Read(); + if (next == null) + { + throw reader.CreateException("Invalid numeric literal: exponent with no trailing digits"); + } + if (next == '-' || next == '+') + { + builder.Append(next.Value); + } + else + { + reader.PushBack(next.Value); + } + int digitCount; + next = ConsumeDigits(builder, out digitCount); + if (digitCount == 0) + { + throw reader.CreateException("Invalid numeric literal: exponent without value"); + } + return next; + } + + private char? ConsumeDigits(StringBuilder builder, out int count) + { + count = 0; + while (true) + { + char? next = reader.Read(); + if (next == null || next.Value < '0' || next.Value > '9') + { + return next; + } + count++; + builder.Append(next.Value); + } + } + + /// + /// Validates that we're in a valid state to read a value (using the given error prefix if necessary) + /// and changes the state to the appropriate one, e.g. ObjectAfterColon to ObjectAfterProperty. + /// + private void ValidateAndModifyStateForValue(string errorPrefix) + { + ValidateState(ValueStates, errorPrefix); + switch (state) + { + case State.StartOfDocument: + state = State.ExpectedEndOfDocument; + return; + case State.ObjectAfterColon: + state = State.ObjectAfterProperty; + return; + case State.ArrayStart: + case State.ArrayAfterComma: + state = State.ArrayAfterValue; + return; + default: + throw new InvalidOperationException("ValidateAndModifyStateForValue does not handle all value states (and should)"); + } + } + + /// + /// Pops the top-most container, and sets the state to the appropriate one for the end of a value + /// in the parent container. + /// + private void PopContainer() + { + containerStack.Pop(); + var parent = containerStack.Peek(); + switch (parent) + { + case ContainerType.Object: + state = State.ObjectAfterProperty; + break; + case ContainerType.Array: + state = State.ArrayAfterValue; + break; + case ContainerType.Document: + state = State.ExpectedEndOfDocument; + break; + default: + throw new InvalidOperationException("Unexpected container type: " + parent); + } + } + + private enum ContainerType + { + Document, Object, Array + } + + /// + /// Possible states of the tokenizer. + /// + /// + /// This is a flags enum purely so we can simply and efficiently represent a set of valid states + /// for checking. + /// + /// Each is documented with an example, + /// where ^ represents the current position within the text stream. The examples all use string values, + /// but could be any value, including nested objects/arrays. + /// The complete state of the tokenizer also includes a stack to indicate the contexts (arrays/objects). + /// Any additional notional state of "AfterValue" indicates that a value has been completed, at which + /// point there's an immediate transition to ExpectedEndOfDocument, ObjectAfterProperty or ArrayAfterValue. + /// + /// + /// These states were derived manually by reading RFC 7159 carefully. + /// + /// + [Flags] + private enum State + { + /// + /// ^ { "foo": "bar" } + /// Before the value in a document. Next states: ObjectStart, ArrayStart, "AfterValue" + /// + StartOfDocument = 1 << 0, + /// + /// { "foo": "bar" } ^ + /// After the value in a document. Next states: ReaderExhausted + /// + ExpectedEndOfDocument = 1 << 1, + /// + /// { "foo": "bar" } ^ (and already read to the end of the reader) + /// Terminal state. + /// + ReaderExhausted = 1 << 2, + /// + /// { ^ "foo": "bar" } + /// Before the *first* property in an object. + /// Next states: + /// "AfterValue" (empty object) + /// ObjectBeforeColon (read a name) + /// + ObjectStart = 1 << 3, + /// + /// { "foo" ^ : "bar", "x": "y" } + /// Next state: ObjectAfterColon + /// + ObjectBeforeColon = 1 << 4, + /// + /// { "foo" : ^ "bar", "x": "y" } + /// Before any property other than the first in an object. + /// (Equivalently: after any property in an object) + /// Next states: + /// "AfterValue" (value is simple) + /// ObjectStart (value is object) + /// ArrayStart (value is array) + /// + ObjectAfterColon = 1 << 5, + /// + /// { "foo" : "bar" ^ , "x" : "y" } + /// At the end of a property, so expecting either a comma or end-of-object + /// Next states: ObjectAfterComma or "AfterValue" + /// + ObjectAfterProperty = 1 << 6, + /// + /// { "foo":"bar", ^ "x":"y" } + /// Read the comma after the previous property, so expecting another property. + /// This is like ObjectStart, but closing brace isn't valid here + /// Next state: ObjectBeforeColon. + /// + ObjectAfterComma = 1 << 7, + /// + /// [ ^ "foo", "bar" ] + /// Before the *first* value in an array. + /// Next states: + /// "AfterValue" (read a value) + /// "AfterValue" (end of array; will pop stack) + /// + ArrayStart = 1 << 8, + /// + /// [ "foo" ^ , "bar" ] + /// After any value in an array, so expecting either a comma or end-of-array + /// Next states: ArrayAfterComma or "AfterValue" + /// + ArrayAfterValue = 1 << 9, + /// + /// [ "foo", ^ "bar" ] + /// After a comma in an array, so there *must* be another value (simple or complex). + /// Next states: "AfterValue" (simple value), StartObject, StartArray + /// + ArrayAfterComma = 1 << 10 + } + + /// + /// Wrapper around a text reader allowing small amounts of buffering and location handling. + /// + private class PushBackReader + { + // TODO: Add locations for errors etc. + + private readonly TextReader reader; + + internal PushBackReader(TextReader reader) + { + // TODO: Wrap the reader in a BufferedReader? + this.reader = reader; + } + + /// + /// The buffered next character, if we have one. + /// + private char? nextChar; + + /// + /// Returns the next character in the stream, or null if we have reached the end. + /// + /// + internal char? Read() + { + if (nextChar != null) + { + char? tmp = nextChar; + nextChar = null; + return tmp; + } + int next = reader.Read(); + return next == -1 ? null : (char?) next; + } + + internal char ReadOrFail(string messageOnFailure) + { + char? next = Read(); + if (next == null) + { + throw CreateException(messageOnFailure); + } + return next.Value; + } + + internal void PushBack(char c) + { + if (nextChar != null) + { + throw new InvalidOperationException("Cannot push back when already buffering a character"); + } + nextChar = c; + } + + /// + /// Creates a new exception appropriate for the current state of the reader. + /// + internal InvalidJsonException CreateException(string message) + { + // TODO: Keep track of and use the location. + return new InvalidJsonException(message); + } + } + } + } +} diff --git a/Libs/Google.Protobuf/LC.Google.Protobuf.csproj b/Libs/Google.Protobuf/LC.Google.Protobuf.csproj new file mode 100644 index 0000000..b725648 --- /dev/null +++ b/Libs/Google.Protobuf/LC.Google.Protobuf.csproj @@ -0,0 +1,43 @@ + + + + C# runtime library for Protocol Buffers - Google's data interchange format. + Copyright 2015, Google Inc. + Google Protocol Buffers + 3.15.6 + + 7.2 + Google Inc. + netstandard2.0 + true + ./keys/Google.Protobuf.snk + true + Protocol;Buffers;Binary;Serialization;Format;Google;proto;proto3 + C# proto3 support + https://github.com/protocolbuffers/protobuf + https://github.com/protocolbuffers/protobuf/blob/master/LICENSE + git + https://github.com/protocolbuffers/protobuf.git + True + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + 0.7.1 + LC.Google.Protobuf + + + + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING + + + + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING;GOOGLE_PROTOBUF_SIMD + + + + + + + + + + diff --git a/Libs/Google.Protobuf/LimitedInputStream.cs b/Libs/Google.Protobuf/LimitedInputStream.cs new file mode 100644 index 0000000..7888c06 --- /dev/null +++ b/Libs/Google.Protobuf/LimitedInputStream.cs @@ -0,0 +1,110 @@ +#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.IO; + +namespace LC.Google.Protobuf +{ + /// + /// Stream implementation which proxies another stream, only allowing a certain amount + /// of data to be read. Note that this is only used to read delimited streams, so it + /// doesn't attempt to implement everything. + /// + internal sealed class LimitedInputStream : Stream + { + private readonly Stream proxied; + private int bytesLeft; + + internal LimitedInputStream(Stream proxied, int size) + { + this.proxied = proxied; + bytesLeft = size; + } + + public override bool CanRead + { + get { return true; } + } + + public override bool CanSeek + { + get { return false; } + } + + public override bool CanWrite + { + get { return false; } + } + + public override void Flush() + { + } + + public override long Length + { + get { throw new NotSupportedException(); } + } + + public override long Position + { + get { throw new NotSupportedException(); } + set { throw new NotSupportedException(); } + } + + public override int Read(byte[] buffer, int offset, int count) + { + if (bytesLeft > 0) + { + int bytesRead = proxied.Read(buffer, offset, Math.Min(bytesLeft, count)); + bytesLeft -= bytesRead; + return bytesRead; + } + return 0; + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotSupportedException(); + } + } +} diff --git a/Libs/Google.Protobuf/MessageExtensions.cs b/Libs/Google.Protobuf/MessageExtensions.cs new file mode 100644 index 0000000..1bbb01e --- /dev/null +++ b/Libs/Google.Protobuf/MessageExtensions.cs @@ -0,0 +1,306 @@ +#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 LC.Google.Protobuf.Reflection; +using System.Buffers; +using System.Collections; +using System; +using System.IO; +using System.Linq; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// Extension methods on and . + /// + public static class MessageExtensions + { + /// + /// Merges data from the given byte array into an existing message. + /// + /// The message to merge the data into. + /// The data to merge, which must be protobuf-encoded binary data. + public static void MergeFrom(this IMessage message, byte[] data) => + MergeFrom(message, data, false, null); + + /// + /// Merges data from the given byte array slice into an existing message. + /// + /// The message to merge the data into. + /// The data containing the slice to merge, which must be protobuf-encoded binary data. + /// The offset of the slice to merge. + /// The length of the slice to merge. + public static void MergeFrom(this IMessage message, byte[] data, int offset, int length) => + MergeFrom(message, data, offset, length, false, null); + + /// + /// Merges data from the given byte string into an existing message. + /// + /// The message to merge the data into. + /// The data to merge, which must be protobuf-encoded binary data. + public static void MergeFrom(this IMessage message, ByteString data) => + MergeFrom(message, data, false, null); + + /// + /// Merges data from the given stream into an existing message. + /// + /// The message to merge the data into. + /// Stream containing the data to merge, which must be protobuf-encoded binary data. + public static void MergeFrom(this IMessage message, Stream input) => + MergeFrom(message, input, false, null); + + /// + /// Merges length-delimited data from the given stream into an existing message. + /// + /// + /// The stream is expected to contain a length and then the data. Only the amount of data + /// specified by the length will be consumed. + /// + /// The message to merge the data into. + /// Stream containing the data to merge, which must be protobuf-encoded binary data. + public static void MergeDelimitedFrom(this IMessage message, Stream input) => + MergeDelimitedFrom(message, input, false, null); + + /// + /// Converts the given message into a byte array in protobuf encoding. + /// + /// The message to convert. + /// The message data as a byte array. + public static byte[] ToByteArray(this IMessage message) + { + ProtoPreconditions.CheckNotNull(message, "message"); + byte[] result = new byte[message.CalculateSize()]; + CodedOutputStream output = new CodedOutputStream(result); + message.WriteTo(output); + output.CheckNoSpaceLeft(); + return result; + } + + /// + /// Writes the given message data to the given stream in protobuf encoding. + /// + /// The message to write to the stream. + /// The stream to write to. + public static void WriteTo(this IMessage message, Stream output) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(output, "output"); + CodedOutputStream codedOutput = new CodedOutputStream(output); + message.WriteTo(codedOutput); + codedOutput.Flush(); + } + + /// + /// Writes the length and then data of the given message to a stream. + /// + /// The message to write. + /// The output stream to write to. + public static void WriteDelimitedTo(this IMessage message, Stream output) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(output, "output"); + CodedOutputStream codedOutput = new CodedOutputStream(output); + codedOutput.WriteLength(message.CalculateSize()); + message.WriteTo(codedOutput); + codedOutput.Flush(); + } + + /// + /// Converts the given message into a byte string in protobuf encoding. + /// + /// The message to convert. + /// The message data as a byte string. + public static ByteString ToByteString(this IMessage message) + { + ProtoPreconditions.CheckNotNull(message, "message"); + return ByteString.AttachBytes(message.ToByteArray()); + } + + /// + /// Writes the given message data to the given buffer writer in protobuf encoding. + /// + /// The message to write to the stream. + /// The stream to write to. + [SecuritySafeCritical] + public static void WriteTo(this IMessage message, IBufferWriter output) + { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + ProtoPreconditions.CheckNotNull(output, nameof(output)); + + WriteContext.Initialize(output, out WriteContext ctx); + WritingPrimitivesMessages.WriteRawMessage(ref ctx, message); + ctx.Flush(); + } + + /// + /// Writes the given message data to the given span in protobuf encoding. + /// The size of the destination span needs to fit the serialized size + /// of the message exactly, otherwise an exception is thrown. + /// + /// The message to write to the stream. + /// The span to write to. Size must match size of the message exactly. + [SecuritySafeCritical] + public static void WriteTo(this IMessage message, Span output) + { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + + WriteContext.Initialize(ref output, out WriteContext ctx); + WritingPrimitivesMessages.WriteRawMessage(ref ctx, message); + ctx.CheckNoSpaceLeft(); + } + + /// + /// Checks if all required fields in a message have values set. For proto3 messages, this returns true + /// + public static bool IsInitialized(this IMessage message) + { + if (message.Descriptor.File.Syntax == Syntax.Proto3) + { + return true; + } + + if (!message.Descriptor.IsExtensionsInitialized(message)) + { + return false; + } + + return message.Descriptor + .Fields + .InDeclarationOrder() + .All(f => + { + if (f.IsMap) + { + var valueField = f.MessageType.Fields[2]; + if (valueField.FieldType == FieldType.Message) + { + var map = (IDictionary)f.Accessor.GetValue(message); + return map.Values.Cast().All(IsInitialized); + } + else + { + return true; + } + } + else if (f.IsRepeated && f.FieldType == FieldType.Message || f.FieldType == FieldType.Group) + { + var enumerable = (IEnumerable)f.Accessor.GetValue(message); + return enumerable.Cast().All(IsInitialized); + } + else if (f.FieldType == FieldType.Message || f.FieldType == FieldType.Group) + { + if (f.Accessor.HasValue(message)) + { + return ((IMessage)f.Accessor.GetValue(message)).IsInitialized(); + } + else + { + return !f.IsRequired; + } + } + else if (f.IsRequired) + { + return f.Accessor.HasValue(message); + } + else + { + return true; + } + }); + } + + // Implementations allowing unknown fields to be discarded. + internal static void MergeFrom(this IMessage message, byte[] data, bool discardUnknownFields, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); + CodedInputStream input = new CodedInputStream(data); + input.DiscardUnknownFields = discardUnknownFields; + input.ExtensionRegistry = registry; + message.MergeFrom(input); + input.CheckReadEndOfStreamTag(); + } + + internal static void MergeFrom(this IMessage message, byte[] data, int offset, int length, bool discardUnknownFields, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); + CodedInputStream input = new CodedInputStream(data, offset, length); + input.DiscardUnknownFields = discardUnknownFields; + input.ExtensionRegistry = registry; + message.MergeFrom(input); + input.CheckReadEndOfStreamTag(); + } + + internal static void MergeFrom(this IMessage message, ByteString data, bool discardUnknownFields, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); + CodedInputStream input = data.CreateCodedInput(); + input.DiscardUnknownFields = discardUnknownFields; + input.ExtensionRegistry = registry; + message.MergeFrom(input); + input.CheckReadEndOfStreamTag(); + } + + internal static void MergeFrom(this IMessage message, Stream input, bool discardUnknownFields, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(input, "input"); + CodedInputStream codedInput = new CodedInputStream(input); + codedInput.DiscardUnknownFields = discardUnknownFields; + codedInput.ExtensionRegistry = registry; + message.MergeFrom(codedInput); + codedInput.CheckReadEndOfStreamTag(); + } + + [SecuritySafeCritical] + internal static void MergeFrom(this IMessage message, ReadOnlySequence data, bool discardUnknownFields, ExtensionRegistry registry) + { + ParseContext.Initialize(data, out ParseContext ctx); + ctx.DiscardUnknownFields = discardUnknownFields; + ctx.ExtensionRegistry = registry; + ParsingPrimitivesMessages.ReadRawMessage(ref ctx, message); + ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref ctx.state); + } + + internal static void MergeDelimitedFrom(this IMessage message, Stream input, bool discardUnknownFields, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(input, "input"); + int size = (int) CodedInputStream.ReadRawVarint32(input); + Stream limitedStream = new LimitedInputStream(input, size); + MergeFrom(message, limitedStream, discardUnknownFields, registry); + } + } +} diff --git a/Libs/Google.Protobuf/MessageParser.cs b/Libs/Google.Protobuf/MessageParser.cs new file mode 100644 index 0000000..90cf5ad --- /dev/null +++ b/Libs/Google.Protobuf/MessageParser.cs @@ -0,0 +1,376 @@ +#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.Buffers; +using System.IO; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// A general message parser, typically used by reflection-based code as all the methods + /// return simple . + /// + public class MessageParser + { + private Func factory; + // TODO: When we use a C# 7.1 compiler, make this private protected. + internal bool DiscardUnknownFields { get; } + + internal ExtensionRegistry Extensions { get; } + + internal MessageParser(Func factory, bool discardUnknownFields, ExtensionRegistry extensions) + { + this.factory = factory; + DiscardUnknownFields = discardUnknownFields; + Extensions = extensions; + } + + /// + /// Creates a template instance ready for population. + /// + /// An empty message. + internal IMessage CreateTemplate() + { + return factory(); + } + + /// + /// Parses a message from a byte array. + /// + /// The byte array containing the message. Must not be null. + /// The newly parsed message. + public IMessage ParseFrom(byte[] data) + { + IMessage message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from a byte array slice. + /// + /// The byte array containing the message. Must not be null. + /// The offset of the slice to parse. + /// The length of the slice to parse. + /// The newly parsed message. + public IMessage ParseFrom(byte[] data, int offset, int length) + { + IMessage message = factory(); + message.MergeFrom(data, offset, length, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given byte string. + /// + /// The data to parse. + /// The parsed message. + public IMessage ParseFrom(ByteString data) + { + IMessage message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given stream. + /// + /// The stream to parse. + /// The parsed message. + public IMessage ParseFrom(Stream input) + { + IMessage message = factory(); + message.MergeFrom(input, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given sequence. + /// + /// The data to parse. + /// The parsed message. + [SecuritySafeCritical] + public IMessage ParseFrom(ReadOnlySequence data) + { + IMessage message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a length-delimited message from the given stream. + /// + /// + /// The stream is expected to contain a length and then the data. Only the amount of data + /// specified by the length will be consumed. + /// + /// The stream to parse. + /// The parsed message. + public IMessage ParseDelimitedFrom(Stream input) + { + IMessage message = factory(); + message.MergeDelimitedFrom(input, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given coded input stream. + /// + /// The stream to parse. + /// The parsed message. + public IMessage ParseFrom(CodedInputStream input) + { + IMessage message = factory(); + MergeFrom(message, input); + return message; + } + + /// + /// Parses a message from the given JSON. + /// + /// The JSON to parse. + /// The parsed message. + /// The JSON does not comply with RFC 7159 + /// The JSON does not represent a Protocol Buffers message correctly + public IMessage ParseJson(string json) + { + IMessage message = factory(); + JsonParser.Default.Merge(message, json); + return message; + } + + // TODO: When we're using a C# 7.1 compiler, make this private protected. + internal void MergeFrom(IMessage message, CodedInputStream codedInput) + { + bool originalDiscard = codedInput.DiscardUnknownFields; + try + { + codedInput.DiscardUnknownFields = DiscardUnknownFields; + message.MergeFrom(codedInput); + } + finally + { + codedInput.DiscardUnknownFields = originalDiscard; + } + } + + /// + /// Creates a new message parser which optionally discards unknown fields when parsing. + /// + /// Whether or not to discard unknown fields when parsing. + /// A newly configured message parser. + public MessageParser WithDiscardUnknownFields(bool discardUnknownFields) => + new MessageParser(factory, discardUnknownFields, Extensions); + + /// + /// Creates a new message parser which registers extensions from the specified registry upon creating the message instance + /// + /// The extensions to register + /// A newly configured message parser. + public MessageParser WithExtensionRegistry(ExtensionRegistry registry) => + new MessageParser(factory, DiscardUnknownFields, registry); + } + + /// + /// A parser for a specific message type. + /// + /// + ///

+ /// This delegates most behavior to the + /// implementation within the original type, but + /// provides convenient overloads to parse from a variety of sources. + ///

+ ///

+ /// Most applications will never need to create their own instances of this type; + /// instead, use the static Parser property of a generated message type to obtain a + /// parser for that type. + ///

+ ///
+ /// The type of message to be parsed. + public sealed class MessageParser : MessageParser where T : IMessage + { + // Implementation note: all the methods here *could* just delegate up to the base class and cast the result. + // The current implementation avoids a virtual method call and a cast, which *may* be significant in some cases. + // Benchmarking work is required to measure the significance - but it's only a few lines of code in any case. + // The API wouldn't change anyway - just the implementation - so this work can be deferred. + private readonly Func factory; + + /// + /// Creates a new parser. + /// + /// + /// The factory method is effectively an optimization over using a generic constraint + /// to require a parameterless constructor: delegates are significantly faster to execute. + /// + /// Function to invoke when a new, empty message is required. + public MessageParser(Func factory) : this(factory, false, null) + { + } + + internal MessageParser(Func factory, bool discardUnknownFields, ExtensionRegistry extensions) : base(() => factory(), discardUnknownFields, extensions) + { + this.factory = factory; + } + + /// + /// Creates a template instance ready for population. + /// + /// An empty message. + internal new T CreateTemplate() + { + return factory(); + } + + /// + /// Parses a message from a byte array. + /// + /// The byte array containing the message. Must not be null. + /// The newly parsed message. + public new T ParseFrom(byte[] data) + { + T message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from a byte array slice. + /// + /// The byte array containing the message. Must not be null. + /// The offset of the slice to parse. + /// The length of the slice to parse. + /// The newly parsed message. + public new T ParseFrom(byte[] data, int offset, int length) + { + T message = factory(); + message.MergeFrom(data, offset, length, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given byte string. + /// + /// The data to parse. + /// The parsed message. + public new T ParseFrom(ByteString data) + { + T message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given stream. + /// + /// The stream to parse. + /// The parsed message. + public new T ParseFrom(Stream input) + { + T message = factory(); + message.MergeFrom(input, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given sequence. + /// + /// The data to parse. + /// The parsed message. + [SecuritySafeCritical] + public new T ParseFrom(ReadOnlySequence data) + { + T message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a length-delimited message from the given stream. + /// + /// + /// The stream is expected to contain a length and then the data. Only the amount of data + /// specified by the length will be consumed. + /// + /// The stream to parse. + /// The parsed message. + public new T ParseDelimitedFrom(Stream input) + { + T message = factory(); + message.MergeDelimitedFrom(input, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given coded input stream. + /// + /// The stream to parse. + /// The parsed message. + public new T ParseFrom(CodedInputStream input) + { + T message = factory(); + MergeFrom(message, input); + return message; + } + + /// + /// Parses a message from the given JSON. + /// + /// The JSON to parse. + /// The parsed message. + /// The JSON does not comply with RFC 7159 + /// The JSON does not represent a Protocol Buffers message correctly + public new T ParseJson(string json) + { + T message = factory(); + JsonParser.Default.Merge(message, json); + return message; + } + + /// + /// Creates a new message parser which optionally discards unknown fields when parsing. + /// + /// Whether or not to discard unknown fields when parsing. + /// A newly configured message parser. + public new MessageParser WithDiscardUnknownFields(bool discardUnknownFields) => + new MessageParser(factory, discardUnknownFields, Extensions); + + /// + /// Creates a new message parser which registers extensions from the specified registry upon creating the message instance + /// + /// The extensions to register + /// A newly configured message parser. + public new MessageParser WithExtensionRegistry(ExtensionRegistry registry) => + new MessageParser(factory, DiscardUnknownFields, registry); + } +} diff --git a/Libs/Google.Protobuf/ObjectIntPair.cs b/Libs/Google.Protobuf/ObjectIntPair.cs new file mode 100644 index 0000000..d834228 --- /dev/null +++ b/Libs/Google.Protobuf/ObjectIntPair.cs @@ -0,0 +1,40 @@ +using System; + +namespace LC.Google.Protobuf +{ + /// + /// Struct used to hold the keys for the fieldByNumber table in DescriptorPool and the keys for the + /// extensionByNumber table in ExtensionRegistry. + /// + internal struct ObjectIntPair : IEquatable> where T : class + { + private readonly int number; + private readonly T obj; + + internal ObjectIntPair(T obj, int number) + { + this.number = number; + this.obj = obj; + } + + public bool Equals(ObjectIntPair other) + { + return obj == other.obj + && number == other.number; + } + + public override bool Equals(object obj) + { + if (obj is ObjectIntPair) + { + return Equals((ObjectIntPair)obj); + } + return false; + } + + public override int GetHashCode() + { + return obj.GetHashCode() * ((1 << 16) - 1) + number; + } + } +} diff --git a/Libs/Google.Protobuf/ParseContext.cs b/Libs/Google.Protobuf/ParseContext.cs new file mode 100644 index 0000000..e2f368f --- /dev/null +++ b/Libs/Google.Protobuf/ParseContext.cs @@ -0,0 +1,329 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + /// + /// An opaque struct that represents the current parsing state and is passed along + /// as the parsing proceeds. + /// All the public methods are intended to be invoked only by the generated code, + /// users should never invoke them directly. + /// + [SecuritySafeCritical] + public ref struct ParseContext + { + internal const int DefaultRecursionLimit = 100; + internal const int DefaultSizeLimit = Int32.MaxValue; + + internal ReadOnlySpan buffer; + internal ParserInternalState state; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void Initialize(ref ReadOnlySpan buffer, ref ParserInternalState state, out ParseContext ctx) + { + ctx.buffer = buffer; + ctx.state = state; + } + + /// + /// Creates a ParseContext instance from CodedInputStream. + /// WARNING: internally this copies the CodedInputStream's state, so after done with the ParseContext, + /// the CodedInputStream's state needs to be updated. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void Initialize(CodedInputStream input, out ParseContext ctx) + { + ctx.buffer = new ReadOnlySpan(input.InternalBuffer); + // ideally we would use a reference to the original state, but that doesn't seem possible + // so we just copy the struct that holds the state. We will need to later store the state back + // into CodedInputStream if we want to keep it usable. + ctx.state = input.InternalState; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void Initialize(ReadOnlySequence input, out ParseContext ctx) + { + Initialize(input, DefaultRecursionLimit, out ctx); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void Initialize(ReadOnlySequence input, int recursionLimit, out ParseContext ctx) + { + ctx.buffer = default; + ctx.state = default; + ctx.state.lastTag = 0; + ctx.state.recursionDepth = 0; + ctx.state.sizeLimit = DefaultSizeLimit; + ctx.state.recursionLimit = recursionLimit; + ctx.state.currentLimit = int.MaxValue; + SegmentedBufferHelper.Initialize(input, out ctx.state.segmentedBufferHelper, out ctx.buffer); + ctx.state.bufferPos = 0; + ctx.state.bufferSize = ctx.buffer.Length; + + ctx.state.DiscardUnknownFields = false; + ctx.state.ExtensionRegistry = null; + } + + /// + /// Returns the last tag read, or 0 if no tags have been read or we've read beyond + /// the end of the input. + /// + internal uint LastTag { get { return state.lastTag; } } + + /// + /// Internal-only property; when set to true, unknown fields will be discarded while parsing. + /// + internal bool DiscardUnknownFields { + get { return state.DiscardUnknownFields; } + set { state.DiscardUnknownFields = value; } + } + + /// + /// Internal-only property; provides extension identifiers to compatible messages while parsing. + /// + internal ExtensionRegistry ExtensionRegistry + { + get { return state.ExtensionRegistry; } + set { state.ExtensionRegistry = value; } + } + + /// + /// Reads a field tag, returning the tag of 0 for "end of input". + /// + /// + /// If this method returns 0, it doesn't necessarily mean the end of all + /// the data in this CodedInputReader; it may be the end of the logical input + /// for an embedded message, for example. + /// + /// The next field tag, or 0 for end of input. (0 is never a valid tag.) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public uint ReadTag() + { + return ParsingPrimitives.ParseTag(ref buffer, ref state); + } + + /// + /// Reads a double field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public double ReadDouble() + { + return ParsingPrimitives.ParseDouble(ref buffer, ref state); + } + + /// + /// Reads a float field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public float ReadFloat() + { + return ParsingPrimitives.ParseFloat(ref buffer, ref state); + } + + /// + /// Reads a uint64 field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ulong ReadUInt64() + { + return ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + } + + /// + /// Reads an int64 field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public long ReadInt64() + { + return (long)ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + } + + /// + /// Reads an int32 field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int ReadInt32() + { + return (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + + /// + /// Reads a fixed64 field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ulong ReadFixed64() + { + return ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + } + + /// + /// Reads a fixed32 field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public uint ReadFixed32() + { + return ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + } + + /// + /// Reads a bool field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool ReadBool() + { + return ParsingPrimitives.ParseRawVarint64(ref buffer, ref state) != 0; + } + /// + /// Reads a string field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public string ReadString() + { + return ParsingPrimitives.ReadString(ref buffer, ref state); + } + + /// + /// Reads an embedded message field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ReadMessage(IMessage message) + { + ParsingPrimitivesMessages.ReadMessage(ref this, message); + } + + /// + /// Reads an embedded group field from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ReadGroup(IMessage message) + { + ParsingPrimitivesMessages.ReadGroup(ref this, message); + } + + /// + /// Reads a bytes field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ByteString ReadBytes() + { + return ParsingPrimitives.ReadBytes(ref buffer, ref state); + } + /// + /// Reads a uint32 field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public uint ReadUInt32() + { + return ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + + /// + /// Reads an enum field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int ReadEnum() + { + // Currently just a pass-through, but it's nice to separate it logically from WriteInt32. + return (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + + /// + /// Reads an sfixed32 field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int ReadSFixed32() + { + return (int)ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + } + + /// + /// Reads an sfixed64 field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public long ReadSFixed64() + { + return (long)ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + } + + /// + /// Reads an sint32 field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int ReadSInt32() + { + return ParsingPrimitives.DecodeZigZag32(ParsingPrimitives.ParseRawVarint32(ref buffer, ref state)); + } + + /// + /// Reads an sint64 field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public long ReadSInt64() + { + return ParsingPrimitives.DecodeZigZag64(ParsingPrimitives.ParseRawVarint64(ref buffer, ref state)); + } + + /// + /// Reads a length for length-delimited data. + /// + /// + /// This is internally just reading a varint, but this method exists + /// to make the calling code clearer. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int ReadLength() + { + return (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + + internal void CopyStateTo(CodedInputStream input) + { + input.InternalState = state; + } + + internal void LoadStateFrom(CodedInputStream input) + { + state = input.InternalState; + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/ParserInternalState.cs b/Libs/Google.Protobuf/ParserInternalState.cs new file mode 100644 index 0000000..04bd26d --- /dev/null +++ b/Libs/Google.Protobuf/ParserInternalState.cs @@ -0,0 +1,115 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + + // warning: this is a mutable struct, so it needs to be only passed as a ref! + internal struct ParserInternalState + { + // NOTE: the Span representing the current buffer is kept separate so that this doesn't have to be a ref struct and so it can + // be included in CodedInputStream's internal state + + /// + /// The position within the current buffer (i.e. the next byte to read) + /// + internal int bufferPos; + + /// + /// Size of the current buffer + /// + internal int bufferSize; + + /// + /// If we are currently inside a length-delimited block, this is the number of + /// bytes in the buffer that are still available once we leave the delimited block. + /// + internal int bufferSizeAfterLimit; + + /// + /// The absolute position of the end of the current length-delimited block (including totalBytesRetired) + /// + internal int currentLimit; + + /// + /// The total number of consumed before the start of the current buffer. The + /// total bytes read up to the current position can be computed as + /// totalBytesRetired + bufferPos. + /// + internal int totalBytesRetired; + + internal int recursionDepth; // current recursion depth + + internal SegmentedBufferHelper segmentedBufferHelper; + + /// + /// The last tag we read. 0 indicates we've read to the end of the stream + /// (or haven't read anything yet). + /// + internal uint lastTag; + + /// + /// The next tag, used to store the value read by PeekTag. + /// + internal uint nextTag; + internal bool hasNextTag; + + // these fields are configuration, they should be readonly + internal int sizeLimit; + internal int recursionLimit; + + // If non-null, the top level parse method was started with given coded input stream as an argument + // which also means we can potentially fallback to calling MergeFrom(CodedInputStream cis) if needed. + internal CodedInputStream CodedInputStream => segmentedBufferHelper.CodedInputStream; + + /// + /// Internal-only property; when set to true, unknown fields will be discarded while parsing. + /// + internal bool DiscardUnknownFields { get; set; } + + /// + /// Internal-only property; provides extension identifiers to compatible messages while parsing. + /// + internal ExtensionRegistry ExtensionRegistry { get; set; } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/ParsingPrimitives.cs b/Libs/Google.Protobuf/ParsingPrimitives.cs new file mode 100644 index 0000000..e807707 --- /dev/null +++ b/Libs/Google.Protobuf/ParsingPrimitives.cs @@ -0,0 +1,815 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + /// + /// Primitives for parsing protobuf wire format. + /// + [SecuritySafeCritical] + internal static class ParsingPrimitives + { + private const int StackallocThreshold = 256; + + /// + /// Reads a length for length-delimited data. + /// + /// + /// This is internally just reading a varint, but this method exists + /// to make the calling code clearer. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ParseLength(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + return (int)ParseRawVarint32(ref buffer, ref state); + } + + /// + /// Parses the next tag. + /// If the end of logical stream was reached, an invalid tag of 0 is returned. + /// + public static uint ParseTag(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + // The "nextTag" logic is there only as an optimization for reading non-packed repeated / map + // fields and is strictly speaking not necessary. + // TODO(jtattermusch): look into simplifying the ParseTag logic. + if (state.hasNextTag) + { + state.lastTag = state.nextTag; + state.hasNextTag = false; + return state.lastTag; + } + + // Optimize for the incredibly common case of having at least two bytes left in the buffer, + // and those two bytes being enough to get the tag. This will be true for fields up to 4095. + if (state.bufferPos + 2 <= state.bufferSize) + { + int tmp = buffer[state.bufferPos++]; + if (tmp < 128) + { + state.lastTag = (uint)tmp; + } + else + { + int result = tmp & 0x7f; + if ((tmp = buffer[state.bufferPos++]) < 128) + { + result |= tmp << 7; + state.lastTag = (uint) result; + } + else + { + // Nope, rewind and go the potentially slow route. + state.bufferPos -= 2; + state.lastTag = ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + } + } + else + { + if (SegmentedBufferHelper.IsAtEnd(ref buffer, ref state)) + { + state.lastTag = 0; + return 0; + } + + state.lastTag = ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + if (WireFormat.GetTagFieldNumber(state.lastTag) == 0) + { + // If we actually read a tag with a field of 0, that's not a valid tag. + throw InvalidProtocolBufferException.InvalidTag(); + } + return state.lastTag; + } + + /// + /// Peeks at the next tag in the stream. If it matches , + /// the tag is consumed and the method returns true; otherwise, the + /// stream is left in the original position and the method returns false. + /// + public static bool MaybeConsumeTag(ref ReadOnlySpan buffer, ref ParserInternalState state, uint tag) + { + if (PeekTag(ref buffer, ref state) == tag) + { + state.hasNextTag = false; + return true; + } + return false; + } + + /// + /// Peeks at the next field tag. This is like calling , but the + /// tag is not consumed. (So a subsequent call to will return the + /// same value.) + /// + public static uint PeekTag(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + if (state.hasNextTag) + { + return state.nextTag; + } + + uint savedLast = state.lastTag; + state.nextTag = ParseTag(ref buffer, ref state); + state.hasNextTag = true; + state.lastTag = savedLast; // Undo the side effect of ReadTag + return state.nextTag; + } + + /// + /// Parses a raw varint. + /// + public static ulong ParseRawVarint64(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + if (state.bufferPos + 10 > state.bufferSize) + { + return ParseRawVarint64SlowPath(ref buffer, ref state); + } + + ulong result = buffer[state.bufferPos++]; + if (result < 128) + { + return result; + } + result &= 0x7f; + int shift = 7; + do + { + byte b = buffer[state.bufferPos++]; + result |= (ulong)(b & 0x7F) << shift; + if (b < 0x80) + { + return result; + } + shift += 7; + } + while (shift < 64); + + throw InvalidProtocolBufferException.MalformedVarint(); + } + + private static ulong ParseRawVarint64SlowPath(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int shift = 0; + ulong result = 0; + do + { + byte b = ReadRawByte(ref buffer, ref state); + result |= (ulong)(b & 0x7F) << shift; + if (b < 0x80) + { + return result; + } + shift += 7; + } + while (shift < 64); + + throw InvalidProtocolBufferException.MalformedVarint(); + } + + /// + /// Parses a raw Varint. If larger than 32 bits, discard the upper bits. + /// This method is optimised for the case where we've got lots of data in the buffer. + /// That means we can check the size just once, then just read directly from the buffer + /// without constant rechecking of the buffer length. + /// + public static uint ParseRawVarint32(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + if (state.bufferPos + 5 > state.bufferSize) + { + return ParseRawVarint32SlowPath(ref buffer, ref state); + } + + int tmp = buffer[state.bufferPos++]; + if (tmp < 128) + { + return (uint)tmp; + } + int result = tmp & 0x7f; + if ((tmp = buffer[state.bufferPos++]) < 128) + { + result |= tmp << 7; + } + else + { + result |= (tmp & 0x7f) << 7; + if ((tmp = buffer[state.bufferPos++]) < 128) + { + result |= tmp << 14; + } + else + { + result |= (tmp & 0x7f) << 14; + if ((tmp = buffer[state.bufferPos++]) < 128) + { + result |= tmp << 21; + } + else + { + result |= (tmp & 0x7f) << 21; + result |= (tmp = buffer[state.bufferPos++]) << 28; + if (tmp >= 128) + { + // Discard upper 32 bits. + // Note that this has to use ReadRawByte() as we only ensure we've + // got at least 5 bytes at the start of the method. This lets us + // use the fast path in more cases, and we rarely hit this section of code. + for (int i = 0; i < 5; i++) + { + if (ReadRawByte(ref buffer, ref state) < 128) + { + return (uint) result; + } + } + throw InvalidProtocolBufferException.MalformedVarint(); + } + } + } + } + return (uint)result; + } + + private static uint ParseRawVarint32SlowPath(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int tmp = ReadRawByte(ref buffer, ref state); + if (tmp < 128) + { + return (uint) tmp; + } + int result = tmp & 0x7f; + if ((tmp = ReadRawByte(ref buffer, ref state)) < 128) + { + result |= tmp << 7; + } + else + { + result |= (tmp & 0x7f) << 7; + if ((tmp = ReadRawByte(ref buffer, ref state)) < 128) + { + result |= tmp << 14; + } + else + { + result |= (tmp & 0x7f) << 14; + if ((tmp = ReadRawByte(ref buffer, ref state)) < 128) + { + result |= tmp << 21; + } + else + { + result |= (tmp & 0x7f) << 21; + result |= (tmp = ReadRawByte(ref buffer, ref state)) << 28; + if (tmp >= 128) + { + // Discard upper 32 bits. + for (int i = 0; i < 5; i++) + { + if (ReadRawByte(ref buffer, ref state) < 128) + { + return (uint) result; + } + } + throw InvalidProtocolBufferException.MalformedVarint(); + } + } + } + } + return (uint) result; + } + + /// + /// Parses a 32-bit little-endian integer. + /// + public static uint ParseRawLittleEndian32(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + const int uintLength = sizeof(uint); + const int ulongLength = sizeof(ulong); + if (state.bufferPos + ulongLength > state.bufferSize) + { + return ParseRawLittleEndian32SlowPath(ref buffer, ref state); + } + // ReadUInt32LittleEndian is many times slower than ReadUInt64LittleEndian (at least on some runtimes) + // so it's faster better to use ReadUInt64LittleEndian and truncate the result. + uint result = (uint) BinaryPrimitives.ReadUInt64LittleEndian(buffer.Slice(state.bufferPos, ulongLength)); + state.bufferPos += uintLength; + return result; + } + + private static uint ParseRawLittleEndian32SlowPath(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + uint b1 = ReadRawByte(ref buffer, ref state); + uint b2 = ReadRawByte(ref buffer, ref state); + uint b3 = ReadRawByte(ref buffer, ref state); + uint b4 = ReadRawByte(ref buffer, ref state); + return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24); + } + + /// + /// Parses a 64-bit little-endian integer. + /// + public static ulong ParseRawLittleEndian64(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + const int length = sizeof(ulong); + if (state.bufferPos + length > state.bufferSize) + { + return ParseRawLittleEndian64SlowPath(ref buffer, ref state); + } + ulong result = BinaryPrimitives.ReadUInt64LittleEndian(buffer.Slice(state.bufferPos, length)); + state.bufferPos += length; + return result; + } + + private static ulong ParseRawLittleEndian64SlowPath(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + ulong b1 = ReadRawByte(ref buffer, ref state); + ulong b2 = ReadRawByte(ref buffer, ref state); + ulong b3 = ReadRawByte(ref buffer, ref state); + ulong b4 = ReadRawByte(ref buffer, ref state); + ulong b5 = ReadRawByte(ref buffer, ref state); + ulong b6 = ReadRawByte(ref buffer, ref state); + ulong b7 = ReadRawByte(ref buffer, ref state); + ulong b8 = ReadRawByte(ref buffer, ref state); + return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24) + | (b5 << 32) | (b6 << 40) | (b7 << 48) | (b8 << 56); + } + + /// + /// Parses a double value. + /// + public static double ParseDouble(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + const int length = sizeof(double); + if (!BitConverter.IsLittleEndian || state.bufferPos + length > state.bufferSize) + { + return BitConverter.Int64BitsToDouble((long)ParseRawLittleEndian64(ref buffer, ref state)); + } + // ReadUnaligned uses processor architecture for endianness. + double result = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(buffer.Slice(state.bufferPos, length))); + state.bufferPos += length; + return result; + } + + /// + /// Parses a float value. + /// + public static float ParseFloat(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + const int length = sizeof(float); + if (!BitConverter.IsLittleEndian || state.bufferPos + length > state.bufferSize) + { + return ParseFloatSlow(ref buffer, ref state); + } + // ReadUnaligned uses processor architecture for endianness. + float result = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(buffer.Slice(state.bufferPos, length))); + state.bufferPos += length; + return result; + } + + private static unsafe float ParseFloatSlow(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + const int length = sizeof(float); + byte* stackBuffer = stackalloc byte[length]; + Span tempSpan = new Span(stackBuffer, length); + for (int i = 0; i < length; i++) + { + tempSpan[i] = ReadRawByte(ref buffer, ref state); + } + + // Content is little endian. Reverse if needed to match endianness of architecture. + if (!BitConverter.IsLittleEndian) + { + tempSpan.Reverse(); + } + return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(tempSpan)); + } + + /// + /// Reads a fixed size of bytes from the input. + /// + /// + /// the end of the stream or the current limit was reached + /// + public static byte[] ReadRawBytes(ref ReadOnlySpan buffer, ref ParserInternalState state, int size) + { + if (size < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + + if (size <= state.bufferSize - state.bufferPos) + { + // We have all the bytes we need already. + byte[] bytes = new byte[size]; + buffer.Slice(state.bufferPos, size).CopyTo(bytes); + state.bufferPos += size; + return bytes; + } + + return ReadRawBytesSlow(ref buffer, ref state, size); + } + + private static byte[] ReadRawBytesSlow(ref ReadOnlySpan buffer, ref ParserInternalState state, int size) + { + ValidateCurrentLimit(ref buffer, ref state, size); + + if ((!state.segmentedBufferHelper.TotalLength.HasValue && size < buffer.Length) || + IsDataAvailableInSource(ref state, size)) + { + // Reading more bytes than are in the buffer, but not an excessive number + // of bytes. We can safely allocate the resulting array ahead of time. + + byte[] bytes = new byte[size]; + ReadRawBytesIntoSpan(ref buffer, ref state, size, bytes); + return bytes; + } + else + { + // The size is very large. For security reasons, we can't allocate the + // entire byte array yet. The size comes directly from the input, so a + // maliciously-crafted message could provide a bogus very large size in + // order to trick the app into allocating a lot of memory. We avoid this + // by allocating and reading only a small chunk at a time, so that the + // malicious message must actually *be* extremely large to cause + // problems. Meanwhile, we limit the allowed size of a message elsewhere. + + List chunks = new List(); + + int pos = state.bufferSize - state.bufferPos; + byte[] firstChunk = new byte[pos]; + buffer.Slice(state.bufferPos, pos).CopyTo(firstChunk); + chunks.Add(firstChunk); + state.bufferPos = state.bufferSize; + + // Read all the rest of the bytes we need. + int sizeLeft = size - pos; + while (sizeLeft > 0) + { + state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true); + byte[] chunk = new byte[Math.Min(sizeLeft, state.bufferSize)]; + + buffer.Slice(0, chunk.Length) + .CopyTo(chunk); + state.bufferPos += chunk.Length; + sizeLeft -= chunk.Length; + chunks.Add(chunk); + } + + // OK, got everything. Now concatenate it all into one buffer. + byte[] bytes = new byte[size]; + int newPos = 0; + foreach (byte[] chunk in chunks) + { + Buffer.BlockCopy(chunk, 0, bytes, newPos, chunk.Length); + newPos += chunk.Length; + } + + // Done. + return bytes; + } + } + + /// + /// Reads and discards bytes. + /// + /// the end of the stream + /// or the current limit was reached + public static void SkipRawBytes(ref ReadOnlySpan buffer, ref ParserInternalState state, int size) + { + if (size < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + + ValidateCurrentLimit(ref buffer, ref state, size); + + if (size <= state.bufferSize - state.bufferPos) + { + // We have all the bytes we need already. + state.bufferPos += size; + } + else + { + // Skipping more bytes than are in the buffer. First skip what we have. + int pos = state.bufferSize - state.bufferPos; + state.bufferPos = state.bufferSize; + + // TODO: If our segmented buffer is backed by a Stream that is seekable, we could skip the bytes more efficiently + // by simply updating stream's Position property. This used to be supported in the past, but the support was dropped + // because it would make the segmentedBufferHelper more complex. Support can be reintroduced if needed. + state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true); + + while (size - pos > state.bufferSize) + { + pos += state.bufferSize; + state.bufferPos = state.bufferSize; + state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true); + } + + state.bufferPos = size - pos; + } + } + + /// + /// Reads a string field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string ReadString(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int length = ParsingPrimitives.ParseLength(ref buffer, ref state); + return ParsingPrimitives.ReadRawString(ref buffer, ref state, length); + } + + /// + /// Reads a bytes field value from the input. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ByteString ReadBytes(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int length = ParsingPrimitives.ParseLength(ref buffer, ref state); + return ByteString.AttachBytes(ParsingPrimitives.ReadRawBytes(ref buffer, ref state, length)); + } + + /// + /// Reads a UTF-8 string from the next "length" bytes. + /// + /// + /// the end of the stream or the current limit was reached + /// + [SecuritySafeCritical] + public static string ReadRawString(ref ReadOnlySpan buffer, ref ParserInternalState state, int length) + { + // No need to read any data for an empty string. + if (length == 0) + { + return string.Empty; + } + + if (length < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + +#if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING + if (length <= state.bufferSize - state.bufferPos) + { + // Fast path: all bytes to decode appear in the same span. + ReadOnlySpan data = buffer.Slice(state.bufferPos, length); + + string value; + unsafe + { + fixed (byte* sourceBytes = &MemoryMarshal.GetReference(data)) + { + value = WritingPrimitives.Utf8Encoding.GetString(sourceBytes, length); + } + } + + state.bufferPos += length; + return value; + } +#endif + + return ReadStringSlow(ref buffer, ref state, length); + } + + /// + /// Reads a string assuming that it is spread across multiple spans in a . + /// + private static string ReadStringSlow(ref ReadOnlySpan buffer, ref ParserInternalState state, int length) + { + ValidateCurrentLimit(ref buffer, ref state, length); + +#if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING + if (IsDataAvailable(ref state, length)) + { + // Read string data into a temporary buffer, either stackalloc'ed or from ArrayPool + // Once all data is read then call Encoding.GetString on buffer and return to pool if needed. + + byte[] byteArray = null; + Span byteSpan = length <= StackallocThreshold ? + stackalloc byte[length] : + (byteArray = ArrayPool.Shared.Rent(length)); + + try + { + unsafe + { + fixed (byte* pByteSpan = &MemoryMarshal.GetReference(byteSpan)) + { + // Compiler doesn't like that a potentially stackalloc'd Span is being used + // in a method with a "ref Span buffer" argument. If the stackalloc'd span was assigned + // to the ref argument then bad things would happen. We'll never do that so it is ok. + // Make compiler happy by passing a new span created from pointer. + var tempSpan = new Span(pByteSpan, byteSpan.Length); + ReadRawBytesIntoSpan(ref buffer, ref state, length, tempSpan); + + return WritingPrimitives.Utf8Encoding.GetString(pByteSpan, length); + } + } + } + finally + { + if (byteArray != null) + { + ArrayPool.Shared.Return(byteArray); + } + } + } +#endif + + // Slow path: Build a byte array first then copy it. + // This will be called when reading from a Stream because we don't know the length of the stream, + // or there is not enough data in the sequence. If there is not enough data then ReadRawBytes will + // throw an exception. + return WritingPrimitives.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length); + } + + /// + /// Validates that the specified size doesn't exceed the current limit. If it does then remaining bytes + /// are skipped and an error is thrown. + /// + private static void ValidateCurrentLimit(ref ReadOnlySpan buffer, ref ParserInternalState state, int size) + { + if (state.totalBytesRetired + state.bufferPos + size > state.currentLimit) + { + // Read to the end of the stream (up to the current limit) anyway. + SkipRawBytes(ref buffer, ref state, state.currentLimit - state.totalBytesRetired - state.bufferPos); + // Then fail. + throw InvalidProtocolBufferException.TruncatedMessage(); + } + } + + [SecuritySafeCritical] + private static byte ReadRawByte(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + if (state.bufferPos == state.bufferSize) + { + state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true); + } + return buffer[state.bufferPos++]; + } + + /// + /// Reads a varint from the input one byte at a time, so that it does not + /// read any bytes after the end of the varint. If you simply wrapped the + /// stream in a CodedInputStream and used ReadRawVarint32(Stream) + /// then you would probably end up reading past the end of the varint since + /// CodedInputStream buffers its input. + /// + /// + /// + public static uint ReadRawVarint32(Stream input) + { + int result = 0; + int offset = 0; + for (; offset < 32; offset += 7) + { + int b = input.ReadByte(); + if (b == -1) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + result |= (b & 0x7f) << offset; + if ((b & 0x80) == 0) + { + return (uint) result; + } + } + // Keep reading up to 64 bits. + for (; offset < 64; offset += 7) + { + int b = input.ReadByte(); + if (b == -1) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + if ((b & 0x80) == 0) + { + return (uint) result; + } + } + throw InvalidProtocolBufferException.MalformedVarint(); + } + + /// + /// Decode a 32-bit value with ZigZag encoding. + /// + /// + /// ZigZag encodes signed integers into values that can be efficiently + /// encoded with varint. (Otherwise, negative values must be + /// sign-extended to 32 bits to be varint encoded, thus always taking + /// 5 bytes on the wire.) + /// + public static int DecodeZigZag32(uint n) + { + return (int)(n >> 1) ^ -(int)(n & 1); + } + + /// + /// Decode a 64-bit value with ZigZag encoding. + /// + /// + /// ZigZag encodes signed integers into values that can be efficiently + /// encoded with varint. (Otherwise, negative values must be + /// sign-extended to 64 bits to be varint encoded, thus always taking + /// 10 bytes on the wire.) + /// + public static long DecodeZigZag64(ulong n) + { + return (long)(n >> 1) ^ -(long)(n & 1); + } + + /// + /// Checks whether there is known data available of the specified size remaining to parse. + /// When parsing from a Stream this can return false because we have no knowledge of the amount + /// of data remaining in the stream until it is read. + /// + public static bool IsDataAvailable(ref ParserInternalState state, int size) + { + // Data fits in remaining buffer + if (size <= state.bufferSize - state.bufferPos) + { + return true; + } + + return IsDataAvailableInSource(ref state, size); + } + + /// + /// Checks whether there is known data available of the specified size remaining to parse + /// in the underlying data source. + /// When parsing from a Stream this will return false because we have no knowledge of the amount + /// of data remaining in the stream until it is read. + /// + private static bool IsDataAvailableInSource(ref ParserInternalState state, int size) + { + // Data fits in remaining source data. + // Note that this will never be true when reading from a stream as the total length is unknown. + return size <= state.segmentedBufferHelper.TotalLength - state.totalBytesRetired - state.bufferPos; + } + + /// + /// Read raw bytes of the specified length into a span. The amount of data available and the current limit should + /// be checked before calling this method. + /// + private static void ReadRawBytesIntoSpan(ref ReadOnlySpan buffer, ref ParserInternalState state, int length, Span byteSpan) + { + int remainingByteLength = length; + while (remainingByteLength > 0) + { + if (state.bufferSize - state.bufferPos == 0) + { + state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true); + } + + ReadOnlySpan unreadSpan = buffer.Slice(state.bufferPos, Math.Min(remainingByteLength, state.bufferSize - state.bufferPos)); + unreadSpan.CopyTo(byteSpan.Slice(length - remainingByteLength)); + + remainingByteLength -= unreadSpan.Length; + state.bufferPos += unreadSpan.Length; + } + } + } +} diff --git a/Libs/Google.Protobuf/ParsingPrimitivesMessages.cs b/Libs/Google.Protobuf/ParsingPrimitivesMessages.cs new file mode 100644 index 0000000..b11caa1 --- /dev/null +++ b/Libs/Google.Protobuf/ParsingPrimitivesMessages.cs @@ -0,0 +1,292 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Buffers; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Security; +using LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + /// + /// Reading and skipping messages / groups + /// + [SecuritySafeCritical] + internal static class ParsingPrimitivesMessages + { + private static readonly byte[] ZeroLengthMessageStreamData = new byte[] { 0 }; + + public static void SkipLastField(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + if (state.lastTag == 0) + { + throw new InvalidOperationException("SkipLastField cannot be called at the end of a stream"); + } + switch (WireFormat.GetTagWireType(state.lastTag)) + { + case WireFormat.WireType.StartGroup: + SkipGroup(ref buffer, ref state, state.lastTag); + break; + case WireFormat.WireType.EndGroup: + throw new InvalidProtocolBufferException( + "SkipLastField called on an end-group tag, indicating that the corresponding start-group was missing"); + case WireFormat.WireType.Fixed32: + ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + break; + case WireFormat.WireType.Fixed64: + ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + break; + case WireFormat.WireType.LengthDelimited: + var length = ParsingPrimitives.ParseLength(ref buffer, ref state); + ParsingPrimitives.SkipRawBytes(ref buffer, ref state, length); + break; + case WireFormat.WireType.Varint: + ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + break; + } + } + + /// + /// Skip a group. + /// + public static void SkipGroup(ref ReadOnlySpan buffer, ref ParserInternalState state, uint startGroupTag) + { + // Note: Currently we expect this to be the way that groups are read. We could put the recursion + // depth changes into the ReadTag method instead, potentially... + state.recursionDepth++; + if (state.recursionDepth >= state.recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + uint tag; + while (true) + { + tag = ParsingPrimitives.ParseTag(ref buffer, ref state); + if (tag == 0) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + // Can't call SkipLastField for this case- that would throw. + if (WireFormat.GetTagWireType(tag) == WireFormat.WireType.EndGroup) + { + break; + } + // This recursion will allow us to handle nested groups. + SkipLastField(ref buffer, ref state); + } + int startField = WireFormat.GetTagFieldNumber(startGroupTag); + int endField = WireFormat.GetTagFieldNumber(tag); + if (startField != endField) + { + throw new InvalidProtocolBufferException( + $"Mismatched end-group tag. Started with field {startField}; ended with field {endField}"); + } + state.recursionDepth--; + } + + public static void ReadMessage(ref ParseContext ctx, IMessage message) + { + int length = ParsingPrimitives.ParseLength(ref ctx.buffer, ref ctx.state); + if (ctx.state.recursionDepth >= ctx.state.recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + int oldLimit = SegmentedBufferHelper.PushLimit(ref ctx.state, length); + ++ctx.state.recursionDepth; + + ReadRawMessage(ref ctx, message); + + CheckReadEndOfStreamTag(ref ctx.state); + // Check that we've read exactly as much data as expected. + if (!SegmentedBufferHelper.IsReachedLimit(ref ctx.state)) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + --ctx.state.recursionDepth; + SegmentedBufferHelper.PopLimit(ref ctx.state, oldLimit); + } + + public static KeyValuePair ReadMapEntry(ref ParseContext ctx, MapField.Codec codec) + { + int length = ParsingPrimitives.ParseLength(ref ctx.buffer, ref ctx.state); + if (ctx.state.recursionDepth >= ctx.state.recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + int oldLimit = SegmentedBufferHelper.PushLimit(ref ctx.state, length); + ++ctx.state.recursionDepth; + + TKey key = codec.KeyCodec.DefaultValue; + TValue value = codec.ValueCodec.DefaultValue; + + uint tag; + while ((tag = ctx.ReadTag()) != 0) + { + if (tag == codec.KeyCodec.Tag) + { + key = codec.KeyCodec.Read(ref ctx); + } + else if (tag == codec.ValueCodec.Tag) + { + value = codec.ValueCodec.Read(ref ctx); + } + else + { + SkipLastField(ref ctx.buffer, ref ctx.state); + } + } + + // Corner case: a map entry with a key but no value, where the value type is a message. + // Read it as if we'd seen input with no data (i.e. create a "default" message). + if (value == null) + { + if (ctx.state.CodedInputStream != null) + { + // the decoded message might not support parsing from ParseContext, so + // we need to allow fallback to the legacy MergeFrom(CodedInputStream) parsing. + value = codec.ValueCodec.Read(new CodedInputStream(ZeroLengthMessageStreamData)); + } + else + { + ParseContext.Initialize(new ReadOnlySequence(ZeroLengthMessageStreamData), out ParseContext zeroLengthCtx); + value = codec.ValueCodec.Read(ref zeroLengthCtx); + } + } + + CheckReadEndOfStreamTag(ref ctx.state); + // Check that we've read exactly as much data as expected. + if (!SegmentedBufferHelper.IsReachedLimit(ref ctx.state)) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + --ctx.state.recursionDepth; + SegmentedBufferHelper.PopLimit(ref ctx.state, oldLimit); + + return new KeyValuePair(key, value); + } + + public static void ReadGroup(ref ParseContext ctx, IMessage message) + { + if (ctx.state.recursionDepth >= ctx.state.recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + ++ctx.state.recursionDepth; + + uint tag = ctx.state.lastTag; + int fieldNumber = WireFormat.GetTagFieldNumber(tag); + ReadRawMessage(ref ctx, message); + CheckLastTagWas(ref ctx.state, WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup)); + + --ctx.state.recursionDepth; + } + + public static void ReadGroup(ref ParseContext ctx, int fieldNumber, UnknownFieldSet set) + { + if (ctx.state.recursionDepth >= ctx.state.recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + ++ctx.state.recursionDepth; + + set.MergeGroupFrom(ref ctx); + CheckLastTagWas(ref ctx.state, WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup)); + + --ctx.state.recursionDepth; + } + + public static void ReadRawMessage(ref ParseContext ctx, IMessage message) + { + if (message is IBufferMessage bufferMessage) + { + bufferMessage.InternalMergeFrom(ref ctx); + } + else + { + // If we reached here, it means we've ran into a nested message with older generated code + // which doesn't provide the InternalMergeFrom method that takes a ParseContext. + // With a slight performance overhead, we can still parse this message just fine, + // but we need to find the original CodedInputStream instance that initiated this + // parsing process and make sure its internal state is up to date. + // Note that this performance overhead is not very high (basically copying contents of a struct) + // and it will only be incurred in case the application mixes older and newer generated code. + // Regenerating the code from .proto files will remove this overhead because it will + // generate the InternalMergeFrom method we need. + + if (ctx.state.CodedInputStream == null) + { + // This can only happen when the parsing started without providing a CodedInputStream instance + // (e.g. ParseContext was created directly from a ReadOnlySequence). + // That also means that one of the new parsing APIs was used at the top level + // and in such case it is reasonable to require that all the nested message provide + // up-to-date generated code with ParseContext support (and fail otherwise). + throw new InvalidProtocolBufferException($"Message {message.GetType().Name} doesn't provide the generated method that enables ParseContext-based parsing. You might need to regenerate the generated protobuf code."); + } + + ctx.CopyStateTo(ctx.state.CodedInputStream); + try + { + // fallback parse using the CodedInputStream that started current parsing tree + message.MergeFrom(ctx.state.CodedInputStream); + } + finally + { + ctx.LoadStateFrom(ctx.state.CodedInputStream); + } + } + } + + /// + /// Verifies that the last call to ReadTag() returned tag 0 - in other words, + /// we've reached the end of the stream when we expected to. + /// + /// The + /// tag read was not the one specified + public static void CheckReadEndOfStreamTag(ref ParserInternalState state) + { + if (state.lastTag != 0) + { + throw InvalidProtocolBufferException.MoreDataAvailable(); + } + } + + private static void CheckLastTagWas(ref ParserInternalState state, uint expectedTag) + { + if (state.lastTag != expectedTag) { + throw InvalidProtocolBufferException.InvalidEndTag(); + } + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/ParsingPrimitivesWrappers.cs b/Libs/Google.Protobuf/ParsingPrimitivesWrappers.cs new file mode 100644 index 0000000..01e657f --- /dev/null +++ b/Libs/Google.Protobuf/ParsingPrimitivesWrappers.cs @@ -0,0 +1,355 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + /// + /// Fast parsing primitives for wrapper types + /// + [SecuritySafeCritical] + internal static class ParsingPrimitivesWrappers + { + internal static float? ReadFloatWrapperLittleEndian(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + // length:1 + tag:1 + value:4 = 6 bytes + if (state.bufferPos + 6 <= state.bufferSize) + { + // The entire wrapper message is already contained in `buffer`. + int length = buffer[state.bufferPos]; + if (length == 0) + { + state.bufferPos++; + return 0F; + } + // tag:1 + value:4 = length of 5 bytes + // field=1, type=32-bit = tag of 13 + if (length != 5 || buffer[state.bufferPos + 1] != 13) + { + return ReadFloatWrapperSlow(ref buffer, ref state); + } + state.bufferPos += 2; + return ParsingPrimitives.ParseFloat(ref buffer, ref state); + } + else + { + return ReadFloatWrapperSlow(ref buffer, ref state); + } + } + + internal static float? ReadFloatWrapperSlow(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int length = ParsingPrimitives.ParseLength(ref buffer, ref state); + if (length == 0) + { + return 0F; + } + int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; + float result = 0F; + do + { + // field=1, type=32-bit = tag of 13 + if (ParsingPrimitives.ParseTag(ref buffer, ref state) == 13) + { + result = ParsingPrimitives.ParseFloat(ref buffer, ref state); + } + else + { + ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); + } + } + while (state.totalBytesRetired + state.bufferPos < finalBufferPos); + return result; + } + + internal static double? ReadDoubleWrapperLittleEndian(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + // length:1 + tag:1 + value:8 = 10 bytes + if (state.bufferPos + 10 <= state.bufferSize) + { + // The entire wrapper message is already contained in `buffer`. + int length = buffer[state.bufferPos]; + if (length == 0) + { + state.bufferPos++; + return 0D; + } + // tag:1 + value:8 = length of 9 bytes + // field=1, type=64-bit = tag of 9 + if (length != 9 || buffer[state.bufferPos + 1] != 9) + { + return ReadDoubleWrapperSlow(ref buffer, ref state); + } + state.bufferPos += 2; + return ParsingPrimitives.ParseDouble(ref buffer, ref state); + } + else + { + return ReadDoubleWrapperSlow(ref buffer, ref state); + } + } + + internal static double? ReadDoubleWrapperSlow(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int length = ParsingPrimitives.ParseLength(ref buffer, ref state); + if (length == 0) + { + return 0D; + } + int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; + double result = 0D; + do + { + // field=1, type=64-bit = tag of 9 + if (ParsingPrimitives.ParseTag(ref buffer, ref state) == 9) + { + result = ParsingPrimitives.ParseDouble(ref buffer, ref state); + } + else + { + ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); + } + } + while (state.totalBytesRetired + state.bufferPos < finalBufferPos); + return result; + } + + internal static bool? ReadBoolWrapper(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + return ReadUInt64Wrapper(ref buffer, ref state) != 0; + } + + internal static uint? ReadUInt32Wrapper(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + // field=1, type=varint = tag of 8 + const int expectedTag = 8; + // length:1 + tag:1 + value:10(varint64-max) = 12 bytes + // Value can be 64 bits for negative integers + if (state.bufferPos + 12 <= state.bufferSize) + { + // The entire wrapper message is already contained in `buffer`. + int pos0 = state.bufferPos; + int length = buffer[state.bufferPos++]; + if (length == 0) + { + return 0; + } + // Length will always fit in a single byte. + if (length >= 128) + { + state.bufferPos = pos0; + return ReadUInt32WrapperSlow(ref buffer, ref state); + } + int finalBufferPos = state.bufferPos + length; + if (buffer[state.bufferPos++] != expectedTag) + { + state.bufferPos = pos0; + return ReadUInt32WrapperSlow(ref buffer, ref state); + } + var result = ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + // Verify this message only contained a single field. + if (state.bufferPos != finalBufferPos) + { + state.bufferPos = pos0; + return ReadUInt32WrapperSlow(ref buffer, ref state); + } + return result; + } + else + { + return ReadUInt32WrapperSlow(ref buffer, ref state); + } + } + + internal static uint? ReadUInt32WrapperSlow(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + int length = ParsingPrimitives.ParseLength(ref buffer, ref state); + if (length == 0) + { + return 0; + } + int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; + uint result = 0; + do + { + // field=1, type=varint = tag of 8 + if (ParsingPrimitives.ParseTag(ref buffer, ref state) == 8) + { + result = ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } + else + { + ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); + } + } + while (state.totalBytesRetired + state.bufferPos < finalBufferPos); + return result; + } + + internal static int? ReadInt32Wrapper(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + return (int?)ReadUInt32Wrapper(ref buffer, ref state); + } + + internal static ulong? ReadUInt64Wrapper(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + // field=1, type=varint = tag of 8 + const int expectedTag = 8; + // length:1 + tag:1 + value:10(varint64-max) = 12 bytes + if (state.bufferPos + 12 <= state.bufferSize) + { + // The entire wrapper message is already contained in `buffer`. + int pos0 = state.bufferPos; + int length = buffer[state.bufferPos++]; + if (length == 0) + { + return 0L; + } + // Length will always fit in a single byte. + if (length >= 128) + { + state.bufferPos = pos0; + return ReadUInt64WrapperSlow(ref buffer, ref state); + } + int finalBufferPos = state.bufferPos + length; + if (buffer[state.bufferPos++] != expectedTag) + { + state.bufferPos = pos0; + return ReadUInt64WrapperSlow(ref buffer, ref state); + } + var result = ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + // Verify this message only contained a single field. + if (state.bufferPos != finalBufferPos) + { + state.bufferPos = pos0; + return ReadUInt64WrapperSlow(ref buffer, ref state); + } + return result; + } + else + { + return ReadUInt64WrapperSlow(ref buffer, ref state); + } + } + + internal static ulong? ReadUInt64WrapperSlow(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + // field=1, type=varint = tag of 8 + const int expectedTag = 8; + int length = ParsingPrimitives.ParseLength(ref buffer, ref state); + if (length == 0) + { + return 0L; + } + int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; + ulong result = 0L; + do + { + if (ParsingPrimitives.ParseTag(ref buffer, ref state) == expectedTag) + { + result = ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + } + else + { + ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); + } + } + while (state.totalBytesRetired + state.bufferPos < finalBufferPos); + return result; + } + + internal static long? ReadInt64Wrapper(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + return (long?)ReadUInt64Wrapper(ref buffer, ref state); + } + + internal static float? ReadFloatWrapperLittleEndian(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadFloatWrapperLittleEndian(ref ctx.buffer, ref ctx.state); + } + + internal static float? ReadFloatWrapperSlow(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadFloatWrapperSlow(ref ctx.buffer, ref ctx.state); + } + + internal static double? ReadDoubleWrapperLittleEndian(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadDoubleWrapperLittleEndian(ref ctx.buffer, ref ctx.state); + } + + internal static double? ReadDoubleWrapperSlow(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadDoubleWrapperSlow(ref ctx.buffer, ref ctx.state); + } + + internal static bool? ReadBoolWrapper(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadBoolWrapper(ref ctx.buffer, ref ctx.state); + } + + internal static uint? ReadUInt32Wrapper(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadUInt32Wrapper(ref ctx.buffer, ref ctx.state); + } + + internal static int? ReadInt32Wrapper(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadInt32Wrapper(ref ctx.buffer, ref ctx.state); + } + + internal static ulong? ReadUInt64Wrapper(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadUInt64Wrapper(ref ctx.buffer, ref ctx.state); + } + + internal static ulong? ReadUInt64WrapperSlow(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadUInt64WrapperSlow(ref ctx.buffer, ref ctx.state); + } + + internal static long? ReadInt64Wrapper(ref ParseContext ctx) + { + return ParsingPrimitivesWrappers.ReadInt64Wrapper(ref ctx.buffer, ref ctx.state); + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Properties/AssemblyInfo.cs b/Libs/Google.Protobuf/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4328e2e --- /dev/null +++ b/Libs/Google.Protobuf/Properties/AssemblyInfo.cs @@ -0,0 +1,56 @@ +#region Copyright notice and license +// 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. +#endregion + +using System.Runtime.CompilerServices; +using System.Security; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +#if !NCRUNCH +[assembly: AllowPartiallyTrustedCallers] +#endif + +[assembly: InternalsVisibleTo("Google.Protobuf.Test, PublicKey=" + + "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" + + "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" + + "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" + + "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" + + "c5ae9cb6")] + +[assembly: InternalsVisibleTo("Google.Protobuf.Benchmarks, PublicKey=" + + "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" + + "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" + + "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" + + "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" + + "c5ae9cb6")] diff --git a/Libs/Google.Protobuf/ProtoPreconditions.cs b/Libs/Google.Protobuf/ProtoPreconditions.cs new file mode 100644 index 0000000..fb87d49 --- /dev/null +++ b/Libs/Google.Protobuf/ProtoPreconditions.cs @@ -0,0 +1,79 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf +{ + /// + /// Helper methods for throwing exceptions when preconditions are not met. + /// + /// + /// This class is used internally and by generated code; it is not particularly + /// expected to be used from application code, although nothing prevents it + /// from being used that way. + /// + public static class ProtoPreconditions + { + /// + /// Throws an ArgumentNullException if the given value is null, otherwise + /// return the value to the caller. + /// + public static T CheckNotNull(T value, string name) where T : class + { + if (value == null) + { + throw new ArgumentNullException(name); + } + return value; + } + + /// + /// Throws an ArgumentNullException if the given value is null, otherwise + /// return the value to the caller. + /// + /// + /// This is equivalent to but without the type parameter + /// constraint. In most cases, the constraint is useful to prevent you from calling CheckNotNull + /// with a value type - but it gets in the way if either you want to use it with a nullable + /// value type, or you want to use it with an unconstrained type parameter. + /// + internal static T CheckNotNullUnconstrained(T value, string name) + { + if (value == null) + { + throw new ArgumentNullException(name); + } + return value; + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/CustomOptions.cs b/Libs/Google.Protobuf/Reflection/CustomOptions.cs new file mode 100644 index 0000000..65c7958 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/CustomOptions.cs @@ -0,0 +1,304 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2017 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 LC.Google.Protobuf.Collections; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Container for a set of custom options specified within a message, field etc. + /// + /// + /// + /// This type is publicly immutable, but internally mutable. It is only populated + /// by the descriptor parsing code - by the time any user code is able to see an instance, + /// it will be fully initialized. + /// + /// + /// If an option is requested using the incorrect method, an answer may still be returned: all + /// of the numeric types are represented internally using 64-bit integers, for example. It is up to + /// the caller to ensure that they make the appropriate method call for the option they're interested in. + /// Note that enum options are simply stored as integers, so the value should be fetched using + /// and then cast appropriately. + /// + /// + /// Repeated options are currently not supported. Asking for a single value of an option + /// which was actually repeated will return the last value, except for message types where + /// all the set values are merged together. + /// + /// + public sealed class CustomOptions + { + private static readonly object[] EmptyParameters = new object[0]; + private readonly IDictionary values; + + internal CustomOptions(IDictionary values) + { + this.values = values; + } + + /// + /// Retrieves a Boolean value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetBool(int field, out bool value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a signed 32-bit integer value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetInt32(int field, out int value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a signed 64-bit integer value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetInt64(int field, out long value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves an unsigned 32-bit integer value for the specified option field, + /// assuming a fixed-length representation. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetFixed32(int field, out uint value) => TryGetUInt32(field, out value); + + /// + /// Retrieves an unsigned 64-bit integer value for the specified option field, + /// assuming a fixed-length representation. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetFixed64(int field, out ulong value) => TryGetUInt64(field, out value); + + /// + /// Retrieves a signed 32-bit integer value for the specified option field, + /// assuming a fixed-length representation. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetSFixed32(int field, out int value) => TryGetInt32(field, out value); + + /// + /// Retrieves a signed 64-bit integer value for the specified option field, + /// assuming a fixed-length representation. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetSFixed64(int field, out long value) => TryGetInt64(field, out value); + + /// + /// Retrieves a signed 32-bit integer value for the specified option field, + /// assuming a zigzag encoding. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetSInt32(int field, out int value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a signed 64-bit integer value for the specified option field, + /// assuming a zigzag encoding. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetSInt64(int field, out long value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves an unsigned 32-bit integer value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetUInt32(int field, out uint value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves an unsigned 64-bit integer value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetUInt64(int field, out ulong value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a 32-bit floating point value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetFloat(int field, out float value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a 64-bit floating point value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetDouble(int field, out double value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a string value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetString(int field, out string value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a bytes value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetBytes(int field, out ByteString value) => TryGetPrimitiveValue(field, out value); + + /// + /// Retrieves a message value for the specified option field. + /// + /// The field to fetch the value for. + /// The output variable to populate. + /// true if a suitable value for the field was found; false otherwise. + public bool TryGetMessage(int field, out T value) where T : class, IMessage, new() + { + if (values == null) + { + value = default(T); + return false; + } + + IExtensionValue extensionValue; + if (values.TryGetValue(field, out extensionValue)) + { + if (extensionValue is ExtensionValue) + { + ExtensionValue single = extensionValue as ExtensionValue; + ByteString bytes = single.GetValue().ToByteString(); + value = new T(); + value.MergeFrom(bytes); + return true; + } + else if (extensionValue is RepeatedExtensionValue) + { + RepeatedExtensionValue repeated = extensionValue as RepeatedExtensionValue; + value = repeated.GetValue() + .Select(v => v.ToByteString()) + .Aggregate(new T(), (t, b) => + { + t.MergeFrom(b); + return t; + }); + return true; + } + } + + value = null; + return false; + } + + private bool TryGetPrimitiveValue(int field, out T value) + { + if (values == null) + { + value = default(T); + return false; + } + + IExtensionValue extensionValue; + if (values.TryGetValue(field, out extensionValue)) + { + if (extensionValue is ExtensionValue) + { + ExtensionValue single = extensionValue as ExtensionValue; + value = single.GetValue(); + return true; + } + else if (extensionValue is RepeatedExtensionValue) + { + RepeatedExtensionValue repeated = extensionValue as RepeatedExtensionValue; + if (repeated.GetValue().Count != 0) + { + RepeatedField repeatedField = repeated.GetValue(); + value = repeatedField[repeatedField.Count - 1]; + return true; + } + } + else // and here we find explicit enum handling since T : Enum ! x is ExtensionValue + { + var type = extensionValue.GetType(); + if (type.GetGenericTypeDefinition() == typeof(ExtensionValue<>)) + { + var typeInfo = type.GetTypeInfo(); + var typeArgs = typeInfo.GenericTypeArguments; + if (typeArgs.Length == 1 && typeArgs[0].GetTypeInfo().IsEnum) + { + value = (T)typeInfo.GetDeclaredMethod(nameof(ExtensionValue.GetValue)).Invoke(extensionValue, EmptyParameters); + return true; + } + } + else if (type.GetGenericTypeDefinition() == typeof(RepeatedExtensionValue<>)) + { + var typeInfo = type.GetTypeInfo(); + var typeArgs = typeInfo.GenericTypeArguments; + if (typeArgs.Length == 1 && typeArgs[0].GetTypeInfo().IsEnum) + { + var values = (IList)typeInfo.GetDeclaredMethod(nameof(RepeatedExtensionValue.GetValue)).Invoke(extensionValue, EmptyParameters); + if (values.Count != 0) + { + value = (T)values[values.Count - 1]; + return true; + } + } + } + } + } + + value = default(T); + return false; + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/Descriptor.cs b/Libs/Google.Protobuf/Reflection/Descriptor.cs new file mode 100644 index 0000000..3afa27f --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/Descriptor.cs @@ -0,0 +1,10296 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/descriptor.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.Reflection { + + /// Holder for reflection information generated from google/protobuf/descriptor.proto + public static partial class DescriptorReflection { + + #region Descriptor + /// File descriptor for google/protobuf/descriptor.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static DescriptorReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "CiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bxIPZ29vZ2xlLnBy", + "b3RvYnVmIkcKEUZpbGVEZXNjcmlwdG9yU2V0EjIKBGZpbGUYASADKAsyJC5n", + "b29nbGUucHJvdG9idWYuRmlsZURlc2NyaXB0b3JQcm90byLbAwoTRmlsZURl", + "c2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEg8KB3BhY2thZ2UYAiABKAkS", + "EgoKZGVwZW5kZW5jeRgDIAMoCRIZChFwdWJsaWNfZGVwZW5kZW5jeRgKIAMo", + "BRIXCg93ZWFrX2RlcGVuZGVuY3kYCyADKAUSNgoMbWVzc2FnZV90eXBlGAQg", + "AygLMiAuZ29vZ2xlLnByb3RvYnVmLkRlc2NyaXB0b3JQcm90bxI3CgllbnVt", + "X3R5cGUYBSADKAsyJC5nb29nbGUucHJvdG9idWYuRW51bURlc2NyaXB0b3JQ", + "cm90bxI4CgdzZXJ2aWNlGAYgAygLMicuZ29vZ2xlLnByb3RvYnVmLlNlcnZp", + "Y2VEZXNjcmlwdG9yUHJvdG8SOAoJZXh0ZW5zaW9uGAcgAygLMiUuZ29vZ2xl", + "LnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3RvEi0KB29wdGlvbnMYCCAB", + "KAsyHC5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMSOQoQc291cmNlX2Nv", + "ZGVfaW5mbxgJIAEoCzIfLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5m", + "bxIOCgZzeW50YXgYDCABKAkiqQUKD0Rlc2NyaXB0b3JQcm90bxIMCgRuYW1l", + "GAEgASgJEjQKBWZpZWxkGAIgAygLMiUuZ29vZ2xlLnByb3RvYnVmLkZpZWxk", + "RGVzY3JpcHRvclByb3RvEjgKCWV4dGVuc2lvbhgGIAMoCzIlLmdvb2dsZS5w", + "cm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90bxI1CgtuZXN0ZWRfdHlwZRgD", + "IAMoCzIgLmdvb2dsZS5wcm90b2J1Zi5EZXNjcmlwdG9yUHJvdG8SNwoJZW51", + "bV90eXBlGAQgAygLMiQuZ29vZ2xlLnByb3RvYnVmLkVudW1EZXNjcmlwdG9y", + "UHJvdG8SSAoPZXh0ZW5zaW9uX3JhbmdlGAUgAygLMi8uZ29vZ2xlLnByb3Rv", + "YnVmLkRlc2NyaXB0b3JQcm90by5FeHRlbnNpb25SYW5nZRI5CgpvbmVvZl9k", + "ZWNsGAggAygLMiUuZ29vZ2xlLnByb3RvYnVmLk9uZW9mRGVzY3JpcHRvclBy", + "b3RvEjAKB29wdGlvbnMYByABKAsyHy5nb29nbGUucHJvdG9idWYuTWVzc2Fn", + "ZU9wdGlvbnMSRgoOcmVzZXJ2ZWRfcmFuZ2UYCSADKAsyLi5nb29nbGUucHJv", + "dG9idWYuRGVzY3JpcHRvclByb3RvLlJlc2VydmVkUmFuZ2USFQoNcmVzZXJ2", + "ZWRfbmFtZRgKIAMoCRplCg5FeHRlbnNpb25SYW5nZRINCgVzdGFydBgBIAEo", + "BRILCgNlbmQYAiABKAUSNwoHb3B0aW9ucxgDIAEoCzImLmdvb2dsZS5wcm90", + "b2J1Zi5FeHRlbnNpb25SYW5nZU9wdGlvbnMaKwoNUmVzZXJ2ZWRSYW5nZRIN", + "CgVzdGFydBgBIAEoBRILCgNlbmQYAiABKAUiZwoVRXh0ZW5zaW9uUmFuZ2VP", + "cHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2ds", + "ZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIi1QUK", + "FEZpZWxkRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSDgoGbnVtYmVy", + "GAMgASgFEjoKBWxhYmVsGAQgASgOMisuZ29vZ2xlLnByb3RvYnVmLkZpZWxk", + "RGVzY3JpcHRvclByb3RvLkxhYmVsEjgKBHR5cGUYBSABKA4yKi5nb29nbGUu", + "cHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJvdG8uVHlwZRIRCgl0eXBlX25h", + "bWUYBiABKAkSEAoIZXh0ZW5kZWUYAiABKAkSFQoNZGVmYXVsdF92YWx1ZRgH", + "IAEoCRITCgtvbmVvZl9pbmRleBgJIAEoBRIRCglqc29uX25hbWUYCiABKAkS", + "LgoHb3B0aW9ucxgIIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlv", + "bnMSFwoPcHJvdG8zX29wdGlvbmFsGBEgASgIIrYCCgRUeXBlEg8KC1RZUEVf", + "RE9VQkxFEAESDgoKVFlQRV9GTE9BVBACEg4KClRZUEVfSU5UNjQQAxIPCgtU", + "WVBFX1VJTlQ2NBAEEg4KClRZUEVfSU5UMzIQBRIQCgxUWVBFX0ZJWEVENjQQ", + "BhIQCgxUWVBFX0ZJWEVEMzIQBxINCglUWVBFX0JPT0wQCBIPCgtUWVBFX1NU", + "UklORxAJEg4KClRZUEVfR1JPVVAQChIQCgxUWVBFX01FU1NBR0UQCxIOCgpU", + "WVBFX0JZVEVTEAwSDwoLVFlQRV9VSU5UMzIQDRINCglUWVBFX0VOVU0QDhIR", + "Cg1UWVBFX1NGSVhFRDMyEA8SEQoNVFlQRV9TRklYRUQ2NBAQEg8KC1RZUEVf", + "U0lOVDMyEBESDwoLVFlQRV9TSU5UNjQQEiJDCgVMYWJlbBISCg5MQUJFTF9P", + "UFRJT05BTBABEhIKDkxBQkVMX1JFUVVJUkVEEAISEgoOTEFCRUxfUkVQRUFU", + "RUQQAyJUChRPbmVvZkRlc2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEi4K", + "B29wdGlvbnMYAiABKAsyHS5nb29nbGUucHJvdG9idWYuT25lb2ZPcHRpb25z", + "IqQCChNFbnVtRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSOAoFdmFs", + "dWUYAiADKAsyKS5nb29nbGUucHJvdG9idWYuRW51bVZhbHVlRGVzY3JpcHRv", + "clByb3RvEi0KB29wdGlvbnMYAyABKAsyHC5nb29nbGUucHJvdG9idWYuRW51", + "bU9wdGlvbnMSTgoOcmVzZXJ2ZWRfcmFuZ2UYBCADKAsyNi5nb29nbGUucHJv", + "dG9idWYuRW51bURlc2NyaXB0b3JQcm90by5FbnVtUmVzZXJ2ZWRSYW5nZRIV", + "Cg1yZXNlcnZlZF9uYW1lGAUgAygJGi8KEUVudW1SZXNlcnZlZFJhbmdlEg0K", + "BXN0YXJ0GAEgASgFEgsKA2VuZBgCIAEoBSJsChhFbnVtVmFsdWVEZXNjcmlw", + "dG9yUHJvdG8SDAoEbmFtZRgBIAEoCRIOCgZudW1iZXIYAiABKAUSMgoHb3B0", + "aW9ucxgDIAEoCzIhLmdvb2dsZS5wcm90b2J1Zi5FbnVtVmFsdWVPcHRpb25z", + "IpABChZTZXJ2aWNlRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSNgoG", + "bWV0aG9kGAIgAygLMiYuZ29vZ2xlLnByb3RvYnVmLk1ldGhvZERlc2NyaXB0", + "b3JQcm90bxIwCgdvcHRpb25zGAMgASgLMh8uZ29vZ2xlLnByb3RvYnVmLlNl", + "cnZpY2VPcHRpb25zIsEBChVNZXRob2REZXNjcmlwdG9yUHJvdG8SDAoEbmFt", + "ZRgBIAEoCRISCgppbnB1dF90eXBlGAIgASgJEhMKC291dHB1dF90eXBlGAMg", + "ASgJEi8KB29wdGlvbnMYBCABKAsyHi5nb29nbGUucHJvdG9idWYuTWV0aG9k", + "T3B0aW9ucxIfChBjbGllbnRfc3RyZWFtaW5nGAUgASgIOgVmYWxzZRIfChBz", + "ZXJ2ZXJfc3RyZWFtaW5nGAYgASgIOgVmYWxzZSKlBgoLRmlsZU9wdGlvbnMS", + "FAoMamF2YV9wYWNrYWdlGAEgASgJEhwKFGphdmFfb3V0ZXJfY2xhc3NuYW1l", + "GAggASgJEiIKE2phdmFfbXVsdGlwbGVfZmlsZXMYCiABKAg6BWZhbHNlEikK", + "HWphdmFfZ2VuZXJhdGVfZXF1YWxzX2FuZF9oYXNoGBQgASgIQgIYARIlChZq", + "YXZhX3N0cmluZ19jaGVja191dGY4GBsgASgIOgVmYWxzZRJGCgxvcHRpbWl6", + "ZV9mb3IYCSABKA4yKS5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMuT3B0", + "aW1pemVNb2RlOgVTUEVFRBISCgpnb19wYWNrYWdlGAsgASgJEiIKE2NjX2dl", + "bmVyaWNfc2VydmljZXMYECABKAg6BWZhbHNlEiQKFWphdmFfZ2VuZXJpY19z", + "ZXJ2aWNlcxgRIAEoCDoFZmFsc2USIgoTcHlfZ2VuZXJpY19zZXJ2aWNlcxgS", + "IAEoCDoFZmFsc2USIwoUcGhwX2dlbmVyaWNfc2VydmljZXMYKiABKAg6BWZh", + "bHNlEhkKCmRlcHJlY2F0ZWQYFyABKAg6BWZhbHNlEh4KEGNjX2VuYWJsZV9h", + "cmVuYXMYHyABKAg6BHRydWUSGQoRb2JqY19jbGFzc19wcmVmaXgYJCABKAkS", + "GAoQY3NoYXJwX25hbWVzcGFjZRglIAEoCRIUCgxzd2lmdF9wcmVmaXgYJyAB", + "KAkSGAoQcGhwX2NsYXNzX3ByZWZpeBgoIAEoCRIVCg1waHBfbmFtZXNwYWNl", + "GCkgASgJEh4KFnBocF9tZXRhZGF0YV9uYW1lc3BhY2UYLCABKAkSFAoMcnVi", + "eV9wYWNrYWdlGC0gASgJEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMo", + "CzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIjoKDE9w", + "dGltaXplTW9kZRIJCgVTUEVFRBABEg0KCUNPREVfU0laRRACEhAKDExJVEVf", + "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECcihAIKDk1lc3NhZ2VPcHRpb25z", + "EiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9ybWF0GAEgASgIOgVmYWxzZRIuCh9u", + "b19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZRIZ", + "CgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRIRCgltYXBfZW50cnkYByABKAgS", + "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAQQBUoECAUQ", + "BkoECAYQB0oECAgQCUoECAkQCiKeAwoMRmllbGRPcHRpb25zEjoKBWN0eXBl", + "GAEgASgOMiMuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToG", + "U1RSSU5HEg4KBnBhY2tlZBgCIAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29n", + "bGUucHJvdG9idWYuRmllbGRPcHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMK", + "BGxhenkYBSABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNl", + "EhMKBHdlYWsYCiABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9u", + "GOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9u", + "Ii8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElF", + "Q0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAES", + "DQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJeCgxPbmVvZk9wdGlv", + "bnMSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnBy", + "b3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoLRW51", + "bU9wdGlvbnMSEwoLYWxsb3dfYWxpYXMYAiABKAgSGQoKZGVwcmVjYXRlZBgD", + "IAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQu", + "Z29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICA", + "AkoECAUQBiJ9ChBFbnVtVmFsdWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQYASAB", + "KAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdv", + "b2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIi", + "ewoOU2VydmljZU9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2US", + "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKtAgoNTWV0aG9k", + "T3B0aW9ucxIZCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZRJfChFpZGVtcG90", + "ZW5jeV9sZXZlbBgiIAEoDjIvLmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRp", + "b25zLklkZW1wb3RlbmN5TGV2ZWw6E0lERU1QT1RFTkNZX1VOS05PV04SQwoU", + "dW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVm", + "LlVuaW50ZXJwcmV0ZWRPcHRpb24iUAoQSWRlbXBvdGVuY3lMZXZlbBIXChNJ", + "REVNUE9URU5DWV9VTktOT1dOEAASEwoPTk9fU0lERV9FRkZFQ1RTEAESDgoK", + "SURFTVBPVEVOVBACKgkI6AcQgICAgAIingIKE1VuaW50ZXJwcmV0ZWRPcHRp", + "b24SOwoEbmFtZRgCIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJl", + "dGVkT3B0aW9uLk5hbWVQYXJ0EhgKEGlkZW50aWZpZXJfdmFsdWUYAyABKAkS", + "GgoScG9zaXRpdmVfaW50X3ZhbHVlGAQgASgEEhoKEm5lZ2F0aXZlX2ludF92", + "YWx1ZRgFIAEoAxIUCgxkb3VibGVfdmFsdWUYBiABKAESFAoMc3RyaW5nX3Zh", + "bHVlGAcgASgMEhcKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCRozCghOYW1lUGFy", + "dBIRCgluYW1lX3BhcnQYASACKAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigIItUB", + "Cg5Tb3VyY2VDb2RlSW5mbxI6Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5w", + "cm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvbhqGAQoITG9jYXRpb24S", + "EAoEcGF0aBgBIAMoBUICEAESEAoEc3BhbhgCIAMoBUICEAESGAoQbGVhZGlu", + "Z19jb21tZW50cxgDIAEoCRIZChF0cmFpbGluZ19jb21tZW50cxgEIAEoCRIh", + "ChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJIqcBChFHZW5lcmF0", + "ZWRDb2RlSW5mbxJBCgphbm5vdGF0aW9uGAEgAygLMi0uZ29vZ2xlLnByb3Rv", + "YnVmLkdlbmVyYXRlZENvZGVJbmZvLkFubm90YXRpb24aTwoKQW5ub3RhdGlv", + "bhIQCgRwYXRoGAEgAygFQgIQARITCgtzb3VyY2VfZmlsZRgCIAEoCRINCgVi", + "ZWdpbhgDIAEoBRILCgNlbmQYBCABKAVCfgoTY29tLmdvb2dsZS5wcm90b2J1", + "ZkIQRGVzY3JpcHRvclByb3Rvc0gBWi1nb29nbGUuZ29sYW5nLm9yZy9wcm90", + "b2J1Zi90eXBlcy9kZXNjcmlwdG9ycGL4AQGiAgNHUEKqAhpHb29nbGUuUHJv", + "dG9idWYuUmVmbGVjdGlvbg==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.FileDescriptorSet), global::LC.Google.Protobuf.Reflection.FileDescriptorSet.Parser, new[]{ "File" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.FileDescriptorProto), global::LC.Google.Protobuf.Reflection.FileDescriptorProto.Parser, new[]{ "Name", "Package", "Dependency", "PublicDependency", "WeakDependency", "MessageType", "EnumType", "Service", "Extension", "Options", "SourceCodeInfo", "Syntax" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.DescriptorProto), global::LC.Google.Protobuf.Reflection.DescriptorProto.Parser, new[]{ "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange), global::LC.Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser, new[]{ "Start", "End", "Options" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange), global::LC.Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions), global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.FieldDescriptorProto), global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Parser, new[]{ "Name", "Number", "Label", "Type", "TypeName", "Extendee", "DefaultValue", "OneofIndex", "JsonName", "Options", "Proto3Optional" }, null, new[]{ typeof(global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type), typeof(global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.OneofDescriptorProto), global::LC.Google.Protobuf.Reflection.OneofDescriptorProto.Parser, new[]{ "Name", "Options" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.EnumDescriptorProto), global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Parser, new[]{ "Name", "Value", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange), global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.EnumValueDescriptorProto), global::LC.Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser, new[]{ "Name", "Number", "Options" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.ServiceDescriptorProto), global::LC.Google.Protobuf.Reflection.ServiceDescriptorProto.Parser, new[]{ "Name", "Method", "Options" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.MethodDescriptorProto), global::LC.Google.Protobuf.Reflection.MethodDescriptorProto.Parser, new[]{ "Name", "InputType", "OutputType", "Options", "ClientStreaming", "ServerStreaming" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.FileOptions), global::LC.Google.Protobuf.Reflection.FileOptions.Parser, new[]{ "JavaPackage", "JavaOuterClassname", "JavaMultipleFiles", "JavaGenerateEqualsAndHash", "JavaStringCheckUtf8", "OptimizeFor", "GoPackage", "CcGenericServices", "JavaGenericServices", "PyGenericServices", "PhpGenericServices", "Deprecated", "CcEnableArenas", "ObjcClassPrefix", "CsharpNamespace", "SwiftPrefix", "PhpClassPrefix", "PhpNamespace", "PhpMetadataNamespace", "RubyPackage", "UninterpretedOption" }, null, new[]{ typeof(global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.MessageOptions), global::LC.Google.Protobuf.Reflection.MessageOptions.Parser, new[]{ "MessageSetWireFormat", "NoStandardDescriptorAccessor", "Deprecated", "MapEntry", "UninterpretedOption" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.FieldOptions), global::LC.Google.Protobuf.Reflection.FieldOptions.Parser, new[]{ "Ctype", "Packed", "Jstype", "Lazy", "Deprecated", "Weak", "UninterpretedOption" }, null, new[]{ typeof(global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType), typeof(global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType) }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.OneofOptions), global::LC.Google.Protobuf.Reflection.OneofOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.EnumOptions), global::LC.Google.Protobuf.Reflection.EnumOptions.Parser, new[]{ "AllowAlias", "Deprecated", "UninterpretedOption" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.EnumValueOptions), global::LC.Google.Protobuf.Reflection.EnumValueOptions.Parser, new[]{ "Deprecated", "UninterpretedOption" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.ServiceOptions), global::LC.Google.Protobuf.Reflection.ServiceOptions.Parser, new[]{ "Deprecated", "UninterpretedOption" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.MethodOptions), global::LC.Google.Protobuf.Reflection.MethodOptions.Parser, new[]{ "Deprecated", "IdempotencyLevel", "UninterpretedOption" }, null, new[]{ typeof(global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.UninterpretedOption), global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser, new[]{ "Name", "IdentifierValue", "PositiveIntValue", "NegativeIntValue", "DoubleValue", "StringValue", "AggregateValue" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart), global::LC.Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart.Parser, new[]{ "NamePart_", "IsExtension" }, null, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.SourceCodeInfo), global::LC.Google.Protobuf.Reflection.SourceCodeInfo.Parser, new[]{ "Location" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.SourceCodeInfo.Types.Location), global::LC.Google.Protobuf.Reflection.SourceCodeInfo.Types.Location.Parser, new[]{ "Path", "Span", "LeadingComments", "TrailingComments", "LeadingDetachedComments" }, null, null, null, null)}), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.GeneratedCodeInfo), global::LC.Google.Protobuf.Reflection.GeneratedCodeInfo.Parser, new[]{ "Annotation" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation), global::LC.Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Parser, new[]{ "Path", "SourceFile", "Begin", "End" }, null, null, null, null)}) + })); + } + #endregion + + } + #region Messages + /// + /// The protocol compiler can output a FileDescriptorSet containing the .proto + /// files it parses. + /// + public sealed partial class FileDescriptorSet : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileDescriptorSet()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileDescriptorSet() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileDescriptorSet(FileDescriptorSet other) : this() { + file_ = other.file_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileDescriptorSet Clone() { + return new FileDescriptorSet(this); + } + + /// Field number for the "file" field. + public const int FileFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_file_codec + = pb::FieldCodec.ForMessage(10, global::LC.Google.Protobuf.Reflection.FileDescriptorProto.Parser); + private readonly pbc::RepeatedField file_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField File { + get { return file_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FileDescriptorSet); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FileDescriptorSet other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!file_.Equals(other.file_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= file_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + file_.WriteTo(output, _repeated_file_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + file_.WriteTo(ref output, _repeated_file_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += file_.CalculateSize(_repeated_file_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FileDescriptorSet other) { + if (other == null) { + return; + } + file_.Add(other.file_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + file_.AddEntriesFrom(input, _repeated_file_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + file_.AddEntriesFrom(ref input, _repeated_file_codec); + break; + } + } + } + } + #endif + + } + + /// + /// Describes a complete .proto file. + /// + public sealed partial class FileDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileDescriptorProto(FileDescriptorProto other) : this() { + name_ = other.name_; + package_ = other.package_; + dependency_ = other.dependency_.Clone(); + publicDependency_ = other.publicDependency_.Clone(); + weakDependency_ = other.weakDependency_.Clone(); + messageType_ = other.messageType_.Clone(); + enumType_ = other.enumType_.Clone(); + service_ = other.service_.Clone(); + extension_ = other.extension_.Clone(); + options_ = other.options_ != null ? other.options_.Clone() : null; + sourceCodeInfo_ = other.sourceCodeInfo_ != null ? other.sourceCodeInfo_.Clone() : null; + syntax_ = other.syntax_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileDescriptorProto Clone() { + return new FileDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + /// + /// file name, relative to root of source tree + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "package" field. + public const int PackageFieldNumber = 2; + private readonly static string PackageDefaultValue = ""; + + private string package_; + /// + /// e.g. "foo", "foo.bar", etc. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Package { + get { return package_ ?? PackageDefaultValue; } + set { + package_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "package" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPackage { + get { return package_ != null; } + } + /// Clears the value of the "package" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPackage() { + package_ = null; + } + + /// Field number for the "dependency" field. + public const int DependencyFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_dependency_codec + = pb::FieldCodec.ForString(26); + private readonly pbc::RepeatedField dependency_ = new pbc::RepeatedField(); + /// + /// Names of files imported by this file. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Dependency { + get { return dependency_; } + } + + /// Field number for the "public_dependency" field. + public const int PublicDependencyFieldNumber = 10; + private static readonly pb::FieldCodec _repeated_publicDependency_codec + = pb::FieldCodec.ForInt32(80); + private readonly pbc::RepeatedField publicDependency_ = new pbc::RepeatedField(); + /// + /// Indexes of the public imported files in the dependency list above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField PublicDependency { + get { return publicDependency_; } + } + + /// Field number for the "weak_dependency" field. + public const int WeakDependencyFieldNumber = 11; + private static readonly pb::FieldCodec _repeated_weakDependency_codec + = pb::FieldCodec.ForInt32(88); + private readonly pbc::RepeatedField weakDependency_ = new pbc::RepeatedField(); + /// + /// Indexes of the weak imported files in the dependency list. + /// For Google-internal migration only. Do not use. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField WeakDependency { + get { return weakDependency_; } + } + + /// Field number for the "message_type" field. + public const int MessageTypeFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_messageType_codec + = pb::FieldCodec.ForMessage(34, global::LC.Google.Protobuf.Reflection.DescriptorProto.Parser); + private readonly pbc::RepeatedField messageType_ = new pbc::RepeatedField(); + /// + /// All top-level definitions in this file. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField MessageType { + get { return messageType_; } + } + + /// Field number for the "enum_type" field. + public const int EnumTypeFieldNumber = 5; + private static readonly pb::FieldCodec _repeated_enumType_codec + = pb::FieldCodec.ForMessage(42, global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Parser); + private readonly pbc::RepeatedField enumType_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField EnumType { + get { return enumType_; } + } + + /// Field number for the "service" field. + public const int ServiceFieldNumber = 6; + private static readonly pb::FieldCodec _repeated_service_codec + = pb::FieldCodec.ForMessage(50, global::LC.Google.Protobuf.Reflection.ServiceDescriptorProto.Parser); + private readonly pbc::RepeatedField service_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Service { + get { return service_; } + } + + /// Field number for the "extension" field. + public const int ExtensionFieldNumber = 7; + private static readonly pb::FieldCodec _repeated_extension_codec + = pb::FieldCodec.ForMessage(58, global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Parser); + private readonly pbc::RepeatedField extension_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Extension { + get { return extension_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 8; + private global::LC.Google.Protobuf.Reflection.FileOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FileOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + /// Field number for the "source_code_info" field. + public const int SourceCodeInfoFieldNumber = 9; + private global::LC.Google.Protobuf.Reflection.SourceCodeInfo sourceCodeInfo_; + /// + /// This field contains optional information about the original source code. + /// You may safely remove this entire field without harming runtime + /// functionality of the descriptors -- the information is needed only by + /// development tools. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.SourceCodeInfo SourceCodeInfo { + get { return sourceCodeInfo_; } + set { + sourceCodeInfo_ = value; + } + } + + /// Field number for the "syntax" field. + public const int SyntaxFieldNumber = 12; + private readonly static string SyntaxDefaultValue = ""; + + private string syntax_; + /// + /// The syntax of the proto file. + /// The supported values are "proto2" and "proto3". + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Syntax { + get { return syntax_ ?? SyntaxDefaultValue; } + set { + syntax_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "syntax" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasSyntax { + get { return syntax_ != null; } + } + /// Clears the value of the "syntax" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearSyntax() { + syntax_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FileDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FileDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Package != other.Package) return false; + if(!dependency_.Equals(other.dependency_)) return false; + if(!publicDependency_.Equals(other.publicDependency_)) return false; + if(!weakDependency_.Equals(other.weakDependency_)) return false; + if(!messageType_.Equals(other.messageType_)) return false; + if(!enumType_.Equals(other.enumType_)) return false; + if(!service_.Equals(other.service_)) return false; + if(!extension_.Equals(other.extension_)) return false; + if (!object.Equals(Options, other.Options)) return false; + if (!object.Equals(SourceCodeInfo, other.SourceCodeInfo)) return false; + if (Syntax != other.Syntax) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + if (HasPackage) hash ^= Package.GetHashCode(); + hash ^= dependency_.GetHashCode(); + hash ^= publicDependency_.GetHashCode(); + hash ^= weakDependency_.GetHashCode(); + hash ^= messageType_.GetHashCode(); + hash ^= enumType_.GetHashCode(); + hash ^= service_.GetHashCode(); + hash ^= extension_.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (sourceCodeInfo_ != null) hash ^= SourceCodeInfo.GetHashCode(); + if (HasSyntax) hash ^= Syntax.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasPackage) { + output.WriteRawTag(18); + output.WriteString(Package); + } + dependency_.WriteTo(output, _repeated_dependency_codec); + messageType_.WriteTo(output, _repeated_messageType_codec); + enumType_.WriteTo(output, _repeated_enumType_codec); + service_.WriteTo(output, _repeated_service_codec); + extension_.WriteTo(output, _repeated_extension_codec); + if (options_ != null) { + output.WriteRawTag(66); + output.WriteMessage(Options); + } + if (sourceCodeInfo_ != null) { + output.WriteRawTag(74); + output.WriteMessage(SourceCodeInfo); + } + publicDependency_.WriteTo(output, _repeated_publicDependency_codec); + weakDependency_.WriteTo(output, _repeated_weakDependency_codec); + if (HasSyntax) { + output.WriteRawTag(98); + output.WriteString(Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasPackage) { + output.WriteRawTag(18); + output.WriteString(Package); + } + dependency_.WriteTo(ref output, _repeated_dependency_codec); + messageType_.WriteTo(ref output, _repeated_messageType_codec); + enumType_.WriteTo(ref output, _repeated_enumType_codec); + service_.WriteTo(ref output, _repeated_service_codec); + extension_.WriteTo(ref output, _repeated_extension_codec); + if (options_ != null) { + output.WriteRawTag(66); + output.WriteMessage(Options); + } + if (sourceCodeInfo_ != null) { + output.WriteRawTag(74); + output.WriteMessage(SourceCodeInfo); + } + publicDependency_.WriteTo(ref output, _repeated_publicDependency_codec); + weakDependency_.WriteTo(ref output, _repeated_weakDependency_codec); + if (HasSyntax) { + output.WriteRawTag(98); + output.WriteString(Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (HasPackage) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Package); + } + size += dependency_.CalculateSize(_repeated_dependency_codec); + size += publicDependency_.CalculateSize(_repeated_publicDependency_codec); + size += weakDependency_.CalculateSize(_repeated_weakDependency_codec); + size += messageType_.CalculateSize(_repeated_messageType_codec); + size += enumType_.CalculateSize(_repeated_enumType_codec); + size += service_.CalculateSize(_repeated_service_codec); + size += extension_.CalculateSize(_repeated_extension_codec); + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (sourceCodeInfo_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceCodeInfo); + } + if (HasSyntax) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Syntax); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FileDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + if (other.HasPackage) { + Package = other.Package; + } + dependency_.Add(other.dependency_); + publicDependency_.Add(other.publicDependency_); + weakDependency_.Add(other.weakDependency_); + messageType_.Add(other.messageType_); + enumType_.Add(other.enumType_); + service_.Add(other.service_); + extension_.Add(other.extension_); + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.FileOptions(); + } + Options.MergeFrom(other.Options); + } + if (other.sourceCodeInfo_ != null) { + if (sourceCodeInfo_ == null) { + SourceCodeInfo = new global::LC.Google.Protobuf.Reflection.SourceCodeInfo(); + } + SourceCodeInfo.MergeFrom(other.SourceCodeInfo); + } + if (other.HasSyntax) { + Syntax = other.Syntax; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Package = input.ReadString(); + break; + } + case 26: { + dependency_.AddEntriesFrom(input, _repeated_dependency_codec); + break; + } + case 34: { + messageType_.AddEntriesFrom(input, _repeated_messageType_codec); + break; + } + case 42: { + enumType_.AddEntriesFrom(input, _repeated_enumType_codec); + break; + } + case 50: { + service_.AddEntriesFrom(input, _repeated_service_codec); + break; + } + case 58: { + extension_.AddEntriesFrom(input, _repeated_extension_codec); + break; + } + case 66: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.FileOptions(); + } + input.ReadMessage(Options); + break; + } + case 74: { + if (sourceCodeInfo_ == null) { + SourceCodeInfo = new global::LC.Google.Protobuf.Reflection.SourceCodeInfo(); + } + input.ReadMessage(SourceCodeInfo); + break; + } + case 82: + case 80: { + publicDependency_.AddEntriesFrom(input, _repeated_publicDependency_codec); + break; + } + case 90: + case 88: { + weakDependency_.AddEntriesFrom(input, _repeated_weakDependency_codec); + break; + } + case 98: { + Syntax = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Package = input.ReadString(); + break; + } + case 26: { + dependency_.AddEntriesFrom(ref input, _repeated_dependency_codec); + break; + } + case 34: { + messageType_.AddEntriesFrom(ref input, _repeated_messageType_codec); + break; + } + case 42: { + enumType_.AddEntriesFrom(ref input, _repeated_enumType_codec); + break; + } + case 50: { + service_.AddEntriesFrom(ref input, _repeated_service_codec); + break; + } + case 58: { + extension_.AddEntriesFrom(ref input, _repeated_extension_codec); + break; + } + case 66: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.FileOptions(); + } + input.ReadMessage(Options); + break; + } + case 74: { + if (sourceCodeInfo_ == null) { + SourceCodeInfo = new global::LC.Google.Protobuf.Reflection.SourceCodeInfo(); + } + input.ReadMessage(SourceCodeInfo); + break; + } + case 82: + case 80: { + publicDependency_.AddEntriesFrom(ref input, _repeated_publicDependency_codec); + break; + } + case 90: + case 88: { + weakDependency_.AddEntriesFrom(ref input, _repeated_weakDependency_codec); + break; + } + case 98: { + Syntax = input.ReadString(); + break; + } + } + } + } + #endif + + } + + /// + /// Describes a message type. + /// + public sealed partial class DescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public DescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public DescriptorProto(DescriptorProto other) : this() { + name_ = other.name_; + field_ = other.field_.Clone(); + extension_ = other.extension_.Clone(); + nestedType_ = other.nestedType_.Clone(); + enumType_ = other.enumType_.Clone(); + extensionRange_ = other.extensionRange_.Clone(); + oneofDecl_ = other.oneofDecl_.Clone(); + options_ = other.options_ != null ? other.options_.Clone() : null; + reservedRange_ = other.reservedRange_.Clone(); + reservedName_ = other.reservedName_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public DescriptorProto Clone() { + return new DescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "field" field. + public const int FieldFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_field_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Parser); + private readonly pbc::RepeatedField field_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Field { + get { return field_; } + } + + /// Field number for the "extension" field. + public const int ExtensionFieldNumber = 6; + private static readonly pb::FieldCodec _repeated_extension_codec + = pb::FieldCodec.ForMessage(50, global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Parser); + private readonly pbc::RepeatedField extension_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Extension { + get { return extension_; } + } + + /// Field number for the "nested_type" field. + public const int NestedTypeFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_nestedType_codec + = pb::FieldCodec.ForMessage(26, global::LC.Google.Protobuf.Reflection.DescriptorProto.Parser); + private readonly pbc::RepeatedField nestedType_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField NestedType { + get { return nestedType_; } + } + + /// Field number for the "enum_type" field. + public const int EnumTypeFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_enumType_codec + = pb::FieldCodec.ForMessage(34, global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Parser); + private readonly pbc::RepeatedField enumType_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField EnumType { + get { return enumType_; } + } + + /// Field number for the "extension_range" field. + public const int ExtensionRangeFieldNumber = 5; + private static readonly pb::FieldCodec _repeated_extensionRange_codec + = pb::FieldCodec.ForMessage(42, global::LC.Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser); + private readonly pbc::RepeatedField extensionRange_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField ExtensionRange { + get { return extensionRange_; } + } + + /// Field number for the "oneof_decl" field. + public const int OneofDeclFieldNumber = 8; + private static readonly pb::FieldCodec _repeated_oneofDecl_codec + = pb::FieldCodec.ForMessage(66, global::LC.Google.Protobuf.Reflection.OneofDescriptorProto.Parser); + private readonly pbc::RepeatedField oneofDecl_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField OneofDecl { + get { return oneofDecl_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 7; + private global::LC.Google.Protobuf.Reflection.MessageOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.MessageOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + /// Field number for the "reserved_range" field. + public const int ReservedRangeFieldNumber = 9; + private static readonly pb::FieldCodec _repeated_reservedRange_codec + = pb::FieldCodec.ForMessage(74, global::LC.Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser); + private readonly pbc::RepeatedField reservedRange_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField ReservedRange { + get { return reservedRange_; } + } + + /// Field number for the "reserved_name" field. + public const int ReservedNameFieldNumber = 10; + private static readonly pb::FieldCodec _repeated_reservedName_codec + = pb::FieldCodec.ForString(82); + private readonly pbc::RepeatedField reservedName_ = new pbc::RepeatedField(); + /// + /// Reserved field names, which may not be used by fields in the same message. + /// A given name may only be reserved once. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField ReservedName { + get { return reservedName_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as DescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(DescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!field_.Equals(other.field_)) return false; + if(!extension_.Equals(other.extension_)) return false; + if(!nestedType_.Equals(other.nestedType_)) return false; + if(!enumType_.Equals(other.enumType_)) return false; + if(!extensionRange_.Equals(other.extensionRange_)) return false; + if(!oneofDecl_.Equals(other.oneofDecl_)) return false; + if (!object.Equals(Options, other.Options)) return false; + if(!reservedRange_.Equals(other.reservedRange_)) return false; + if(!reservedName_.Equals(other.reservedName_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + hash ^= field_.GetHashCode(); + hash ^= extension_.GetHashCode(); + hash ^= nestedType_.GetHashCode(); + hash ^= enumType_.GetHashCode(); + hash ^= extensionRange_.GetHashCode(); + hash ^= oneofDecl_.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + hash ^= reservedRange_.GetHashCode(); + hash ^= reservedName_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + field_.WriteTo(output, _repeated_field_codec); + nestedType_.WriteTo(output, _repeated_nestedType_codec); + enumType_.WriteTo(output, _repeated_enumType_codec); + extensionRange_.WriteTo(output, _repeated_extensionRange_codec); + extension_.WriteTo(output, _repeated_extension_codec); + if (options_ != null) { + output.WriteRawTag(58); + output.WriteMessage(Options); + } + oneofDecl_.WriteTo(output, _repeated_oneofDecl_codec); + reservedRange_.WriteTo(output, _repeated_reservedRange_codec); + reservedName_.WriteTo(output, _repeated_reservedName_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + field_.WriteTo(ref output, _repeated_field_codec); + nestedType_.WriteTo(ref output, _repeated_nestedType_codec); + enumType_.WriteTo(ref output, _repeated_enumType_codec); + extensionRange_.WriteTo(ref output, _repeated_extensionRange_codec); + extension_.WriteTo(ref output, _repeated_extension_codec); + if (options_ != null) { + output.WriteRawTag(58); + output.WriteMessage(Options); + } + oneofDecl_.WriteTo(ref output, _repeated_oneofDecl_codec); + reservedRange_.WriteTo(ref output, _repeated_reservedRange_codec); + reservedName_.WriteTo(ref output, _repeated_reservedName_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += field_.CalculateSize(_repeated_field_codec); + size += extension_.CalculateSize(_repeated_extension_codec); + size += nestedType_.CalculateSize(_repeated_nestedType_codec); + size += enumType_.CalculateSize(_repeated_enumType_codec); + size += extensionRange_.CalculateSize(_repeated_extensionRange_codec); + size += oneofDecl_.CalculateSize(_repeated_oneofDecl_codec); + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + size += reservedRange_.CalculateSize(_repeated_reservedRange_codec); + size += reservedName_.CalculateSize(_repeated_reservedName_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(DescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + field_.Add(other.field_); + extension_.Add(other.extension_); + nestedType_.Add(other.nestedType_); + enumType_.Add(other.enumType_); + extensionRange_.Add(other.extensionRange_); + oneofDecl_.Add(other.oneofDecl_); + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.MessageOptions(); + } + Options.MergeFrom(other.Options); + } + reservedRange_.Add(other.reservedRange_); + reservedName_.Add(other.reservedName_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + field_.AddEntriesFrom(input, _repeated_field_codec); + break; + } + case 26: { + nestedType_.AddEntriesFrom(input, _repeated_nestedType_codec); + break; + } + case 34: { + enumType_.AddEntriesFrom(input, _repeated_enumType_codec); + break; + } + case 42: { + extensionRange_.AddEntriesFrom(input, _repeated_extensionRange_codec); + break; + } + case 50: { + extension_.AddEntriesFrom(input, _repeated_extension_codec); + break; + } + case 58: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.MessageOptions(); + } + input.ReadMessage(Options); + break; + } + case 66: { + oneofDecl_.AddEntriesFrom(input, _repeated_oneofDecl_codec); + break; + } + case 74: { + reservedRange_.AddEntriesFrom(input, _repeated_reservedRange_codec); + break; + } + case 82: { + reservedName_.AddEntriesFrom(input, _repeated_reservedName_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + field_.AddEntriesFrom(ref input, _repeated_field_codec); + break; + } + case 26: { + nestedType_.AddEntriesFrom(ref input, _repeated_nestedType_codec); + break; + } + case 34: { + enumType_.AddEntriesFrom(ref input, _repeated_enumType_codec); + break; + } + case 42: { + extensionRange_.AddEntriesFrom(ref input, _repeated_extensionRange_codec); + break; + } + case 50: { + extension_.AddEntriesFrom(ref input, _repeated_extension_codec); + break; + } + case 58: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.MessageOptions(); + } + input.ReadMessage(Options); + break; + } + case 66: { + oneofDecl_.AddEntriesFrom(ref input, _repeated_oneofDecl_codec); + break; + } + case 74: { + reservedRange_.AddEntriesFrom(ref input, _repeated_reservedRange_codec); + break; + } + case 82: { + reservedName_.AddEntriesFrom(ref input, _repeated_reservedName_codec); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the DescriptorProto message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public sealed partial class ExtensionRange : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ExtensionRange()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorProto.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ExtensionRange() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ExtensionRange(ExtensionRange other) : this() { + _hasBits0 = other._hasBits0; + start_ = other.start_; + end_ = other.end_; + options_ = other.options_ != null ? other.options_.Clone() : null; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ExtensionRange Clone() { + return new ExtensionRange(this); + } + + /// Field number for the "start" field. + public const int StartFieldNumber = 1; + private readonly static int StartDefaultValue = 0; + + private int start_; + /// + /// Inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Start { + get { if ((_hasBits0 & 1) != 0) { return start_; } else { return StartDefaultValue; } } + set { + _hasBits0 |= 1; + start_ = value; + } + } + /// Gets whether the "start" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasStart { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "start" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearStart() { + _hasBits0 &= ~1; + } + + /// Field number for the "end" field. + public const int EndFieldNumber = 2; + private readonly static int EndDefaultValue = 0; + + private int end_; + /// + /// Exclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int End { + get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } } + set { + _hasBits0 |= 2; + end_ = value; + } + } + /// Gets whether the "end" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasEnd { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "end" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEnd() { + _hasBits0 &= ~2; + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ExtensionRange); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ExtensionRange other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Start != other.Start) return false; + if (End != other.End) return false; + if (!object.Equals(Options, other.Options)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasStart) hash ^= Start.GetHashCode(); + if (HasEnd) hash ^= End.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasStart) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start); + } + if (HasEnd) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(End); + } + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ExtensionRange other) { + if (other == null) { + return; + } + if (other.HasStart) { + Start = other.Start; + } + if (other.HasEnd) { + End = other.End; + } + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions(); + } + Options.MergeFrom(other.Options); + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.ExtensionRangeOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + + } + + /// + /// Range of reserved tag numbers. Reserved tag numbers may not be used by + /// fields or extension ranges in the same message. Reserved ranges may + /// not overlap. + /// + public sealed partial class ReservedRange : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ReservedRange()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorProto.Descriptor.NestedTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ReservedRange() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ReservedRange(ReservedRange other) : this() { + _hasBits0 = other._hasBits0; + start_ = other.start_; + end_ = other.end_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ReservedRange Clone() { + return new ReservedRange(this); + } + + /// Field number for the "start" field. + public const int StartFieldNumber = 1; + private readonly static int StartDefaultValue = 0; + + private int start_; + /// + /// Inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Start { + get { if ((_hasBits0 & 1) != 0) { return start_; } else { return StartDefaultValue; } } + set { + _hasBits0 |= 1; + start_ = value; + } + } + /// Gets whether the "start" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasStart { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "start" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearStart() { + _hasBits0 &= ~1; + } + + /// Field number for the "end" field. + public const int EndFieldNumber = 2; + private readonly static int EndDefaultValue = 0; + + private int end_; + /// + /// Exclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int End { + get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } } + set { + _hasBits0 |= 2; + end_ = value; + } + } + /// Gets whether the "end" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasEnd { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "end" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEnd() { + _hasBits0 &= ~2; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ReservedRange); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ReservedRange other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Start != other.Start) return false; + if (End != other.End) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasStart) hash ^= Start.GetHashCode(); + if (HasEnd) hash ^= End.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasStart) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start); + } + if (HasEnd) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(End); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ReservedRange other) { + if (other == null) { + return; + } + if (other.HasStart) { + Start = other.Start; + } + if (other.HasEnd) { + End = other.End; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + } + } + } + #endif + + } + + } + #endregion + + } + + public sealed partial class ExtensionRangeOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ExtensionRangeOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[3]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ExtensionRangeOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ExtensionRangeOptions(ExtensionRangeOptions other) : this() { + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ExtensionRangeOptions Clone() { + return new ExtensionRangeOptions(this); + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ExtensionRangeOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ExtensionRangeOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ExtensionRangeOptions other) { + if (other == null) { + return; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + } + + /// + /// Describes a field within a message. + /// + public sealed partial class FieldDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[4]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldDescriptorProto(FieldDescriptorProto other) : this() { + _hasBits0 = other._hasBits0; + name_ = other.name_; + number_ = other.number_; + label_ = other.label_; + type_ = other.type_; + typeName_ = other.typeName_; + extendee_ = other.extendee_; + defaultValue_ = other.defaultValue_; + oneofIndex_ = other.oneofIndex_; + jsonName_ = other.jsonName_; + options_ = other.options_ != null ? other.options_.Clone() : null; + proto3Optional_ = other.proto3Optional_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldDescriptorProto Clone() { + return new FieldDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "number" field. + public const int NumberFieldNumber = 3; + private readonly static int NumberDefaultValue = 0; + + private int number_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Number { + get { if ((_hasBits0 & 1) != 0) { return number_; } else { return NumberDefaultValue; } } + set { + _hasBits0 |= 1; + number_ = value; + } + } + /// Gets whether the "number" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasNumber { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "number" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNumber() { + _hasBits0 &= ~1; + } + + /// Field number for the "label" field. + public const int LabelFieldNumber = 4; + private readonly static global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label LabelDefaultValue = global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label.Optional; + + private global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label label_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label Label { + get { if ((_hasBits0 & 2) != 0) { return label_; } else { return LabelDefaultValue; } } + set { + _hasBits0 |= 2; + label_ = value; + } + } + /// Gets whether the "label" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasLabel { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "label" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearLabel() { + _hasBits0 &= ~2; + } + + /// Field number for the "type" field. + public const int TypeFieldNumber = 5; + private readonly static global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type TypeDefaultValue = global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type.Double; + + private global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type type_; + /// + /// If type_name is set, this need not be set. If both this and type_name + /// are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type Type { + get { if ((_hasBits0 & 4) != 0) { return type_; } else { return TypeDefaultValue; } } + set { + _hasBits0 |= 4; + type_ = value; + } + } + /// Gets whether the "type" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasType { + get { return (_hasBits0 & 4) != 0; } + } + /// Clears the value of the "type" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearType() { + _hasBits0 &= ~4; + } + + /// Field number for the "type_name" field. + public const int TypeNameFieldNumber = 6; + private readonly static string TypeNameDefaultValue = ""; + + private string typeName_; + /// + /// For message and enum types, this is the name of the type. If the name + /// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + /// rules are used to find the type (i.e. first the nested types within this + /// message are searched, then within the parent, on up to the root + /// namespace). + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TypeName { + get { return typeName_ ?? TypeNameDefaultValue; } + set { + typeName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "type_name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasTypeName { + get { return typeName_ != null; } + } + /// Clears the value of the "type_name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearTypeName() { + typeName_ = null; + } + + /// Field number for the "extendee" field. + public const int ExtendeeFieldNumber = 2; + private readonly static string ExtendeeDefaultValue = ""; + + private string extendee_; + /// + /// For extensions, this is the name of the type being extended. It is + /// resolved in the same manner as type_name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Extendee { + get { return extendee_ ?? ExtendeeDefaultValue; } + set { + extendee_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "extendee" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasExtendee { + get { return extendee_ != null; } + } + /// Clears the value of the "extendee" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearExtendee() { + extendee_ = null; + } + + /// Field number for the "default_value" field. + public const int DefaultValueFieldNumber = 7; + private readonly static string DefaultValueDefaultValue = ""; + + private string defaultValue_; + /// + /// For numeric types, contains the original text representation of the value. + /// For booleans, "true" or "false". + /// For strings, contains the default text contents (not escaped in any way). + /// For bytes, contains the C escaped value. All bytes >= 128 are escaped. + /// TODO(kenton): Base-64 encode? + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string DefaultValue { + get { return defaultValue_ ?? DefaultValueDefaultValue; } + set { + defaultValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "default_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDefaultValue { + get { return defaultValue_ != null; } + } + /// Clears the value of the "default_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDefaultValue() { + defaultValue_ = null; + } + + /// Field number for the "oneof_index" field. + public const int OneofIndexFieldNumber = 9; + private readonly static int OneofIndexDefaultValue = 0; + + private int oneofIndex_; + /// + /// If set, gives the index of a oneof in the containing type's oneof_decl + /// list. This field is a member of that oneof. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int OneofIndex { + get { if ((_hasBits0 & 8) != 0) { return oneofIndex_; } else { return OneofIndexDefaultValue; } } + set { + _hasBits0 |= 8; + oneofIndex_ = value; + } + } + /// Gets whether the "oneof_index" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasOneofIndex { + get { return (_hasBits0 & 8) != 0; } + } + /// Clears the value of the "oneof_index" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearOneofIndex() { + _hasBits0 &= ~8; + } + + /// Field number for the "json_name" field. + public const int JsonNameFieldNumber = 10; + private readonly static string JsonNameDefaultValue = ""; + + private string jsonName_; + /// + /// JSON name of this field. The value is set by protocol compiler. If the + /// user has set a "json_name" option on this field, that option's value + /// will be used. Otherwise, it's deduced from the field's name by converting + /// it to camelCase. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string JsonName { + get { return jsonName_ ?? JsonNameDefaultValue; } + set { + jsonName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "json_name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJsonName { + get { return jsonName_ != null; } + } + /// Clears the value of the "json_name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJsonName() { + jsonName_ = null; + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 8; + private global::LC.Google.Protobuf.Reflection.FieldOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FieldOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + /// Field number for the "proto3_optional" field. + public const int Proto3OptionalFieldNumber = 17; + private readonly static bool Proto3OptionalDefaultValue = false; + + private bool proto3Optional_; + /// + /// If true, this is a proto3 "optional". When a proto3 field is optional, it + /// tracks presence regardless of field type. + /// + /// When proto3_optional is true, this field must be belong to a oneof to + /// signal to old proto3 clients that presence is tracked for this field. This + /// oneof is known as a "synthetic" oneof, and this field must be its sole + /// member (each proto3 optional field gets its own synthetic oneof). Synthetic + /// oneofs exist in the descriptor only, and do not generate any API. Synthetic + /// oneofs must be ordered after all "real" oneofs. + /// + /// For message fields, proto3_optional doesn't create any semantic change, + /// since non-repeated message fields always track presence. However it still + /// indicates the semantic detail of whether the user wrote "optional" or not. + /// This can be useful for round-tripping the .proto file. For consistency we + /// give message fields a synthetic oneof also, even though it is not required + /// to track presence. This is especially important because the parser can't + /// tell if a field is a message or an enum, so it must always create a + /// synthetic oneof. + /// + /// Proto2 optional fields do not set this flag, because they already indicate + /// optional with `LABEL_OPTIONAL`. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Proto3Optional { + get { if ((_hasBits0 & 16) != 0) { return proto3Optional_; } else { return Proto3OptionalDefaultValue; } } + set { + _hasBits0 |= 16; + proto3Optional_ = value; + } + } + /// Gets whether the "proto3_optional" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasProto3Optional { + get { return (_hasBits0 & 16) != 0; } + } + /// Clears the value of the "proto3_optional" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearProto3Optional() { + _hasBits0 &= ~16; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FieldDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FieldDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Number != other.Number) return false; + if (Label != other.Label) return false; + if (Type != other.Type) return false; + if (TypeName != other.TypeName) return false; + if (Extendee != other.Extendee) return false; + if (DefaultValue != other.DefaultValue) return false; + if (OneofIndex != other.OneofIndex) return false; + if (JsonName != other.JsonName) return false; + if (!object.Equals(Options, other.Options)) return false; + if (Proto3Optional != other.Proto3Optional) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + if (HasNumber) hash ^= Number.GetHashCode(); + if (HasLabel) hash ^= Label.GetHashCode(); + if (HasType) hash ^= Type.GetHashCode(); + if (HasTypeName) hash ^= TypeName.GetHashCode(); + if (HasExtendee) hash ^= Extendee.GetHashCode(); + if (HasDefaultValue) hash ^= DefaultValue.GetHashCode(); + if (HasOneofIndex) hash ^= OneofIndex.GetHashCode(); + if (HasJsonName) hash ^= JsonName.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (HasProto3Optional) hash ^= Proto3Optional.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasExtendee) { + output.WriteRawTag(18); + output.WriteString(Extendee); + } + if (HasNumber) { + output.WriteRawTag(24); + output.WriteInt32(Number); + } + if (HasLabel) { + output.WriteRawTag(32); + output.WriteEnum((int) Label); + } + if (HasType) { + output.WriteRawTag(40); + output.WriteEnum((int) Type); + } + if (HasTypeName) { + output.WriteRawTag(50); + output.WriteString(TypeName); + } + if (HasDefaultValue) { + output.WriteRawTag(58); + output.WriteString(DefaultValue); + } + if (options_ != null) { + output.WriteRawTag(66); + output.WriteMessage(Options); + } + if (HasOneofIndex) { + output.WriteRawTag(72); + output.WriteInt32(OneofIndex); + } + if (HasJsonName) { + output.WriteRawTag(82); + output.WriteString(JsonName); + } + if (HasProto3Optional) { + output.WriteRawTag(136, 1); + output.WriteBool(Proto3Optional); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasExtendee) { + output.WriteRawTag(18); + output.WriteString(Extendee); + } + if (HasNumber) { + output.WriteRawTag(24); + output.WriteInt32(Number); + } + if (HasLabel) { + output.WriteRawTag(32); + output.WriteEnum((int) Label); + } + if (HasType) { + output.WriteRawTag(40); + output.WriteEnum((int) Type); + } + if (HasTypeName) { + output.WriteRawTag(50); + output.WriteString(TypeName); + } + if (HasDefaultValue) { + output.WriteRawTag(58); + output.WriteString(DefaultValue); + } + if (options_ != null) { + output.WriteRawTag(66); + output.WriteMessage(Options); + } + if (HasOneofIndex) { + output.WriteRawTag(72); + output.WriteInt32(OneofIndex); + } + if (HasJsonName) { + output.WriteRawTag(82); + output.WriteString(JsonName); + } + if (HasProto3Optional) { + output.WriteRawTag(136, 1); + output.WriteBool(Proto3Optional); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (HasNumber) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number); + } + if (HasLabel) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Label); + } + if (HasType) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type); + } + if (HasTypeName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeName); + } + if (HasExtendee) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Extendee); + } + if (HasDefaultValue) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(DefaultValue); + } + if (HasOneofIndex) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofIndex); + } + if (HasJsonName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName); + } + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (HasProto3Optional) { + size += 2 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FieldDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + if (other.HasNumber) { + Number = other.Number; + } + if (other.HasLabel) { + Label = other.Label; + } + if (other.HasType) { + Type = other.Type; + } + if (other.HasTypeName) { + TypeName = other.TypeName; + } + if (other.HasExtendee) { + Extendee = other.Extendee; + } + if (other.HasDefaultValue) { + DefaultValue = other.DefaultValue; + } + if (other.HasOneofIndex) { + OneofIndex = other.OneofIndex; + } + if (other.HasJsonName) { + JsonName = other.JsonName; + } + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.FieldOptions(); + } + Options.MergeFrom(other.Options); + } + if (other.HasProto3Optional) { + Proto3Optional = other.Proto3Optional; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Extendee = input.ReadString(); + break; + } + case 24: { + Number = input.ReadInt32(); + break; + } + case 32: { + Label = (global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) input.ReadEnum(); + break; + } + case 40: { + Type = (global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type) input.ReadEnum(); + break; + } + case 50: { + TypeName = input.ReadString(); + break; + } + case 58: { + DefaultValue = input.ReadString(); + break; + } + case 66: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.FieldOptions(); + } + input.ReadMessage(Options); + break; + } + case 72: { + OneofIndex = input.ReadInt32(); + break; + } + case 82: { + JsonName = input.ReadString(); + break; + } + case 136: { + Proto3Optional = input.ReadBool(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Extendee = input.ReadString(); + break; + } + case 24: { + Number = input.ReadInt32(); + break; + } + case 32: { + Label = (global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) input.ReadEnum(); + break; + } + case 40: { + Type = (global::LC.Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type) input.ReadEnum(); + break; + } + case 50: { + TypeName = input.ReadString(); + break; + } + case 58: { + DefaultValue = input.ReadString(); + break; + } + case 66: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.FieldOptions(); + } + input.ReadMessage(Options); + break; + } + case 72: { + OneofIndex = input.ReadInt32(); + break; + } + case 82: { + JsonName = input.ReadString(); + break; + } + case 136: { + Proto3Optional = input.ReadBool(); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the FieldDescriptorProto message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public enum Type { + /// + /// 0 is reserved for errors. + /// Order is weird for historical reasons. + /// + [pbr::OriginalName("TYPE_DOUBLE")] Double = 1, + [pbr::OriginalName("TYPE_FLOAT")] Float = 2, + /// + /// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + /// negative values are likely. + /// + [pbr::OriginalName("TYPE_INT64")] Int64 = 3, + [pbr::OriginalName("TYPE_UINT64")] Uint64 = 4, + /// + /// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + /// negative values are likely. + /// + [pbr::OriginalName("TYPE_INT32")] Int32 = 5, + [pbr::OriginalName("TYPE_FIXED64")] Fixed64 = 6, + [pbr::OriginalName("TYPE_FIXED32")] Fixed32 = 7, + [pbr::OriginalName("TYPE_BOOL")] Bool = 8, + [pbr::OriginalName("TYPE_STRING")] String = 9, + /// + /// Tag-delimited aggregate. + /// Group type is deprecated and not supported in proto3. However, Proto3 + /// implementations should still be able to parse the group wire format and + /// treat group fields as unknown fields. + /// + [pbr::OriginalName("TYPE_GROUP")] Group = 10, + /// + /// Length-delimited aggregate. + /// + [pbr::OriginalName("TYPE_MESSAGE")] Message = 11, + /// + /// New in version 2. + /// + [pbr::OriginalName("TYPE_BYTES")] Bytes = 12, + [pbr::OriginalName("TYPE_UINT32")] Uint32 = 13, + [pbr::OriginalName("TYPE_ENUM")] Enum = 14, + [pbr::OriginalName("TYPE_SFIXED32")] Sfixed32 = 15, + [pbr::OriginalName("TYPE_SFIXED64")] Sfixed64 = 16, + /// + /// Uses ZigZag encoding. + /// + [pbr::OriginalName("TYPE_SINT32")] Sint32 = 17, + /// + /// Uses ZigZag encoding. + /// + [pbr::OriginalName("TYPE_SINT64")] Sint64 = 18, + } + + public enum Label { + /// + /// 0 is reserved for errors + /// + [pbr::OriginalName("LABEL_OPTIONAL")] Optional = 1, + [pbr::OriginalName("LABEL_REQUIRED")] Required = 2, + [pbr::OriginalName("LABEL_REPEATED")] Repeated = 3, + } + + } + #endregion + + } + + /// + /// Describes a oneof. + /// + public sealed partial class OneofDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[5]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public OneofDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public OneofDescriptorProto(OneofDescriptorProto other) : this() { + name_ = other.name_; + options_ = other.options_ != null ? other.options_.Clone() : null; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public OneofDescriptorProto Clone() { + return new OneofDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 2; + private global::LC.Google.Protobuf.Reflection.OneofOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.OneofOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as OneofDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(OneofDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (!object.Equals(Options, other.Options)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (options_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (options_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(OneofDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.OneofOptions(); + } + Options.MergeFrom(other.Options); + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.OneofOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.OneofOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + + } + + /// + /// Describes an enum type. + /// + public sealed partial class EnumDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[6]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumDescriptorProto(EnumDescriptorProto other) : this() { + name_ = other.name_; + value_ = other.value_.Clone(); + options_ = other.options_ != null ? other.options_.Clone() : null; + reservedRange_ = other.reservedRange_.Clone(); + reservedName_ = other.reservedName_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumDescriptorProto Clone() { + return new EnumDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "value" field. + public const int ValueFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_value_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser); + private readonly pbc::RepeatedField value_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Value { + get { return value_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private global::LC.Google.Protobuf.Reflection.EnumOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.EnumOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + /// Field number for the "reserved_range" field. + public const int ReservedRangeFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_reservedRange_codec + = pb::FieldCodec.ForMessage(34, global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange.Parser); + private readonly pbc::RepeatedField reservedRange_ = new pbc::RepeatedField(); + /// + /// Range of reserved numeric values. Reserved numeric values may not be used + /// by enum values in the same enum declaration. Reserved ranges may not + /// overlap. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField ReservedRange { + get { return reservedRange_; } + } + + /// Field number for the "reserved_name" field. + public const int ReservedNameFieldNumber = 5; + private static readonly pb::FieldCodec _repeated_reservedName_codec + = pb::FieldCodec.ForString(42); + private readonly pbc::RepeatedField reservedName_ = new pbc::RepeatedField(); + /// + /// Reserved enum value names, which may not be reused. A given name may only + /// be reserved once. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField ReservedName { + get { return reservedName_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EnumDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EnumDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!value_.Equals(other.value_)) return false; + if (!object.Equals(Options, other.Options)) return false; + if(!reservedRange_.Equals(other.reservedRange_)) return false; + if(!reservedName_.Equals(other.reservedName_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + hash ^= value_.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + hash ^= reservedRange_.GetHashCode(); + hash ^= reservedName_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + value_.WriteTo(output, _repeated_value_codec); + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + reservedRange_.WriteTo(output, _repeated_reservedRange_codec); + reservedName_.WriteTo(output, _repeated_reservedName_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + value_.WriteTo(ref output, _repeated_value_codec); + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + reservedRange_.WriteTo(ref output, _repeated_reservedRange_codec); + reservedName_.WriteTo(ref output, _repeated_reservedName_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += value_.CalculateSize(_repeated_value_codec); + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + size += reservedRange_.CalculateSize(_repeated_reservedRange_codec); + size += reservedName_.CalculateSize(_repeated_reservedName_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EnumDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + value_.Add(other.value_); + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.EnumOptions(); + } + Options.MergeFrom(other.Options); + } + reservedRange_.Add(other.reservedRange_); + reservedName_.Add(other.reservedName_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + value_.AddEntriesFrom(input, _repeated_value_codec); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.EnumOptions(); + } + input.ReadMessage(Options); + break; + } + case 34: { + reservedRange_.AddEntriesFrom(input, _repeated_reservedRange_codec); + break; + } + case 42: { + reservedName_.AddEntriesFrom(input, _repeated_reservedName_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + value_.AddEntriesFrom(ref input, _repeated_value_codec); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.EnumOptions(); + } + input.ReadMessage(Options); + break; + } + case 34: { + reservedRange_.AddEntriesFrom(ref input, _repeated_reservedRange_codec); + break; + } + case 42: { + reservedName_.AddEntriesFrom(ref input, _repeated_reservedName_codec); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the EnumDescriptorProto message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + /// + /// Range of reserved numeric values. Reserved values may not be used by + /// entries in the same enum. Reserved ranges may not overlap. + /// + /// Note that this is distinct from DescriptorProto.ReservedRange in that it + /// is inclusive such that it can appropriately represent the entire int32 + /// domain. + /// + public sealed partial class EnumReservedRange : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumReservedRange()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.EnumDescriptorProto.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumReservedRange() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumReservedRange(EnumReservedRange other) : this() { + _hasBits0 = other._hasBits0; + start_ = other.start_; + end_ = other.end_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumReservedRange Clone() { + return new EnumReservedRange(this); + } + + /// Field number for the "start" field. + public const int StartFieldNumber = 1; + private readonly static int StartDefaultValue = 0; + + private int start_; + /// + /// Inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Start { + get { if ((_hasBits0 & 1) != 0) { return start_; } else { return StartDefaultValue; } } + set { + _hasBits0 |= 1; + start_ = value; + } + } + /// Gets whether the "start" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasStart { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "start" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearStart() { + _hasBits0 &= ~1; + } + + /// Field number for the "end" field. + public const int EndFieldNumber = 2; + private readonly static int EndDefaultValue = 0; + + private int end_; + /// + /// Inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int End { + get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } } + set { + _hasBits0 |= 2; + end_ = value; + } + } + /// Gets whether the "end" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasEnd { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "end" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEnd() { + _hasBits0 &= ~2; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EnumReservedRange); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EnumReservedRange other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Start != other.Start) return false; + if (End != other.End) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasStart) hash ^= Start.GetHashCode(); + if (HasEnd) hash ^= End.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasStart) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start); + } + if (HasEnd) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(End); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EnumReservedRange other) { + if (other == null) { + return; + } + if (other.HasStart) { + Start = other.Start; + } + if (other.HasEnd) { + End = other.End; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + } + } + } + #endif + + } + + } + #endregion + + } + + /// + /// Describes a value within an enum. + /// + public sealed partial class EnumValueDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValueDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[7]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValueDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValueDescriptorProto(EnumValueDescriptorProto other) : this() { + _hasBits0 = other._hasBits0; + name_ = other.name_; + number_ = other.number_; + options_ = other.options_ != null ? other.options_.Clone() : null; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValueDescriptorProto Clone() { + return new EnumValueDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "number" field. + public const int NumberFieldNumber = 2; + private readonly static int NumberDefaultValue = 0; + + private int number_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Number { + get { if ((_hasBits0 & 1) != 0) { return number_; } else { return NumberDefaultValue; } } + set { + _hasBits0 |= 1; + number_ = value; + } + } + /// Gets whether the "number" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasNumber { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "number" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNumber() { + _hasBits0 &= ~1; + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private global::LC.Google.Protobuf.Reflection.EnumValueOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.EnumValueOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EnumValueDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EnumValueDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Number != other.Number) return false; + if (!object.Equals(Options, other.Options)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + if (HasNumber) hash ^= Number.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasNumber) { + output.WriteRawTag(16); + output.WriteInt32(Number); + } + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasNumber) { + output.WriteRawTag(16); + output.WriteInt32(Number); + } + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (HasNumber) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number); + } + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EnumValueDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + if (other.HasNumber) { + Number = other.Number; + } + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.EnumValueOptions(); + } + Options.MergeFrom(other.Options); + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Number = input.ReadInt32(); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.EnumValueOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Number = input.ReadInt32(); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.EnumValueOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + + } + + /// + /// Describes a service. + /// + public sealed partial class ServiceDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ServiceDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[8]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ServiceDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ServiceDescriptorProto(ServiceDescriptorProto other) : this() { + name_ = other.name_; + method_ = other.method_.Clone(); + options_ = other.options_ != null ? other.options_.Clone() : null; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ServiceDescriptorProto Clone() { + return new ServiceDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "method" field. + public const int MethodFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_method_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.Reflection.MethodDescriptorProto.Parser); + private readonly pbc::RepeatedField method_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Method { + get { return method_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private global::LC.Google.Protobuf.Reflection.ServiceOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.ServiceOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ServiceDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ServiceDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!method_.Equals(other.method_)) return false; + if (!object.Equals(Options, other.Options)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + hash ^= method_.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + method_.WriteTo(output, _repeated_method_codec); + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + method_.WriteTo(ref output, _repeated_method_codec); + if (options_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += method_.CalculateSize(_repeated_method_codec); + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ServiceDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + method_.Add(other.method_); + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.ServiceOptions(); + } + Options.MergeFrom(other.Options); + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + method_.AddEntriesFrom(input, _repeated_method_codec); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.ServiceOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + method_.AddEntriesFrom(ref input, _repeated_method_codec); + break; + } + case 26: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.ServiceOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + + } + + /// + /// Describes a method of a service. + /// + public sealed partial class MethodDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MethodDescriptorProto()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[9]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MethodDescriptorProto() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MethodDescriptorProto(MethodDescriptorProto other) : this() { + _hasBits0 = other._hasBits0; + name_ = other.name_; + inputType_ = other.inputType_; + outputType_ = other.outputType_; + options_ = other.options_ != null ? other.options_.Clone() : null; + clientStreaming_ = other.clientStreaming_; + serverStreaming_ = other.serverStreaming_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MethodDescriptorProto Clone() { + return new MethodDescriptorProto(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private readonly static string NameDefaultValue = ""; + + private string name_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_ ?? NameDefaultValue; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasName { + get { return name_ != null; } + } + /// Clears the value of the "name" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearName() { + name_ = null; + } + + /// Field number for the "input_type" field. + public const int InputTypeFieldNumber = 2; + private readonly static string InputTypeDefaultValue = ""; + + private string inputType_; + /// + /// Input and output type names. These are resolved in the same way as + /// FieldDescriptorProto.type_name, but must refer to a message type. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string InputType { + get { return inputType_ ?? InputTypeDefaultValue; } + set { + inputType_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "input_type" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasInputType { + get { return inputType_ != null; } + } + /// Clears the value of the "input_type" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearInputType() { + inputType_ = null; + } + + /// Field number for the "output_type" field. + public const int OutputTypeFieldNumber = 3; + private readonly static string OutputTypeDefaultValue = ""; + + private string outputType_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string OutputType { + get { return outputType_ ?? OutputTypeDefaultValue; } + set { + outputType_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "output_type" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasOutputType { + get { return outputType_ != null; } + } + /// Clears the value of the "output_type" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearOutputType() { + outputType_ = null; + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 4; + private global::LC.Google.Protobuf.Reflection.MethodOptions options_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.MethodOptions Options { + get { return options_; } + set { + options_ = value; + } + } + + /// Field number for the "client_streaming" field. + public const int ClientStreamingFieldNumber = 5; + private readonly static bool ClientStreamingDefaultValue = false; + + private bool clientStreaming_; + /// + /// Identifies if client streams multiple client messages + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool ClientStreaming { + get { if ((_hasBits0 & 1) != 0) { return clientStreaming_; } else { return ClientStreamingDefaultValue; } } + set { + _hasBits0 |= 1; + clientStreaming_ = value; + } + } + /// Gets whether the "client_streaming" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasClientStreaming { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "client_streaming" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearClientStreaming() { + _hasBits0 &= ~1; + } + + /// Field number for the "server_streaming" field. + public const int ServerStreamingFieldNumber = 6; + private readonly static bool ServerStreamingDefaultValue = false; + + private bool serverStreaming_; + /// + /// Identifies if server streams multiple server messages + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool ServerStreaming { + get { if ((_hasBits0 & 2) != 0) { return serverStreaming_; } else { return ServerStreamingDefaultValue; } } + set { + _hasBits0 |= 2; + serverStreaming_ = value; + } + } + /// Gets whether the "server_streaming" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasServerStreaming { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "server_streaming" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearServerStreaming() { + _hasBits0 &= ~2; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as MethodDescriptorProto); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(MethodDescriptorProto other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (InputType != other.InputType) return false; + if (OutputType != other.OutputType) return false; + if (!object.Equals(Options, other.Options)) return false; + if (ClientStreaming != other.ClientStreaming) return false; + if (ServerStreaming != other.ServerStreaming) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasName) hash ^= Name.GetHashCode(); + if (HasInputType) hash ^= InputType.GetHashCode(); + if (HasOutputType) hash ^= OutputType.GetHashCode(); + if (options_ != null) hash ^= Options.GetHashCode(); + if (HasClientStreaming) hash ^= ClientStreaming.GetHashCode(); + if (HasServerStreaming) hash ^= ServerStreaming.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasInputType) { + output.WriteRawTag(18); + output.WriteString(InputType); + } + if (HasOutputType) { + output.WriteRawTag(26); + output.WriteString(OutputType); + } + if (options_ != null) { + output.WriteRawTag(34); + output.WriteMessage(Options); + } + if (HasClientStreaming) { + output.WriteRawTag(40); + output.WriteBool(ClientStreaming); + } + if (HasServerStreaming) { + output.WriteRawTag(48); + output.WriteBool(ServerStreaming); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasInputType) { + output.WriteRawTag(18); + output.WriteString(InputType); + } + if (HasOutputType) { + output.WriteRawTag(26); + output.WriteString(OutputType); + } + if (options_ != null) { + output.WriteRawTag(34); + output.WriteMessage(Options); + } + if (HasClientStreaming) { + output.WriteRawTag(40); + output.WriteBool(ClientStreaming); + } + if (HasServerStreaming) { + output.WriteRawTag(48); + output.WriteBool(ServerStreaming); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasName) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (HasInputType) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(InputType); + } + if (HasOutputType) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(OutputType); + } + if (options_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); + } + if (HasClientStreaming) { + size += 1 + 1; + } + if (HasServerStreaming) { + size += 1 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(MethodDescriptorProto other) { + if (other == null) { + return; + } + if (other.HasName) { + Name = other.Name; + } + if (other.HasInputType) { + InputType = other.InputType; + } + if (other.HasOutputType) { + OutputType = other.OutputType; + } + if (other.options_ != null) { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.MethodOptions(); + } + Options.MergeFrom(other.Options); + } + if (other.HasClientStreaming) { + ClientStreaming = other.ClientStreaming; + } + if (other.HasServerStreaming) { + ServerStreaming = other.ServerStreaming; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + InputType = input.ReadString(); + break; + } + case 26: { + OutputType = input.ReadString(); + break; + } + case 34: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.MethodOptions(); + } + input.ReadMessage(Options); + break; + } + case 40: { + ClientStreaming = input.ReadBool(); + break; + } + case 48: { + ServerStreaming = input.ReadBool(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + InputType = input.ReadString(); + break; + } + case 26: { + OutputType = input.ReadString(); + break; + } + case 34: { + if (options_ == null) { + Options = new global::LC.Google.Protobuf.Reflection.MethodOptions(); + } + input.ReadMessage(Options); + break; + } + case 40: { + ClientStreaming = input.ReadBool(); + break; + } + case 48: { + ServerStreaming = input.ReadBool(); + break; + } + } + } + } + #endif + + } + + public sealed partial class FileOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[10]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileOptions(FileOptions other) : this() { + _hasBits0 = other._hasBits0; + javaPackage_ = other.javaPackage_; + javaOuterClassname_ = other.javaOuterClassname_; + javaMultipleFiles_ = other.javaMultipleFiles_; + javaGenerateEqualsAndHash_ = other.javaGenerateEqualsAndHash_; + javaStringCheckUtf8_ = other.javaStringCheckUtf8_; + optimizeFor_ = other.optimizeFor_; + goPackage_ = other.goPackage_; + ccGenericServices_ = other.ccGenericServices_; + javaGenericServices_ = other.javaGenericServices_; + pyGenericServices_ = other.pyGenericServices_; + phpGenericServices_ = other.phpGenericServices_; + deprecated_ = other.deprecated_; + ccEnableArenas_ = other.ccEnableArenas_; + objcClassPrefix_ = other.objcClassPrefix_; + csharpNamespace_ = other.csharpNamespace_; + swiftPrefix_ = other.swiftPrefix_; + phpClassPrefix_ = other.phpClassPrefix_; + phpNamespace_ = other.phpNamespace_; + phpMetadataNamespace_ = other.phpMetadataNamespace_; + rubyPackage_ = other.rubyPackage_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FileOptions Clone() { + return new FileOptions(this); + } + + /// Field number for the "java_package" field. + public const int JavaPackageFieldNumber = 1; + private readonly static string JavaPackageDefaultValue = ""; + + private string javaPackage_; + /// + /// Sets the Java package where classes generated from this .proto will be + /// placed. By default, the proto package is used, but this is often + /// inappropriate because proto packages do not normally start with backwards + /// domain names. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string JavaPackage { + get { return javaPackage_ ?? JavaPackageDefaultValue; } + set { + javaPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "java_package" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJavaPackage { + get { return javaPackage_ != null; } + } + /// Clears the value of the "java_package" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJavaPackage() { + javaPackage_ = null; + } + + /// Field number for the "java_outer_classname" field. + public const int JavaOuterClassnameFieldNumber = 8; + private readonly static string JavaOuterClassnameDefaultValue = ""; + + private string javaOuterClassname_; + /// + /// If set, all the classes from the .proto file are wrapped in a single + /// outer class with the given name. This applies to both Proto1 + /// (equivalent to the old "--one_java_file" option) and Proto2 (where + /// a .proto always translates to a single class, but you may want to + /// explicitly choose the class name). + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string JavaOuterClassname { + get { return javaOuterClassname_ ?? JavaOuterClassnameDefaultValue; } + set { + javaOuterClassname_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "java_outer_classname" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJavaOuterClassname { + get { return javaOuterClassname_ != null; } + } + /// Clears the value of the "java_outer_classname" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJavaOuterClassname() { + javaOuterClassname_ = null; + } + + /// Field number for the "java_multiple_files" field. + public const int JavaMultipleFilesFieldNumber = 10; + private readonly static bool JavaMultipleFilesDefaultValue = false; + + private bool javaMultipleFiles_; + /// + /// If set true, then the Java code generator will generate a separate .java + /// file for each top-level message, enum, and service defined in the .proto + /// file. Thus, these types will *not* be nested inside the outer class + /// named by java_outer_classname. However, the outer class will still be + /// generated to contain the file's getDescriptor() method as well as any + /// top-level extensions defined in the file. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool JavaMultipleFiles { + get { if ((_hasBits0 & 2) != 0) { return javaMultipleFiles_; } else { return JavaMultipleFilesDefaultValue; } } + set { + _hasBits0 |= 2; + javaMultipleFiles_ = value; + } + } + /// Gets whether the "java_multiple_files" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJavaMultipleFiles { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "java_multiple_files" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJavaMultipleFiles() { + _hasBits0 &= ~2; + } + + /// Field number for the "java_generate_equals_and_hash" field. + public const int JavaGenerateEqualsAndHashFieldNumber = 20; + private readonly static bool JavaGenerateEqualsAndHashDefaultValue = false; + + private bool javaGenerateEqualsAndHash_; + /// + /// This option does nothing. + /// + [global::System.ObsoleteAttribute] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool JavaGenerateEqualsAndHash { + get { if ((_hasBits0 & 32) != 0) { return javaGenerateEqualsAndHash_; } else { return JavaGenerateEqualsAndHashDefaultValue; } } + set { + _hasBits0 |= 32; + javaGenerateEqualsAndHash_ = value; + } + } + /// Gets whether the "java_generate_equals_and_hash" field is set + [global::System.ObsoleteAttribute] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJavaGenerateEqualsAndHash { + get { return (_hasBits0 & 32) != 0; } + } + /// Clears the value of the "java_generate_equals_and_hash" field + [global::System.ObsoleteAttribute] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJavaGenerateEqualsAndHash() { + _hasBits0 &= ~32; + } + + /// Field number for the "java_string_check_utf8" field. + public const int JavaStringCheckUtf8FieldNumber = 27; + private readonly static bool JavaStringCheckUtf8DefaultValue = false; + + private bool javaStringCheckUtf8_; + /// + /// If set true, then the Java2 code generator will generate code that + /// throws an exception whenever an attempt is made to assign a non-UTF-8 + /// byte sequence to a string field. + /// Message reflection will do the same. + /// However, an extension field still accepts non-UTF-8 byte sequences. + /// This option has no effect on when used with the lite runtime. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool JavaStringCheckUtf8 { + get { if ((_hasBits0 & 128) != 0) { return javaStringCheckUtf8_; } else { return JavaStringCheckUtf8DefaultValue; } } + set { + _hasBits0 |= 128; + javaStringCheckUtf8_ = value; + } + } + /// Gets whether the "java_string_check_utf8" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJavaStringCheckUtf8 { + get { return (_hasBits0 & 128) != 0; } + } + /// Clears the value of the "java_string_check_utf8" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJavaStringCheckUtf8() { + _hasBits0 &= ~128; + } + + /// Field number for the "optimize_for" field. + public const int OptimizeForFieldNumber = 9; + private readonly static global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode OptimizeForDefaultValue = global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode.Speed; + + private global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode optimizeFor_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode OptimizeFor { + get { if ((_hasBits0 & 1) != 0) { return optimizeFor_; } else { return OptimizeForDefaultValue; } } + set { + _hasBits0 |= 1; + optimizeFor_ = value; + } + } + /// Gets whether the "optimize_for" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasOptimizeFor { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "optimize_for" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearOptimizeFor() { + _hasBits0 &= ~1; + } + + /// Field number for the "go_package" field. + public const int GoPackageFieldNumber = 11; + private readonly static string GoPackageDefaultValue = ""; + + private string goPackage_; + /// + /// Sets the Go package where structs generated from this .proto will be + /// placed. If omitted, the Go package will be derived from the following: + /// - The basename of the package import path, if provided. + /// - Otherwise, the package statement in the .proto file, if present. + /// - Otherwise, the basename of the .proto file, without extension. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string GoPackage { + get { return goPackage_ ?? GoPackageDefaultValue; } + set { + goPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "go_package" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasGoPackage { + get { return goPackage_ != null; } + } + /// Clears the value of the "go_package" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearGoPackage() { + goPackage_ = null; + } + + /// Field number for the "cc_generic_services" field. + public const int CcGenericServicesFieldNumber = 16; + private readonly static bool CcGenericServicesDefaultValue = false; + + private bool ccGenericServices_; + /// + /// Should generic services be generated in each language? "Generic" services + /// are not specific to any particular RPC system. They are generated by the + /// main code generators in each language (without additional plugins). + /// Generic services were the only kind of service generation supported by + /// early versions of google.protobuf. + /// + /// Generic services are now considered deprecated in favor of using plugins + /// that generate code specific to your particular RPC system. Therefore, + /// these default to false. Old code which depends on generic services should + /// explicitly set them to true. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool CcGenericServices { + get { if ((_hasBits0 & 4) != 0) { return ccGenericServices_; } else { return CcGenericServicesDefaultValue; } } + set { + _hasBits0 |= 4; + ccGenericServices_ = value; + } + } + /// Gets whether the "cc_generic_services" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasCcGenericServices { + get { return (_hasBits0 & 4) != 0; } + } + /// Clears the value of the "cc_generic_services" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearCcGenericServices() { + _hasBits0 &= ~4; + } + + /// Field number for the "java_generic_services" field. + public const int JavaGenericServicesFieldNumber = 17; + private readonly static bool JavaGenericServicesDefaultValue = false; + + private bool javaGenericServices_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool JavaGenericServices { + get { if ((_hasBits0 & 8) != 0) { return javaGenericServices_; } else { return JavaGenericServicesDefaultValue; } } + set { + _hasBits0 |= 8; + javaGenericServices_ = value; + } + } + /// Gets whether the "java_generic_services" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJavaGenericServices { + get { return (_hasBits0 & 8) != 0; } + } + /// Clears the value of the "java_generic_services" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJavaGenericServices() { + _hasBits0 &= ~8; + } + + /// Field number for the "py_generic_services" field. + public const int PyGenericServicesFieldNumber = 18; + private readonly static bool PyGenericServicesDefaultValue = false; + + private bool pyGenericServices_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool PyGenericServices { + get { if ((_hasBits0 & 16) != 0) { return pyGenericServices_; } else { return PyGenericServicesDefaultValue; } } + set { + _hasBits0 |= 16; + pyGenericServices_ = value; + } + } + /// Gets whether the "py_generic_services" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPyGenericServices { + get { return (_hasBits0 & 16) != 0; } + } + /// Clears the value of the "py_generic_services" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPyGenericServices() { + _hasBits0 &= ~16; + } + + /// Field number for the "php_generic_services" field. + public const int PhpGenericServicesFieldNumber = 42; + private readonly static bool PhpGenericServicesDefaultValue = false; + + private bool phpGenericServices_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool PhpGenericServices { + get { if ((_hasBits0 & 512) != 0) { return phpGenericServices_; } else { return PhpGenericServicesDefaultValue; } } + set { + _hasBits0 |= 512; + phpGenericServices_ = value; + } + } + /// Gets whether the "php_generic_services" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPhpGenericServices { + get { return (_hasBits0 & 512) != 0; } + } + /// Clears the value of the "php_generic_services" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPhpGenericServices() { + _hasBits0 &= ~512; + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 23; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this file deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for everything in the file, or it will be completely ignored; in the very + /// least, this is a formalization for deprecating files. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 64) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 64; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 64) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~64; + } + + /// Field number for the "cc_enable_arenas" field. + public const int CcEnableArenasFieldNumber = 31; + private readonly static bool CcEnableArenasDefaultValue = true; + + private bool ccEnableArenas_; + /// + /// Enables the use of arenas for the proto messages in this file. This applies + /// only to generated classes for C++. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool CcEnableArenas { + get { if ((_hasBits0 & 256) != 0) { return ccEnableArenas_; } else { return CcEnableArenasDefaultValue; } } + set { + _hasBits0 |= 256; + ccEnableArenas_ = value; + } + } + /// Gets whether the "cc_enable_arenas" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasCcEnableArenas { + get { return (_hasBits0 & 256) != 0; } + } + /// Clears the value of the "cc_enable_arenas" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearCcEnableArenas() { + _hasBits0 &= ~256; + } + + /// Field number for the "objc_class_prefix" field. + public const int ObjcClassPrefixFieldNumber = 36; + private readonly static string ObjcClassPrefixDefaultValue = ""; + + private string objcClassPrefix_; + /// + /// Sets the objective c class prefix which is prepended to all objective c + /// generated classes from this .proto. There is no default. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ObjcClassPrefix { + get { return objcClassPrefix_ ?? ObjcClassPrefixDefaultValue; } + set { + objcClassPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "objc_class_prefix" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasObjcClassPrefix { + get { return objcClassPrefix_ != null; } + } + /// Clears the value of the "objc_class_prefix" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearObjcClassPrefix() { + objcClassPrefix_ = null; + } + + /// Field number for the "csharp_namespace" field. + public const int CsharpNamespaceFieldNumber = 37; + private readonly static string CsharpNamespaceDefaultValue = ""; + + private string csharpNamespace_; + /// + /// Namespace for generated classes; defaults to the package. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string CsharpNamespace { + get { return csharpNamespace_ ?? CsharpNamespaceDefaultValue; } + set { + csharpNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "csharp_namespace" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasCsharpNamespace { + get { return csharpNamespace_ != null; } + } + /// Clears the value of the "csharp_namespace" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearCsharpNamespace() { + csharpNamespace_ = null; + } + + /// Field number for the "swift_prefix" field. + public const int SwiftPrefixFieldNumber = 39; + private readonly static string SwiftPrefixDefaultValue = ""; + + private string swiftPrefix_; + /// + /// By default Swift generators will take the proto package and CamelCase it + /// replacing '.' with underscore and use that to prefix the types/symbols + /// defined. When this options is provided, they will use this value instead + /// to prefix the types/symbols defined. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string SwiftPrefix { + get { return swiftPrefix_ ?? SwiftPrefixDefaultValue; } + set { + swiftPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "swift_prefix" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasSwiftPrefix { + get { return swiftPrefix_ != null; } + } + /// Clears the value of the "swift_prefix" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearSwiftPrefix() { + swiftPrefix_ = null; + } + + /// Field number for the "php_class_prefix" field. + public const int PhpClassPrefixFieldNumber = 40; + private readonly static string PhpClassPrefixDefaultValue = ""; + + private string phpClassPrefix_; + /// + /// Sets the php class prefix which is prepended to all php generated classes + /// from this .proto. Default is empty. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string PhpClassPrefix { + get { return phpClassPrefix_ ?? PhpClassPrefixDefaultValue; } + set { + phpClassPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "php_class_prefix" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPhpClassPrefix { + get { return phpClassPrefix_ != null; } + } + /// Clears the value of the "php_class_prefix" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPhpClassPrefix() { + phpClassPrefix_ = null; + } + + /// Field number for the "php_namespace" field. + public const int PhpNamespaceFieldNumber = 41; + private readonly static string PhpNamespaceDefaultValue = ""; + + private string phpNamespace_; + /// + /// Use this option to change the namespace of php generated classes. Default + /// is empty. When this option is empty, the package name will be used for + /// determining the namespace. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string PhpNamespace { + get { return phpNamespace_ ?? PhpNamespaceDefaultValue; } + set { + phpNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "php_namespace" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPhpNamespace { + get { return phpNamespace_ != null; } + } + /// Clears the value of the "php_namespace" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPhpNamespace() { + phpNamespace_ = null; + } + + /// Field number for the "php_metadata_namespace" field. + public const int PhpMetadataNamespaceFieldNumber = 44; + private readonly static string PhpMetadataNamespaceDefaultValue = ""; + + private string phpMetadataNamespace_; + /// + /// Use this option to change the namespace of php generated metadata classes. + /// Default is empty. When this option is empty, the proto file name will be + /// used for determining the namespace. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string PhpMetadataNamespace { + get { return phpMetadataNamespace_ ?? PhpMetadataNamespaceDefaultValue; } + set { + phpMetadataNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "php_metadata_namespace" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPhpMetadataNamespace { + get { return phpMetadataNamespace_ != null; } + } + /// Clears the value of the "php_metadata_namespace" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPhpMetadataNamespace() { + phpMetadataNamespace_ = null; + } + + /// Field number for the "ruby_package" field. + public const int RubyPackageFieldNumber = 45; + private readonly static string RubyPackageDefaultValue = ""; + + private string rubyPackage_; + /// + /// Use this option to change the package of ruby generated classes. Default + /// is empty. When this option is not set, the package name will be used for + /// determining the ruby package. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string RubyPackage { + get { return rubyPackage_ ?? RubyPackageDefaultValue; } + set { + rubyPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "ruby_package" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasRubyPackage { + get { return rubyPackage_ != null; } + } + /// Clears the value of the "ruby_package" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearRubyPackage() { + rubyPackage_ = null; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. + /// See the documentation for the "Options" section above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FileOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FileOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (JavaPackage != other.JavaPackage) return false; + if (JavaOuterClassname != other.JavaOuterClassname) return false; + if (JavaMultipleFiles != other.JavaMultipleFiles) return false; + if (JavaGenerateEqualsAndHash != other.JavaGenerateEqualsAndHash) return false; + if (JavaStringCheckUtf8 != other.JavaStringCheckUtf8) return false; + if (OptimizeFor != other.OptimizeFor) return false; + if (GoPackage != other.GoPackage) return false; + if (CcGenericServices != other.CcGenericServices) return false; + if (JavaGenericServices != other.JavaGenericServices) return false; + if (PyGenericServices != other.PyGenericServices) return false; + if (PhpGenericServices != other.PhpGenericServices) return false; + if (Deprecated != other.Deprecated) return false; + if (CcEnableArenas != other.CcEnableArenas) return false; + if (ObjcClassPrefix != other.ObjcClassPrefix) return false; + if (CsharpNamespace != other.CsharpNamespace) return false; + if (SwiftPrefix != other.SwiftPrefix) return false; + if (PhpClassPrefix != other.PhpClassPrefix) return false; + if (PhpNamespace != other.PhpNamespace) return false; + if (PhpMetadataNamespace != other.PhpMetadataNamespace) return false; + if (RubyPackage != other.RubyPackage) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasJavaPackage) hash ^= JavaPackage.GetHashCode(); + if (HasJavaOuterClassname) hash ^= JavaOuterClassname.GetHashCode(); + if (HasJavaMultipleFiles) hash ^= JavaMultipleFiles.GetHashCode(); + if (HasJavaGenerateEqualsAndHash) hash ^= JavaGenerateEqualsAndHash.GetHashCode(); + if (HasJavaStringCheckUtf8) hash ^= JavaStringCheckUtf8.GetHashCode(); + if (HasOptimizeFor) hash ^= OptimizeFor.GetHashCode(); + if (HasGoPackage) hash ^= GoPackage.GetHashCode(); + if (HasCcGenericServices) hash ^= CcGenericServices.GetHashCode(); + if (HasJavaGenericServices) hash ^= JavaGenericServices.GetHashCode(); + if (HasPyGenericServices) hash ^= PyGenericServices.GetHashCode(); + if (HasPhpGenericServices) hash ^= PhpGenericServices.GetHashCode(); + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + if (HasCcEnableArenas) hash ^= CcEnableArenas.GetHashCode(); + if (HasObjcClassPrefix) hash ^= ObjcClassPrefix.GetHashCode(); + if (HasCsharpNamespace) hash ^= CsharpNamespace.GetHashCode(); + if (HasSwiftPrefix) hash ^= SwiftPrefix.GetHashCode(); + if (HasPhpClassPrefix) hash ^= PhpClassPrefix.GetHashCode(); + if (HasPhpNamespace) hash ^= PhpNamespace.GetHashCode(); + if (HasPhpMetadataNamespace) hash ^= PhpMetadataNamespace.GetHashCode(); + if (HasRubyPackage) hash ^= RubyPackage.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasJavaPackage) { + output.WriteRawTag(10); + output.WriteString(JavaPackage); + } + if (HasJavaOuterClassname) { + output.WriteRawTag(66); + output.WriteString(JavaOuterClassname); + } + if (HasOptimizeFor) { + output.WriteRawTag(72); + output.WriteEnum((int) OptimizeFor); + } + if (HasJavaMultipleFiles) { + output.WriteRawTag(80); + output.WriteBool(JavaMultipleFiles); + } + if (HasGoPackage) { + output.WriteRawTag(90); + output.WriteString(GoPackage); + } + if (HasCcGenericServices) { + output.WriteRawTag(128, 1); + output.WriteBool(CcGenericServices); + } + if (HasJavaGenericServices) { + output.WriteRawTag(136, 1); + output.WriteBool(JavaGenericServices); + } + if (HasPyGenericServices) { + output.WriteRawTag(144, 1); + output.WriteBool(PyGenericServices); + } + if (HasJavaGenerateEqualsAndHash) { + output.WriteRawTag(160, 1); + output.WriteBool(JavaGenerateEqualsAndHash); + } + if (HasDeprecated) { + output.WriteRawTag(184, 1); + output.WriteBool(Deprecated); + } + if (HasJavaStringCheckUtf8) { + output.WriteRawTag(216, 1); + output.WriteBool(JavaStringCheckUtf8); + } + if (HasCcEnableArenas) { + output.WriteRawTag(248, 1); + output.WriteBool(CcEnableArenas); + } + if (HasObjcClassPrefix) { + output.WriteRawTag(162, 2); + output.WriteString(ObjcClassPrefix); + } + if (HasCsharpNamespace) { + output.WriteRawTag(170, 2); + output.WriteString(CsharpNamespace); + } + if (HasSwiftPrefix) { + output.WriteRawTag(186, 2); + output.WriteString(SwiftPrefix); + } + if (HasPhpClassPrefix) { + output.WriteRawTag(194, 2); + output.WriteString(PhpClassPrefix); + } + if (HasPhpNamespace) { + output.WriteRawTag(202, 2); + output.WriteString(PhpNamespace); + } + if (HasPhpGenericServices) { + output.WriteRawTag(208, 2); + output.WriteBool(PhpGenericServices); + } + if (HasPhpMetadataNamespace) { + output.WriteRawTag(226, 2); + output.WriteString(PhpMetadataNamespace); + } + if (HasRubyPackage) { + output.WriteRawTag(234, 2); + output.WriteString(RubyPackage); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasJavaPackage) { + output.WriteRawTag(10); + output.WriteString(JavaPackage); + } + if (HasJavaOuterClassname) { + output.WriteRawTag(66); + output.WriteString(JavaOuterClassname); + } + if (HasOptimizeFor) { + output.WriteRawTag(72); + output.WriteEnum((int) OptimizeFor); + } + if (HasJavaMultipleFiles) { + output.WriteRawTag(80); + output.WriteBool(JavaMultipleFiles); + } + if (HasGoPackage) { + output.WriteRawTag(90); + output.WriteString(GoPackage); + } + if (HasCcGenericServices) { + output.WriteRawTag(128, 1); + output.WriteBool(CcGenericServices); + } + if (HasJavaGenericServices) { + output.WriteRawTag(136, 1); + output.WriteBool(JavaGenericServices); + } + if (HasPyGenericServices) { + output.WriteRawTag(144, 1); + output.WriteBool(PyGenericServices); + } + if (HasJavaGenerateEqualsAndHash) { + output.WriteRawTag(160, 1); + output.WriteBool(JavaGenerateEqualsAndHash); + } + if (HasDeprecated) { + output.WriteRawTag(184, 1); + output.WriteBool(Deprecated); + } + if (HasJavaStringCheckUtf8) { + output.WriteRawTag(216, 1); + output.WriteBool(JavaStringCheckUtf8); + } + if (HasCcEnableArenas) { + output.WriteRawTag(248, 1); + output.WriteBool(CcEnableArenas); + } + if (HasObjcClassPrefix) { + output.WriteRawTag(162, 2); + output.WriteString(ObjcClassPrefix); + } + if (HasCsharpNamespace) { + output.WriteRawTag(170, 2); + output.WriteString(CsharpNamespace); + } + if (HasSwiftPrefix) { + output.WriteRawTag(186, 2); + output.WriteString(SwiftPrefix); + } + if (HasPhpClassPrefix) { + output.WriteRawTag(194, 2); + output.WriteString(PhpClassPrefix); + } + if (HasPhpNamespace) { + output.WriteRawTag(202, 2); + output.WriteString(PhpNamespace); + } + if (HasPhpGenericServices) { + output.WriteRawTag(208, 2); + output.WriteBool(PhpGenericServices); + } + if (HasPhpMetadataNamespace) { + output.WriteRawTag(226, 2); + output.WriteString(PhpMetadataNamespace); + } + if (HasRubyPackage) { + output.WriteRawTag(234, 2); + output.WriteString(RubyPackage); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasJavaPackage) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JavaPackage); + } + if (HasJavaOuterClassname) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JavaOuterClassname); + } + if (HasJavaMultipleFiles) { + size += 1 + 1; + } + if (HasJavaGenerateEqualsAndHash) { + size += 2 + 1; + } + if (HasJavaStringCheckUtf8) { + size += 2 + 1; + } + if (HasOptimizeFor) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) OptimizeFor); + } + if (HasGoPackage) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(GoPackage); + } + if (HasCcGenericServices) { + size += 2 + 1; + } + if (HasJavaGenericServices) { + size += 2 + 1; + } + if (HasPyGenericServices) { + size += 2 + 1; + } + if (HasPhpGenericServices) { + size += 2 + 1; + } + if (HasDeprecated) { + size += 2 + 1; + } + if (HasCcEnableArenas) { + size += 2 + 1; + } + if (HasObjcClassPrefix) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(ObjcClassPrefix); + } + if (HasCsharpNamespace) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(CsharpNamespace); + } + if (HasSwiftPrefix) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(SwiftPrefix); + } + if (HasPhpClassPrefix) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpClassPrefix); + } + if (HasPhpNamespace) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpNamespace); + } + if (HasPhpMetadataNamespace) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpMetadataNamespace); + } + if (HasRubyPackage) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(RubyPackage); + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FileOptions other) { + if (other == null) { + return; + } + if (other.HasJavaPackage) { + JavaPackage = other.JavaPackage; + } + if (other.HasJavaOuterClassname) { + JavaOuterClassname = other.JavaOuterClassname; + } + if (other.HasJavaMultipleFiles) { + JavaMultipleFiles = other.JavaMultipleFiles; + } + if (other.HasJavaGenerateEqualsAndHash) { + JavaGenerateEqualsAndHash = other.JavaGenerateEqualsAndHash; + } + if (other.HasJavaStringCheckUtf8) { + JavaStringCheckUtf8 = other.JavaStringCheckUtf8; + } + if (other.HasOptimizeFor) { + OptimizeFor = other.OptimizeFor; + } + if (other.HasGoPackage) { + GoPackage = other.GoPackage; + } + if (other.HasCcGenericServices) { + CcGenericServices = other.CcGenericServices; + } + if (other.HasJavaGenericServices) { + JavaGenericServices = other.JavaGenericServices; + } + if (other.HasPyGenericServices) { + PyGenericServices = other.PyGenericServices; + } + if (other.HasPhpGenericServices) { + PhpGenericServices = other.PhpGenericServices; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + if (other.HasCcEnableArenas) { + CcEnableArenas = other.CcEnableArenas; + } + if (other.HasObjcClassPrefix) { + ObjcClassPrefix = other.ObjcClassPrefix; + } + if (other.HasCsharpNamespace) { + CsharpNamespace = other.CsharpNamespace; + } + if (other.HasSwiftPrefix) { + SwiftPrefix = other.SwiftPrefix; + } + if (other.HasPhpClassPrefix) { + PhpClassPrefix = other.PhpClassPrefix; + } + if (other.HasPhpNamespace) { + PhpNamespace = other.PhpNamespace; + } + if (other.HasPhpMetadataNamespace) { + PhpMetadataNamespace = other.PhpMetadataNamespace; + } + if (other.HasRubyPackage) { + RubyPackage = other.RubyPackage; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 10: { + JavaPackage = input.ReadString(); + break; + } + case 66: { + JavaOuterClassname = input.ReadString(); + break; + } + case 72: { + OptimizeFor = (global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) input.ReadEnum(); + break; + } + case 80: { + JavaMultipleFiles = input.ReadBool(); + break; + } + case 90: { + GoPackage = input.ReadString(); + break; + } + case 128: { + CcGenericServices = input.ReadBool(); + break; + } + case 136: { + JavaGenericServices = input.ReadBool(); + break; + } + case 144: { + PyGenericServices = input.ReadBool(); + break; + } + case 160: { + JavaGenerateEqualsAndHash = input.ReadBool(); + break; + } + case 184: { + Deprecated = input.ReadBool(); + break; + } + case 216: { + JavaStringCheckUtf8 = input.ReadBool(); + break; + } + case 248: { + CcEnableArenas = input.ReadBool(); + break; + } + case 290: { + ObjcClassPrefix = input.ReadString(); + break; + } + case 298: { + CsharpNamespace = input.ReadString(); + break; + } + case 314: { + SwiftPrefix = input.ReadString(); + break; + } + case 322: { + PhpClassPrefix = input.ReadString(); + break; + } + case 330: { + PhpNamespace = input.ReadString(); + break; + } + case 336: { + PhpGenericServices = input.ReadBool(); + break; + } + case 354: { + PhpMetadataNamespace = input.ReadString(); + break; + } + case 362: { + RubyPackage = input.ReadString(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 10: { + JavaPackage = input.ReadString(); + break; + } + case 66: { + JavaOuterClassname = input.ReadString(); + break; + } + case 72: { + OptimizeFor = (global::LC.Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) input.ReadEnum(); + break; + } + case 80: { + JavaMultipleFiles = input.ReadBool(); + break; + } + case 90: { + GoPackage = input.ReadString(); + break; + } + case 128: { + CcGenericServices = input.ReadBool(); + break; + } + case 136: { + JavaGenericServices = input.ReadBool(); + break; + } + case 144: { + PyGenericServices = input.ReadBool(); + break; + } + case 160: { + JavaGenerateEqualsAndHash = input.ReadBool(); + break; + } + case 184: { + Deprecated = input.ReadBool(); + break; + } + case 216: { + JavaStringCheckUtf8 = input.ReadBool(); + break; + } + case 248: { + CcEnableArenas = input.ReadBool(); + break; + } + case 290: { + ObjcClassPrefix = input.ReadString(); + break; + } + case 298: { + CsharpNamespace = input.ReadString(); + break; + } + case 314: { + SwiftPrefix = input.ReadString(); + break; + } + case 322: { + PhpClassPrefix = input.ReadString(); + break; + } + case 330: { + PhpNamespace = input.ReadString(); + break; + } + case 336: { + PhpGenericServices = input.ReadBool(); + break; + } + case 354: { + PhpMetadataNamespace = input.ReadString(); + break; + } + case 362: { + RubyPackage = input.ReadString(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + #region Nested types + /// Container for nested types declared in the FileOptions message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + /// + /// Generated classes can be optimized for speed or code size. + /// + public enum OptimizeMode { + /// + /// Generate complete code for parsing, serialization, + /// + [pbr::OriginalName("SPEED")] Speed = 1, + /// + /// etc. + /// + [pbr::OriginalName("CODE_SIZE")] CodeSize = 2, + /// + /// Generate code using MessageLite and the lite runtime. + /// + [pbr::OriginalName("LITE_RUNTIME")] LiteRuntime = 3, + } + + } + #endregion + + } + + public sealed partial class MessageOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[11]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MessageOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MessageOptions(MessageOptions other) : this() { + _hasBits0 = other._hasBits0; + messageSetWireFormat_ = other.messageSetWireFormat_; + noStandardDescriptorAccessor_ = other.noStandardDescriptorAccessor_; + deprecated_ = other.deprecated_; + mapEntry_ = other.mapEntry_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MessageOptions Clone() { + return new MessageOptions(this); + } + + /// Field number for the "message_set_wire_format" field. + public const int MessageSetWireFormatFieldNumber = 1; + private readonly static bool MessageSetWireFormatDefaultValue = false; + + private bool messageSetWireFormat_; + /// + /// Set true to use the old proto1 MessageSet wire format for extensions. + /// This is provided for backwards-compatibility with the MessageSet wire + /// format. You should not use this for any other reason: It's less + /// efficient, has fewer features, and is more complicated. + /// + /// The message must be defined exactly as follows: + /// message Foo { + /// option message_set_wire_format = true; + /// extensions 4 to max; + /// } + /// Note that the message cannot have any defined fields; MessageSets only + /// have extensions. + /// + /// All extensions of your type must be singular messages; e.g. they cannot + /// be int32s, enums, or repeated messages. + /// + /// Because this is an option, the above two restrictions are not enforced by + /// the protocol compiler. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool MessageSetWireFormat { + get { if ((_hasBits0 & 1) != 0) { return messageSetWireFormat_; } else { return MessageSetWireFormatDefaultValue; } } + set { + _hasBits0 |= 1; + messageSetWireFormat_ = value; + } + } + /// Gets whether the "message_set_wire_format" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasMessageSetWireFormat { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "message_set_wire_format" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearMessageSetWireFormat() { + _hasBits0 &= ~1; + } + + /// Field number for the "no_standard_descriptor_accessor" field. + public const int NoStandardDescriptorAccessorFieldNumber = 2; + private readonly static bool NoStandardDescriptorAccessorDefaultValue = false; + + private bool noStandardDescriptorAccessor_; + /// + /// Disables the generation of the standard "descriptor()" accessor, which can + /// conflict with a field of the same name. This is meant to make migration + /// from proto1 easier; new code should avoid fields named "descriptor". + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool NoStandardDescriptorAccessor { + get { if ((_hasBits0 & 2) != 0) { return noStandardDescriptorAccessor_; } else { return NoStandardDescriptorAccessorDefaultValue; } } + set { + _hasBits0 |= 2; + noStandardDescriptorAccessor_ = value; + } + } + /// Gets whether the "no_standard_descriptor_accessor" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasNoStandardDescriptorAccessor { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "no_standard_descriptor_accessor" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNoStandardDescriptorAccessor() { + _hasBits0 &= ~2; + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 3; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this message deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for the message, or it will be completely ignored; in the very least, + /// this is a formalization for deprecating messages. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 4) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 4; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 4) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~4; + } + + /// Field number for the "map_entry" field. + public const int MapEntryFieldNumber = 7; + private readonly static bool MapEntryDefaultValue = false; + + private bool mapEntry_; + /// + /// Whether the message is an automatically generated map entry type for the + /// maps field. + /// + /// For maps fields: + /// map<KeyType, ValueType> map_field = 1; + /// The parsed descriptor looks like: + /// message MapFieldEntry { + /// option map_entry = true; + /// optional KeyType key = 1; + /// optional ValueType value = 2; + /// } + /// repeated MapFieldEntry map_field = 1; + /// + /// Implementations may choose not to generate the map_entry=true message, but + /// use a native map in the target language to hold the keys and values. + /// The reflection APIs in such implementations still need to work as + /// if the field is a repeated message field. + /// + /// NOTE: Do not set the option in .proto files. Always use the maps syntax + /// instead. The option should only be implicitly set by the proto compiler + /// parser. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool MapEntry { + get { if ((_hasBits0 & 8) != 0) { return mapEntry_; } else { return MapEntryDefaultValue; } } + set { + _hasBits0 |= 8; + mapEntry_ = value; + } + } + /// Gets whether the "map_entry" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasMapEntry { + get { return (_hasBits0 & 8) != 0; } + } + /// Clears the value of the "map_entry" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearMapEntry() { + _hasBits0 &= ~8; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as MessageOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(MessageOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (MessageSetWireFormat != other.MessageSetWireFormat) return false; + if (NoStandardDescriptorAccessor != other.NoStandardDescriptorAccessor) return false; + if (Deprecated != other.Deprecated) return false; + if (MapEntry != other.MapEntry) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasMessageSetWireFormat) hash ^= MessageSetWireFormat.GetHashCode(); + if (HasNoStandardDescriptorAccessor) hash ^= NoStandardDescriptorAccessor.GetHashCode(); + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + if (HasMapEntry) hash ^= MapEntry.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasMessageSetWireFormat) { + output.WriteRawTag(8); + output.WriteBool(MessageSetWireFormat); + } + if (HasNoStandardDescriptorAccessor) { + output.WriteRawTag(16); + output.WriteBool(NoStandardDescriptorAccessor); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + if (HasMapEntry) { + output.WriteRawTag(56); + output.WriteBool(MapEntry); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasMessageSetWireFormat) { + output.WriteRawTag(8); + output.WriteBool(MessageSetWireFormat); + } + if (HasNoStandardDescriptorAccessor) { + output.WriteRawTag(16); + output.WriteBool(NoStandardDescriptorAccessor); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + if (HasMapEntry) { + output.WriteRawTag(56); + output.WriteBool(MapEntry); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasMessageSetWireFormat) { + size += 1 + 1; + } + if (HasNoStandardDescriptorAccessor) { + size += 1 + 1; + } + if (HasDeprecated) { + size += 1 + 1; + } + if (HasMapEntry) { + size += 1 + 1; + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(MessageOptions other) { + if (other == null) { + return; + } + if (other.HasMessageSetWireFormat) { + MessageSetWireFormat = other.MessageSetWireFormat; + } + if (other.HasNoStandardDescriptorAccessor) { + NoStandardDescriptorAccessor = other.NoStandardDescriptorAccessor; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + if (other.HasMapEntry) { + MapEntry = other.MapEntry; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 8: { + MessageSetWireFormat = input.ReadBool(); + break; + } + case 16: { + NoStandardDescriptorAccessor = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 56: { + MapEntry = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + MessageSetWireFormat = input.ReadBool(); + break; + } + case 16: { + NoStandardDescriptorAccessor = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 56: { + MapEntry = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + } + + public sealed partial class FieldOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[12]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldOptions(FieldOptions other) : this() { + _hasBits0 = other._hasBits0; + ctype_ = other.ctype_; + packed_ = other.packed_; + jstype_ = other.jstype_; + lazy_ = other.lazy_; + deprecated_ = other.deprecated_; + weak_ = other.weak_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldOptions Clone() { + return new FieldOptions(this); + } + + /// Field number for the "ctype" field. + public const int CtypeFieldNumber = 1; + private readonly static global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType CtypeDefaultValue = global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType.String; + + private global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType ctype_; + /// + /// The ctype option instructs the C++ code generator to use a different + /// representation of the field than it normally would. See the specific + /// options below. This option is not yet implemented in the open source + /// release -- sorry, we'll try to include it in a future version! + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType Ctype { + get { if ((_hasBits0 & 1) != 0) { return ctype_; } else { return CtypeDefaultValue; } } + set { + _hasBits0 |= 1; + ctype_ = value; + } + } + /// Gets whether the "ctype" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasCtype { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "ctype" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearCtype() { + _hasBits0 &= ~1; + } + + /// Field number for the "packed" field. + public const int PackedFieldNumber = 2; + private readonly static bool PackedDefaultValue = false; + + private bool packed_; + /// + /// The packed option can be enabled for repeated primitive fields to enable + /// a more efficient representation on the wire. Rather than repeatedly + /// writing the tag and type for each element, the entire array is encoded as + /// a single length-delimited blob. In proto3, only explicit setting it to + /// false will avoid using packed encoding. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Packed { + get { if ((_hasBits0 & 2) != 0) { return packed_; } else { return PackedDefaultValue; } } + set { + _hasBits0 |= 2; + packed_ = value; + } + } + /// Gets whether the "packed" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPacked { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "packed" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPacked() { + _hasBits0 &= ~2; + } + + /// Field number for the "jstype" field. + public const int JstypeFieldNumber = 6; + private readonly static global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType JstypeDefaultValue = global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType.JsNormal; + + private global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType jstype_; + /// + /// The jstype option determines the JavaScript type used for values of the + /// field. The option is permitted only for 64 bit integral and fixed types + /// (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + /// is represented as JavaScript string, which avoids loss of precision that + /// can happen when a large value is converted to a floating point JavaScript. + /// Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + /// use the JavaScript "number" type. The behavior of the default option + /// JS_NORMAL is implementation dependent. + /// + /// This option is an enum to permit additional types to be added, e.g. + /// goog.math.Integer. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType Jstype { + get { if ((_hasBits0 & 16) != 0) { return jstype_; } else { return JstypeDefaultValue; } } + set { + _hasBits0 |= 16; + jstype_ = value; + } + } + /// Gets whether the "jstype" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasJstype { + get { return (_hasBits0 & 16) != 0; } + } + /// Clears the value of the "jstype" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearJstype() { + _hasBits0 &= ~16; + } + + /// Field number for the "lazy" field. + public const int LazyFieldNumber = 5; + private readonly static bool LazyDefaultValue = false; + + private bool lazy_; + /// + /// Should this field be parsed lazily? Lazy applies only to message-type + /// fields. It means that when the outer message is initially parsed, the + /// inner message's contents will not be parsed but instead stored in encoded + /// form. The inner message will actually be parsed when it is first accessed. + /// + /// This is only a hint. Implementations are free to choose whether to use + /// eager or lazy parsing regardless of the value of this option. However, + /// setting this option true suggests that the protocol author believes that + /// using lazy parsing on this field is worth the additional bookkeeping + /// overhead typically needed to implement it. + /// + /// This option does not affect the public interface of any generated code; + /// all method signatures remain the same. Furthermore, thread-safety of the + /// interface is not affected by this option; const methods remain safe to + /// call from multiple threads concurrently, while non-const methods continue + /// to require exclusive access. + /// + /// Note that implementations may choose not to check required fields within + /// a lazy sub-message. That is, calling IsInitialized() on the outer message + /// may return true even if the inner message has missing required fields. + /// This is necessary because otherwise the inner message would have to be + /// parsed in order to perform the check, defeating the purpose of lazy + /// parsing. An implementation which chooses not to check required fields + /// must be consistent about it. That is, for any particular sub-message, the + /// implementation must either *always* check its required fields, or *never* + /// check its required fields, regardless of whether or not the message has + /// been parsed. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Lazy { + get { if ((_hasBits0 & 8) != 0) { return lazy_; } else { return LazyDefaultValue; } } + set { + _hasBits0 |= 8; + lazy_ = value; + } + } + /// Gets whether the "lazy" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasLazy { + get { return (_hasBits0 & 8) != 0; } + } + /// Clears the value of the "lazy" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearLazy() { + _hasBits0 &= ~8; + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 3; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this field deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for accessors, or it will be completely ignored; in the very least, this + /// is a formalization for deprecating fields. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 4) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 4; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 4) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~4; + } + + /// Field number for the "weak" field. + public const int WeakFieldNumber = 10; + private readonly static bool WeakDefaultValue = false; + + private bool weak_; + /// + /// For Google-internal migration only. Do not use. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Weak { + get { if ((_hasBits0 & 32) != 0) { return weak_; } else { return WeakDefaultValue; } } + set { + _hasBits0 |= 32; + weak_ = value; + } + } + /// Gets whether the "weak" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasWeak { + get { return (_hasBits0 & 32) != 0; } + } + /// Clears the value of the "weak" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearWeak() { + _hasBits0 &= ~32; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FieldOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FieldOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Ctype != other.Ctype) return false; + if (Packed != other.Packed) return false; + if (Jstype != other.Jstype) return false; + if (Lazy != other.Lazy) return false; + if (Deprecated != other.Deprecated) return false; + if (Weak != other.Weak) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasCtype) hash ^= Ctype.GetHashCode(); + if (HasPacked) hash ^= Packed.GetHashCode(); + if (HasJstype) hash ^= Jstype.GetHashCode(); + if (HasLazy) hash ^= Lazy.GetHashCode(); + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + if (HasWeak) hash ^= Weak.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasCtype) { + output.WriteRawTag(8); + output.WriteEnum((int) Ctype); + } + if (HasPacked) { + output.WriteRawTag(16); + output.WriteBool(Packed); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + if (HasLazy) { + output.WriteRawTag(40); + output.WriteBool(Lazy); + } + if (HasJstype) { + output.WriteRawTag(48); + output.WriteEnum((int) Jstype); + } + if (HasWeak) { + output.WriteRawTag(80); + output.WriteBool(Weak); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasCtype) { + output.WriteRawTag(8); + output.WriteEnum((int) Ctype); + } + if (HasPacked) { + output.WriteRawTag(16); + output.WriteBool(Packed); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + if (HasLazy) { + output.WriteRawTag(40); + output.WriteBool(Lazy); + } + if (HasJstype) { + output.WriteRawTag(48); + output.WriteEnum((int) Jstype); + } + if (HasWeak) { + output.WriteRawTag(80); + output.WriteBool(Weak); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasCtype) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Ctype); + } + if (HasPacked) { + size += 1 + 1; + } + if (HasJstype) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Jstype); + } + if (HasLazy) { + size += 1 + 1; + } + if (HasDeprecated) { + size += 1 + 1; + } + if (HasWeak) { + size += 1 + 1; + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FieldOptions other) { + if (other == null) { + return; + } + if (other.HasCtype) { + Ctype = other.Ctype; + } + if (other.HasPacked) { + Packed = other.Packed; + } + if (other.HasJstype) { + Jstype = other.Jstype; + } + if (other.HasLazy) { + Lazy = other.Lazy; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + if (other.HasWeak) { + Weak = other.Weak; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 8: { + Ctype = (global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum(); + break; + } + case 16: { + Packed = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 40: { + Lazy = input.ReadBool(); + break; + } + case 48: { + Jstype = (global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType) input.ReadEnum(); + break; + } + case 80: { + Weak = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + Ctype = (global::LC.Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum(); + break; + } + case 16: { + Packed = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 40: { + Lazy = input.ReadBool(); + break; + } + case 48: { + Jstype = (global::LC.Google.Protobuf.Reflection.FieldOptions.Types.JSType) input.ReadEnum(); + break; + } + case 80: { + Weak = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + #region Nested types + /// Container for nested types declared in the FieldOptions message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public enum CType { + /// + /// Default mode. + /// + [pbr::OriginalName("STRING")] String = 0, + [pbr::OriginalName("CORD")] Cord = 1, + [pbr::OriginalName("STRING_PIECE")] StringPiece = 2, + } + + public enum JSType { + /// + /// Use the default type. + /// + [pbr::OriginalName("JS_NORMAL")] JsNormal = 0, + /// + /// Use JavaScript strings. + /// + [pbr::OriginalName("JS_STRING")] JsString = 1, + /// + /// Use JavaScript numbers. + /// + [pbr::OriginalName("JS_NUMBER")] JsNumber = 2, + } + + } + #endregion + + } + + public sealed partial class OneofOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[13]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public OneofOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public OneofOptions(OneofOptions other) : this() { + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public OneofOptions Clone() { + return new OneofOptions(this); + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as OneofOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(OneofOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(OneofOptions other) { + if (other == null) { + return; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + } + + public sealed partial class EnumOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[14]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumOptions(EnumOptions other) : this() { + _hasBits0 = other._hasBits0; + allowAlias_ = other.allowAlias_; + deprecated_ = other.deprecated_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumOptions Clone() { + return new EnumOptions(this); + } + + /// Field number for the "allow_alias" field. + public const int AllowAliasFieldNumber = 2; + private readonly static bool AllowAliasDefaultValue = false; + + private bool allowAlias_; + /// + /// Set this option to true to allow mapping different tag names to the same + /// value. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool AllowAlias { + get { if ((_hasBits0 & 1) != 0) { return allowAlias_; } else { return AllowAliasDefaultValue; } } + set { + _hasBits0 |= 1; + allowAlias_ = value; + } + } + /// Gets whether the "allow_alias" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasAllowAlias { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "allow_alias" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearAllowAlias() { + _hasBits0 &= ~1; + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 3; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this enum deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for the enum, or it will be completely ignored; in the very least, this + /// is a formalization for deprecating enums. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 2) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 2; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~2; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EnumOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EnumOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (AllowAlias != other.AllowAlias) return false; + if (Deprecated != other.Deprecated) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasAllowAlias) hash ^= AllowAlias.GetHashCode(); + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasAllowAlias) { + output.WriteRawTag(16); + output.WriteBool(AllowAlias); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasAllowAlias) { + output.WriteRawTag(16); + output.WriteBool(AllowAlias); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasAllowAlias) { + size += 1 + 1; + } + if (HasDeprecated) { + size += 1 + 1; + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EnumOptions other) { + if (other == null) { + return; + } + if (other.HasAllowAlias) { + AllowAlias = other.AllowAlias; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 16: { + AllowAlias = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 16: { + AllowAlias = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + } + + public sealed partial class EnumValueOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValueOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[15]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValueOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValueOptions(EnumValueOptions other) : this() { + _hasBits0 = other._hasBits0; + deprecated_ = other.deprecated_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValueOptions Clone() { + return new EnumValueOptions(this); + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 1; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this enum value deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for the enum value, or it will be completely ignored; in the very least, + /// this is a formalization for deprecating enum values. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 1) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 1; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~1; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EnumValueOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EnumValueOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Deprecated != other.Deprecated) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasDeprecated) { + output.WriteRawTag(8); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasDeprecated) { + output.WriteRawTag(8); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasDeprecated) { + size += 1 + 1; + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EnumValueOptions other) { + if (other == null) { + return; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 8: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + } + + public sealed partial class ServiceOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ServiceOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[16]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ServiceOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ServiceOptions(ServiceOptions other) : this() { + _hasBits0 = other._hasBits0; + deprecated_ = other.deprecated_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ServiceOptions Clone() { + return new ServiceOptions(this); + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 33; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this service deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for the service, or it will be completely ignored; in the very least, + /// this is a formalization for deprecating services. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 1) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 1; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~1; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ServiceOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ServiceOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Deprecated != other.Deprecated) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasDeprecated) { + output.WriteRawTag(136, 2); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasDeprecated) { + output.WriteRawTag(136, 2); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasDeprecated) { + size += 2 + 1; + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ServiceOptions other) { + if (other == null) { + return; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 264: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 264: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + } + + public sealed partial class MethodOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MethodOptions()); + private pb::UnknownFieldSet _unknownFields; + internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions { get { return _extensions; } } + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[17]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MethodOptions() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MethodOptions(MethodOptions other) : this() { + _hasBits0 = other._hasBits0; + deprecated_ = other.deprecated_; + idempotencyLevel_ = other.idempotencyLevel_; + uninterpretedOption_ = other.uninterpretedOption_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + _extensions = pb::ExtensionSet.Clone(other._extensions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MethodOptions Clone() { + return new MethodOptions(this); + } + + /// Field number for the "deprecated" field. + public const int DeprecatedFieldNumber = 33; + private readonly static bool DeprecatedDefaultValue = false; + + private bool deprecated_; + /// + /// Is this method deprecated? + /// Depending on the target platform, this can emit Deprecated annotations + /// for the method, or it will be completely ignored; in the very least, + /// this is a formalization for deprecating methods. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Deprecated { + get { if ((_hasBits0 & 1) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } } + set { + _hasBits0 |= 1; + deprecated_ = value; + } + } + /// Gets whether the "deprecated" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDeprecated { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "deprecated" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDeprecated() { + _hasBits0 &= ~1; + } + + /// Field number for the "idempotency_level" field. + public const int IdempotencyLevelFieldNumber = 34; + private readonly static global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel IdempotencyLevelDefaultValue = global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel.IdempotencyUnknown; + + private global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel idempotencyLevel_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel IdempotencyLevel { + get { if ((_hasBits0 & 2) != 0) { return idempotencyLevel_; } else { return IdempotencyLevelDefaultValue; } } + set { + _hasBits0 |= 2; + idempotencyLevel_ = value; + } + } + /// Gets whether the "idempotency_level" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasIdempotencyLevel { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "idempotency_level" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearIdempotencyLevel() { + _hasBits0 &= ~2; + } + + /// Field number for the "uninterpreted_option" field. + public const int UninterpretedOptionFieldNumber = 999; + private static readonly pb::FieldCodec _repeated_uninterpretedOption_codec + = pb::FieldCodec.ForMessage(7994, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Parser); + private readonly pbc::RepeatedField uninterpretedOption_ = new pbc::RepeatedField(); + /// + /// The parser stores options it doesn't recognize here. See above. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField UninterpretedOption { + get { return uninterpretedOption_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as MethodOptions); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(MethodOptions other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Deprecated != other.Deprecated) return false; + if (IdempotencyLevel != other.IdempotencyLevel) return false; + if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false; + if (!Equals(_extensions, other._extensions)) { + return false; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasDeprecated) hash ^= Deprecated.GetHashCode(); + if (HasIdempotencyLevel) hash ^= IdempotencyLevel.GetHashCode(); + hash ^= uninterpretedOption_.GetHashCode(); + if (_extensions != null) { + hash ^= _extensions.GetHashCode(); + } + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasDeprecated) { + output.WriteRawTag(136, 2); + output.WriteBool(Deprecated); + } + if (HasIdempotencyLevel) { + output.WriteRawTag(144, 2); + output.WriteEnum((int) IdempotencyLevel); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasDeprecated) { + output.WriteRawTag(136, 2); + output.WriteBool(Deprecated); + } + if (HasIdempotencyLevel) { + output.WriteRawTag(144, 2); + output.WriteEnum((int) IdempotencyLevel); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasDeprecated) { + size += 2 + 1; + } + if (HasIdempotencyLevel) { + size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) IdempotencyLevel); + } + size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec); + if (_extensions != null) { + size += _extensions.CalculateSize(); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(MethodOptions other) { + if (other == null) { + return; + } + if (other.HasDeprecated) { + Deprecated = other.Deprecated; + } + if (other.HasIdempotencyLevel) { + IdempotencyLevel = other.IdempotencyLevel; + } + uninterpretedOption_.Add(other.uninterpretedOption_); + pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + } + break; + case 264: { + Deprecated = input.ReadBool(); + break; + } + case 272: { + IdempotencyLevel = (global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) input.ReadEnum(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 264: { + Deprecated = input.ReadBool(); + break; + } + case 272: { + IdempotencyLevel = (global::LC.Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) input.ReadEnum(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + #region Nested types + /// Container for nested types declared in the MethodOptions message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + /// + /// Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + /// or neither? HTTP based RPC implementation may choose GET verb for safe + /// methods, and PUT verb for idempotent methods instead of the default POST. + /// + public enum IdempotencyLevel { + [pbr::OriginalName("IDEMPOTENCY_UNKNOWN")] IdempotencyUnknown = 0, + /// + /// implies idempotent + /// + [pbr::OriginalName("NO_SIDE_EFFECTS")] NoSideEffects = 1, + /// + /// idempotent, but may have side effects + /// + [pbr::OriginalName("IDEMPOTENT")] Idempotent = 2, + } + + } + #endregion + + } + + /// + /// A message representing a option the parser does not recognize. This only + /// appears in options protos created by the compiler::Parser class. + /// DescriptorPool resolves these when building Descriptor objects. Therefore, + /// options protos in descriptor objects (e.g. returned by Descriptor::options(), + /// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions + /// in them. + /// + public sealed partial class UninterpretedOption : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new UninterpretedOption()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[18]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public UninterpretedOption() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public UninterpretedOption(UninterpretedOption other) : this() { + _hasBits0 = other._hasBits0; + name_ = other.name_.Clone(); + identifierValue_ = other.identifierValue_; + positiveIntValue_ = other.positiveIntValue_; + negativeIntValue_ = other.negativeIntValue_; + doubleValue_ = other.doubleValue_; + stringValue_ = other.stringValue_; + aggregateValue_ = other.aggregateValue_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public UninterpretedOption Clone() { + return new UninterpretedOption(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_name_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart.Parser); + private readonly pbc::RepeatedField name_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Name { + get { return name_; } + } + + /// Field number for the "identifier_value" field. + public const int IdentifierValueFieldNumber = 3; + private readonly static string IdentifierValueDefaultValue = ""; + + private string identifierValue_; + /// + /// The value of the uninterpreted option, in whatever type the tokenizer + /// identified it as during parsing. Exactly one of these should be set. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string IdentifierValue { + get { return identifierValue_ ?? IdentifierValueDefaultValue; } + set { + identifierValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "identifier_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasIdentifierValue { + get { return identifierValue_ != null; } + } + /// Clears the value of the "identifier_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearIdentifierValue() { + identifierValue_ = null; + } + + /// Field number for the "positive_int_value" field. + public const int PositiveIntValueFieldNumber = 4; + private readonly static ulong PositiveIntValueDefaultValue = 0UL; + + private ulong positiveIntValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ulong PositiveIntValue { + get { if ((_hasBits0 & 1) != 0) { return positiveIntValue_; } else { return PositiveIntValueDefaultValue; } } + set { + _hasBits0 |= 1; + positiveIntValue_ = value; + } + } + /// Gets whether the "positive_int_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasPositiveIntValue { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "positive_int_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearPositiveIntValue() { + _hasBits0 &= ~1; + } + + /// Field number for the "negative_int_value" field. + public const int NegativeIntValueFieldNumber = 5; + private readonly static long NegativeIntValueDefaultValue = 0L; + + private long negativeIntValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long NegativeIntValue { + get { if ((_hasBits0 & 2) != 0) { return negativeIntValue_; } else { return NegativeIntValueDefaultValue; } } + set { + _hasBits0 |= 2; + negativeIntValue_ = value; + } + } + /// Gets whether the "negative_int_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasNegativeIntValue { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "negative_int_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNegativeIntValue() { + _hasBits0 &= ~2; + } + + /// Field number for the "double_value" field. + public const int DoubleValueFieldNumber = 6; + private readonly static double DoubleValueDefaultValue = 0D; + + private double doubleValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleValue { + get { if ((_hasBits0 & 4) != 0) { return doubleValue_; } else { return DoubleValueDefaultValue; } } + set { + _hasBits0 |= 4; + doubleValue_ = value; + } + } + /// Gets whether the "double_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasDoubleValue { + get { return (_hasBits0 & 4) != 0; } + } + /// Clears the value of the "double_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearDoubleValue() { + _hasBits0 &= ~4; + } + + /// Field number for the "string_value" field. + public const int StringValueFieldNumber = 7; + private readonly static pb::ByteString StringValueDefaultValue = pb::ByteString.Empty; + + private pb::ByteString stringValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString StringValue { + get { return stringValue_ ?? StringValueDefaultValue; } + set { + stringValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "string_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasStringValue { + get { return stringValue_ != null; } + } + /// Clears the value of the "string_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearStringValue() { + stringValue_ = null; + } + + /// Field number for the "aggregate_value" field. + public const int AggregateValueFieldNumber = 8; + private readonly static string AggregateValueDefaultValue = ""; + + private string aggregateValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string AggregateValue { + get { return aggregateValue_ ?? AggregateValueDefaultValue; } + set { + aggregateValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "aggregate_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasAggregateValue { + get { return aggregateValue_ != null; } + } + /// Clears the value of the "aggregate_value" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearAggregateValue() { + aggregateValue_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as UninterpretedOption); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(UninterpretedOption other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!name_.Equals(other.name_)) return false; + if (IdentifierValue != other.IdentifierValue) return false; + if (PositiveIntValue != other.PositiveIntValue) return false; + if (NegativeIntValue != other.NegativeIntValue) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleValue, other.DoubleValue)) return false; + if (StringValue != other.StringValue) return false; + if (AggregateValue != other.AggregateValue) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= name_.GetHashCode(); + if (HasIdentifierValue) hash ^= IdentifierValue.GetHashCode(); + if (HasPositiveIntValue) hash ^= PositiveIntValue.GetHashCode(); + if (HasNegativeIntValue) hash ^= NegativeIntValue.GetHashCode(); + if (HasDoubleValue) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleValue); + if (HasStringValue) hash ^= StringValue.GetHashCode(); + if (HasAggregateValue) hash ^= AggregateValue.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + name_.WriteTo(output, _repeated_name_codec); + if (HasIdentifierValue) { + output.WriteRawTag(26); + output.WriteString(IdentifierValue); + } + if (HasPositiveIntValue) { + output.WriteRawTag(32); + output.WriteUInt64(PositiveIntValue); + } + if (HasNegativeIntValue) { + output.WriteRawTag(40); + output.WriteInt64(NegativeIntValue); + } + if (HasDoubleValue) { + output.WriteRawTag(49); + output.WriteDouble(DoubleValue); + } + if (HasStringValue) { + output.WriteRawTag(58); + output.WriteBytes(StringValue); + } + if (HasAggregateValue) { + output.WriteRawTag(66); + output.WriteString(AggregateValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + name_.WriteTo(ref output, _repeated_name_codec); + if (HasIdentifierValue) { + output.WriteRawTag(26); + output.WriteString(IdentifierValue); + } + if (HasPositiveIntValue) { + output.WriteRawTag(32); + output.WriteUInt64(PositiveIntValue); + } + if (HasNegativeIntValue) { + output.WriteRawTag(40); + output.WriteInt64(NegativeIntValue); + } + if (HasDoubleValue) { + output.WriteRawTag(49); + output.WriteDouble(DoubleValue); + } + if (HasStringValue) { + output.WriteRawTag(58); + output.WriteBytes(StringValue); + } + if (HasAggregateValue) { + output.WriteRawTag(66); + output.WriteString(AggregateValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += name_.CalculateSize(_repeated_name_codec); + if (HasIdentifierValue) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(IdentifierValue); + } + if (HasPositiveIntValue) { + size += 1 + pb::CodedOutputStream.ComputeUInt64Size(PositiveIntValue); + } + if (HasNegativeIntValue) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(NegativeIntValue); + } + if (HasDoubleValue) { + size += 1 + 8; + } + if (HasStringValue) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(StringValue); + } + if (HasAggregateValue) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(AggregateValue); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(UninterpretedOption other) { + if (other == null) { + return; + } + name_.Add(other.name_); + if (other.HasIdentifierValue) { + IdentifierValue = other.IdentifierValue; + } + if (other.HasPositiveIntValue) { + PositiveIntValue = other.PositiveIntValue; + } + if (other.HasNegativeIntValue) { + NegativeIntValue = other.NegativeIntValue; + } + if (other.HasDoubleValue) { + DoubleValue = other.DoubleValue; + } + if (other.HasStringValue) { + StringValue = other.StringValue; + } + if (other.HasAggregateValue) { + AggregateValue = other.AggregateValue; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 18: { + name_.AddEntriesFrom(input, _repeated_name_codec); + break; + } + case 26: { + IdentifierValue = input.ReadString(); + break; + } + case 32: { + PositiveIntValue = input.ReadUInt64(); + break; + } + case 40: { + NegativeIntValue = input.ReadInt64(); + break; + } + case 49: { + DoubleValue = input.ReadDouble(); + break; + } + case 58: { + StringValue = input.ReadBytes(); + break; + } + case 66: { + AggregateValue = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 18: { + name_.AddEntriesFrom(ref input, _repeated_name_codec); + break; + } + case 26: { + IdentifierValue = input.ReadString(); + break; + } + case 32: { + PositiveIntValue = input.ReadUInt64(); + break; + } + case 40: { + NegativeIntValue = input.ReadInt64(); + break; + } + case 49: { + DoubleValue = input.ReadDouble(); + break; + } + case 58: { + StringValue = input.ReadBytes(); + break; + } + case 66: { + AggregateValue = input.ReadString(); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the UninterpretedOption message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + /// + /// The name of the uninterpreted option. Each string represents a segment in + /// a dot-separated name. is_extension is true iff a segment represents an + /// extension (denoted with parentheses in options specs in .proto files). + /// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + /// "foo.(bar.baz).qux". + /// + public sealed partial class NamePart : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NamePart()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.UninterpretedOption.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NamePart() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NamePart(NamePart other) : this() { + _hasBits0 = other._hasBits0; + namePart_ = other.namePart_; + isExtension_ = other.isExtension_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NamePart Clone() { + return new NamePart(this); + } + + /// Field number for the "name_part" field. + public const int NamePart_FieldNumber = 1; + private readonly static string NamePart_DefaultValue = ""; + + private string namePart_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string NamePart_ { + get { return namePart_ ?? NamePart_DefaultValue; } + set { + namePart_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "name_part" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasNamePart_ { + get { return namePart_ != null; } + } + /// Clears the value of the "name_part" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNamePart_() { + namePart_ = null; + } + + /// Field number for the "is_extension" field. + public const int IsExtensionFieldNumber = 2; + private readonly static bool IsExtensionDefaultValue = false; + + private bool isExtension_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool IsExtension { + get { if ((_hasBits0 & 1) != 0) { return isExtension_; } else { return IsExtensionDefaultValue; } } + set { + _hasBits0 |= 1; + isExtension_ = value; + } + } + /// Gets whether the "is_extension" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasIsExtension { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "is_extension" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearIsExtension() { + _hasBits0 &= ~1; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as NamePart); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(NamePart other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (NamePart_ != other.NamePart_) return false; + if (IsExtension != other.IsExtension) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (HasNamePart_) hash ^= NamePart_.GetHashCode(); + if (HasIsExtension) hash ^= IsExtension.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (HasNamePart_) { + output.WriteRawTag(10); + output.WriteString(NamePart_); + } + if (HasIsExtension) { + output.WriteRawTag(16); + output.WriteBool(IsExtension); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (HasNamePart_) { + output.WriteRawTag(10); + output.WriteString(NamePart_); + } + if (HasIsExtension) { + output.WriteRawTag(16); + output.WriteBool(IsExtension); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (HasNamePart_) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(NamePart_); + } + if (HasIsExtension) { + size += 1 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(NamePart other) { + if (other == null) { + return; + } + if (other.HasNamePart_) { + NamePart_ = other.NamePart_; + } + if (other.HasIsExtension) { + IsExtension = other.IsExtension; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + NamePart_ = input.ReadString(); + break; + } + case 16: { + IsExtension = input.ReadBool(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + NamePart_ = input.ReadString(); + break; + } + case 16: { + IsExtension = input.ReadBool(); + break; + } + } + } + } + #endif + + } + + } + #endregion + + } + + /// + /// Encapsulates information about the original source file from which a + /// FileDescriptorProto was generated. + /// + public sealed partial class SourceCodeInfo : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SourceCodeInfo()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[19]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceCodeInfo() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceCodeInfo(SourceCodeInfo other) : this() { + location_ = other.location_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceCodeInfo Clone() { + return new SourceCodeInfo(this); + } + + /// Field number for the "location" field. + public const int LocationFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_location_codec + = pb::FieldCodec.ForMessage(10, global::LC.Google.Protobuf.Reflection.SourceCodeInfo.Types.Location.Parser); + private readonly pbc::RepeatedField location_ = new pbc::RepeatedField(); + /// + /// A Location identifies a piece of source code in a .proto file which + /// corresponds to a particular definition. This information is intended + /// to be useful to IDEs, code indexers, documentation generators, and similar + /// tools. + /// + /// For example, say we have a file like: + /// message Foo { + /// optional string foo = 1; + /// } + /// Let's look at just the field definition: + /// optional string foo = 1; + /// ^ ^^ ^^ ^ ^^^ + /// a bc de f ghi + /// We have the following locations: + /// span path represents + /// [a,i) [ 4, 0, 2, 0 ] The whole field definition. + /// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + /// [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + /// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + /// [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + /// + /// Notes: + /// - A location may refer to a repeated field itself (i.e. not to any + /// particular index within it). This is used whenever a set of elements are + /// logically enclosed in a single code segment. For example, an entire + /// extend block (possibly containing multiple extension definitions) will + /// have an outer location whose path refers to the "extensions" repeated + /// field without an index. + /// - Multiple locations may have the same path. This happens when a single + /// logical declaration is spread out across multiple places. The most + /// obvious example is the "extend" block again -- there may be multiple + /// extend blocks in the same scope, each of which will have the same path. + /// - A location's span is not always a subset of its parent's span. For + /// example, the "extendee" of an extension declaration appears at the + /// beginning of the "extend" block and is shared by all extensions within + /// the block. + /// - Just because a location's span is a subset of some other location's span + /// does not mean that it is a descendant. For example, a "group" defines + /// both a type and a field in a single declaration. Thus, the locations + /// corresponding to the type and field and their components will overlap. + /// - Code which tries to interpret locations should probably be designed to + /// ignore those that it doesn't understand, as more types of locations could + /// be recorded in the future. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Location { + get { return location_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as SourceCodeInfo); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(SourceCodeInfo other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!location_.Equals(other.location_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= location_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + location_.WriteTo(output, _repeated_location_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + location_.WriteTo(ref output, _repeated_location_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += location_.CalculateSize(_repeated_location_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(SourceCodeInfo other) { + if (other == null) { + return; + } + location_.Add(other.location_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + location_.AddEntriesFrom(input, _repeated_location_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + location_.AddEntriesFrom(ref input, _repeated_location_codec); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the SourceCodeInfo message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public sealed partial class Location : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Location()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.SourceCodeInfo.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Location() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Location(Location other) : this() { + path_ = other.path_.Clone(); + span_ = other.span_.Clone(); + leadingComments_ = other.leadingComments_; + trailingComments_ = other.trailingComments_; + leadingDetachedComments_ = other.leadingDetachedComments_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Location Clone() { + return new Location(this); + } + + /// Field number for the "path" field. + public const int PathFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_path_codec + = pb::FieldCodec.ForInt32(10); + private readonly pbc::RepeatedField path_ = new pbc::RepeatedField(); + /// + /// Identifies which part of the FileDescriptorProto was defined at this + /// location. + /// + /// Each element is a field number or an index. They form a path from + /// the root FileDescriptorProto to the place where the definition. For + /// example, this path: + /// [ 4, 3, 2, 7, 1 ] + /// refers to: + /// file.message_type(3) // 4, 3 + /// .field(7) // 2, 7 + /// .name() // 1 + /// This is because FileDescriptorProto.message_type has field number 4: + /// repeated DescriptorProto message_type = 4; + /// and DescriptorProto.field has field number 2: + /// repeated FieldDescriptorProto field = 2; + /// and FieldDescriptorProto.name has field number 1: + /// optional string name = 1; + /// + /// Thus, the above path gives the location of a field name. If we removed + /// the last element: + /// [ 4, 3, 2, 7 ] + /// this path refers to the whole field declaration (from the beginning + /// of the label to the terminating semicolon). + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Path { + get { return path_; } + } + + /// Field number for the "span" field. + public const int SpanFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_span_codec + = pb::FieldCodec.ForInt32(18); + private readonly pbc::RepeatedField span_ = new pbc::RepeatedField(); + /// + /// Always has exactly three or four elements: start line, start column, + /// end line (optional, otherwise assumed same as start line), end column. + /// These are packed into a single field for efficiency. Note that line + /// and column numbers are zero-based -- typically you will want to add + /// 1 to each before displaying to a user. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Span { + get { return span_; } + } + + /// Field number for the "leading_comments" field. + public const int LeadingCommentsFieldNumber = 3; + private readonly static string LeadingCommentsDefaultValue = ""; + + private string leadingComments_; + /// + /// If this SourceCodeInfo represents a complete declaration, these are any + /// comments appearing before and after the declaration which appear to be + /// attached to the declaration. + /// + /// A series of line comments appearing on consecutive lines, with no other + /// tokens appearing on those lines, will be treated as a single comment. + /// + /// leading_detached_comments will keep paragraphs of comments that appear + /// before (but not connected to) the current element. Each paragraph, + /// separated by empty lines, will be one comment element in the repeated + /// field. + /// + /// Only the comment content is provided; comment markers (e.g. //) are + /// stripped out. For block comments, leading whitespace and an asterisk + /// will be stripped from the beginning of each line other than the first. + /// Newlines are included in the output. + /// + /// Examples: + /// + /// optional int32 foo = 1; // Comment attached to foo. + /// // Comment attached to bar. + /// optional int32 bar = 2; + /// + /// optional string baz = 3; + /// // Comment attached to baz. + /// // Another line attached to baz. + /// + /// // Comment attached to qux. + /// // + /// // Another line attached to qux. + /// optional double qux = 4; + /// + /// // Detached comment for corge. This is not leading or trailing comments + /// // to qux or corge because there are blank lines separating it from + /// // both. + /// + /// // Detached comment for corge paragraph 2. + /// + /// optional string corge = 5; + /// /* Block comment attached + /// * to corge. Leading asterisks + /// * will be removed. */ + /// /* Block comment attached to + /// * grault. */ + /// optional int32 grault = 6; + /// + /// // ignored detached comments. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string LeadingComments { + get { return leadingComments_ ?? LeadingCommentsDefaultValue; } + set { + leadingComments_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "leading_comments" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasLeadingComments { + get { return leadingComments_ != null; } + } + /// Clears the value of the "leading_comments" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearLeadingComments() { + leadingComments_ = null; + } + + /// Field number for the "trailing_comments" field. + public const int TrailingCommentsFieldNumber = 4; + private readonly static string TrailingCommentsDefaultValue = ""; + + private string trailingComments_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TrailingComments { + get { return trailingComments_ ?? TrailingCommentsDefaultValue; } + set { + trailingComments_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "trailing_comments" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasTrailingComments { + get { return trailingComments_ != null; } + } + /// Clears the value of the "trailing_comments" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearTrailingComments() { + trailingComments_ = null; + } + + /// Field number for the "leading_detached_comments" field. + public const int LeadingDetachedCommentsFieldNumber = 6; + private static readonly pb::FieldCodec _repeated_leadingDetachedComments_codec + = pb::FieldCodec.ForString(50); + private readonly pbc::RepeatedField leadingDetachedComments_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField LeadingDetachedComments { + get { return leadingDetachedComments_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Location); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Location other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!path_.Equals(other.path_)) return false; + if(!span_.Equals(other.span_)) return false; + if (LeadingComments != other.LeadingComments) return false; + if (TrailingComments != other.TrailingComments) return false; + if(!leadingDetachedComments_.Equals(other.leadingDetachedComments_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= path_.GetHashCode(); + hash ^= span_.GetHashCode(); + if (HasLeadingComments) hash ^= LeadingComments.GetHashCode(); + if (HasTrailingComments) hash ^= TrailingComments.GetHashCode(); + hash ^= leadingDetachedComments_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + path_.WriteTo(output, _repeated_path_codec); + span_.WriteTo(output, _repeated_span_codec); + if (HasLeadingComments) { + output.WriteRawTag(26); + output.WriteString(LeadingComments); + } + if (HasTrailingComments) { + output.WriteRawTag(34); + output.WriteString(TrailingComments); + } + leadingDetachedComments_.WriteTo(output, _repeated_leadingDetachedComments_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + path_.WriteTo(ref output, _repeated_path_codec); + span_.WriteTo(ref output, _repeated_span_codec); + if (HasLeadingComments) { + output.WriteRawTag(26); + output.WriteString(LeadingComments); + } + if (HasTrailingComments) { + output.WriteRawTag(34); + output.WriteString(TrailingComments); + } + leadingDetachedComments_.WriteTo(ref output, _repeated_leadingDetachedComments_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += path_.CalculateSize(_repeated_path_codec); + size += span_.CalculateSize(_repeated_span_codec); + if (HasLeadingComments) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(LeadingComments); + } + if (HasTrailingComments) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TrailingComments); + } + size += leadingDetachedComments_.CalculateSize(_repeated_leadingDetachedComments_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Location other) { + if (other == null) { + return; + } + path_.Add(other.path_); + span_.Add(other.span_); + if (other.HasLeadingComments) { + LeadingComments = other.LeadingComments; + } + if (other.HasTrailingComments) { + TrailingComments = other.TrailingComments; + } + leadingDetachedComments_.Add(other.leadingDetachedComments_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: + case 8: { + path_.AddEntriesFrom(input, _repeated_path_codec); + break; + } + case 18: + case 16: { + span_.AddEntriesFrom(input, _repeated_span_codec); + break; + } + case 26: { + LeadingComments = input.ReadString(); + break; + } + case 34: { + TrailingComments = input.ReadString(); + break; + } + case 50: { + leadingDetachedComments_.AddEntriesFrom(input, _repeated_leadingDetachedComments_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: + case 8: { + path_.AddEntriesFrom(ref input, _repeated_path_codec); + break; + } + case 18: + case 16: { + span_.AddEntriesFrom(ref input, _repeated_span_codec); + break; + } + case 26: { + LeadingComments = input.ReadString(); + break; + } + case 34: { + TrailingComments = input.ReadString(); + break; + } + case 50: { + leadingDetachedComments_.AddEntriesFrom(ref input, _repeated_leadingDetachedComments_codec); + break; + } + } + } + } + #endif + + } + + } + #endregion + + } + + /// + /// Describes the relationship between generated code and its original source + /// file. A GeneratedCodeInfo message is associated with only one generated + /// source file, but may contain references to different source .proto files. + /// + public sealed partial class GeneratedCodeInfo : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new GeneratedCodeInfo()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[20]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public GeneratedCodeInfo() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public GeneratedCodeInfo(GeneratedCodeInfo other) : this() { + annotation_ = other.annotation_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public GeneratedCodeInfo Clone() { + return new GeneratedCodeInfo(this); + } + + /// Field number for the "annotation" field. + public const int AnnotationFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_annotation_codec + = pb::FieldCodec.ForMessage(10, global::LC.Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Parser); + private readonly pbc::RepeatedField annotation_ = new pbc::RepeatedField(); + /// + /// An Annotation connects some span of text in generated code to an element + /// of its generating .proto file. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Annotation { + get { return annotation_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as GeneratedCodeInfo); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(GeneratedCodeInfo other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!annotation_.Equals(other.annotation_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= annotation_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + annotation_.WriteTo(output, _repeated_annotation_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + annotation_.WriteTo(ref output, _repeated_annotation_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += annotation_.CalculateSize(_repeated_annotation_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(GeneratedCodeInfo other) { + if (other == null) { + return; + } + annotation_.Add(other.annotation_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + annotation_.AddEntriesFrom(input, _repeated_annotation_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + annotation_.AddEntriesFrom(ref input, _repeated_annotation_codec); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the GeneratedCodeInfo message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public sealed partial class Annotation : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Annotation()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.Reflection.GeneratedCodeInfo.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Annotation() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Annotation(Annotation other) : this() { + _hasBits0 = other._hasBits0; + path_ = other.path_.Clone(); + sourceFile_ = other.sourceFile_; + begin_ = other.begin_; + end_ = other.end_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Annotation Clone() { + return new Annotation(this); + } + + /// Field number for the "path" field. + public const int PathFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_path_codec + = pb::FieldCodec.ForInt32(10); + private readonly pbc::RepeatedField path_ = new pbc::RepeatedField(); + /// + /// Identifies the element in the original source .proto file. This field + /// is formatted the same as SourceCodeInfo.Location.path. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Path { + get { return path_; } + } + + /// Field number for the "source_file" field. + public const int SourceFileFieldNumber = 2; + private readonly static string SourceFileDefaultValue = ""; + + private string sourceFile_; + /// + /// Identifies the filesystem path to the original source .proto. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string SourceFile { + get { return sourceFile_ ?? SourceFileDefaultValue; } + set { + sourceFile_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Gets whether the "source_file" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasSourceFile { + get { return sourceFile_ != null; } + } + /// Clears the value of the "source_file" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearSourceFile() { + sourceFile_ = null; + } + + /// Field number for the "begin" field. + public const int BeginFieldNumber = 3; + private readonly static int BeginDefaultValue = 0; + + private int begin_; + /// + /// Identifies the starting offset in bytes in the generated code + /// that relates to the identified object. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Begin { + get { if ((_hasBits0 & 1) != 0) { return begin_; } else { return BeginDefaultValue; } } + set { + _hasBits0 |= 1; + begin_ = value; + } + } + /// Gets whether the "begin" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasBegin { + get { return (_hasBits0 & 1) != 0; } + } + /// Clears the value of the "begin" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearBegin() { + _hasBits0 &= ~1; + } + + /// Field number for the "end" field. + public const int EndFieldNumber = 4; + private readonly static int EndDefaultValue = 0; + + private int end_; + /// + /// Identifies the ending offset in bytes in the generated code that + /// relates to the identified offset. The end offset should be one past + /// the last relevant byte (so the length of the text = end - begin). + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int End { + get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } } + set { + _hasBits0 |= 2; + end_ = value; + } + } + /// Gets whether the "end" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasEnd { + get { return (_hasBits0 & 2) != 0; } + } + /// Clears the value of the "end" field + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEnd() { + _hasBits0 &= ~2; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Annotation); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Annotation other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!path_.Equals(other.path_)) return false; + if (SourceFile != other.SourceFile) return false; + if (Begin != other.Begin) return false; + if (End != other.End) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= path_.GetHashCode(); + if (HasSourceFile) hash ^= SourceFile.GetHashCode(); + if (HasBegin) hash ^= Begin.GetHashCode(); + if (HasEnd) hash ^= End.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + path_.WriteTo(output, _repeated_path_codec); + if (HasSourceFile) { + output.WriteRawTag(18); + output.WriteString(SourceFile); + } + if (HasBegin) { + output.WriteRawTag(24); + output.WriteInt32(Begin); + } + if (HasEnd) { + output.WriteRawTag(32); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + path_.WriteTo(ref output, _repeated_path_codec); + if (HasSourceFile) { + output.WriteRawTag(18); + output.WriteString(SourceFile); + } + if (HasBegin) { + output.WriteRawTag(24); + output.WriteInt32(Begin); + } + if (HasEnd) { + output.WriteRawTag(32); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += path_.CalculateSize(_repeated_path_codec); + if (HasSourceFile) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(SourceFile); + } + if (HasBegin) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Begin); + } + if (HasEnd) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(End); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Annotation other) { + if (other == null) { + return; + } + path_.Add(other.path_); + if (other.HasSourceFile) { + SourceFile = other.SourceFile; + } + if (other.HasBegin) { + Begin = other.Begin; + } + if (other.HasEnd) { + End = other.End; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: + case 8: { + path_.AddEntriesFrom(input, _repeated_path_codec); + break; + } + case 18: { + SourceFile = input.ReadString(); + break; + } + case 24: { + Begin = input.ReadInt32(); + break; + } + case 32: { + End = input.ReadInt32(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: + case 8: { + path_.AddEntriesFrom(ref input, _repeated_path_codec); + break; + } + case 18: { + SourceFile = input.ReadString(); + break; + } + case 24: { + Begin = input.ReadInt32(); + break; + } + case 32: { + End = input.ReadInt32(); + break; + } + } + } + } + #endif + + } + + } + #endregion + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/Reflection/DescriptorBase.cs b/Libs/Google.Protobuf/Reflection/DescriptorBase.cs new file mode 100644 index 0000000..459e72b --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/DescriptorBase.cs @@ -0,0 +1,92 @@ +#region Copyright notice and license +// 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. +#endregion + +using System.Collections.Generic; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Base class for nearly all descriptors, providing common functionality. + /// + public abstract class DescriptorBase : IDescriptor + { + internal DescriptorBase(FileDescriptor file, string fullName, int index) + { + File = file; + FullName = fullName; + Index = index; + } + + /// + /// The index of this descriptor within its parent descriptor. + /// + /// + /// This returns the index of this descriptor within its parent, for + /// this descriptor's type. (There can be duplicate values for different + /// types, e.g. one enum type with index 0 and one message type with index 0.) + /// + public int Index { get; } + + /// + /// Returns the name of the entity (field, message etc) being described. + /// + public abstract string Name { get; } + + /// + /// The fully qualified name of the descriptor's target. + /// + public string FullName { get; } + + /// + /// The file this descriptor was declared in. + /// + public FileDescriptor File { get; } + + /// + /// The declaration information about the descriptor, or null if no declaration information + /// is available for this descriptor. + /// + /// + /// This information is typically only available for dynamically loaded descriptors, + /// for example within a protoc plugin where the full descriptors, including source info, + /// are passed to the code by protoc. + /// + public DescriptorDeclaration Declaration => File.GetDeclaration(this); + + /// + /// Retrieves the list of nested descriptors corresponding to the given field number, if any. + /// If the field is unknown or not a nested descriptor list, return null to terminate the search. + /// The default implementation returns null. + /// + internal virtual IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) => null; + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/DescriptorDeclaration.cs b/Libs/Google.Protobuf/Reflection/DescriptorDeclaration.cs new file mode 100644 index 0000000..bf0cb06 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/DescriptorDeclaration.cs @@ -0,0 +1,112 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2018 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.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using static LC.Google.Protobuf.Reflection.SourceCodeInfo.Types; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Provides additional information about the declaration of a descriptor, + /// such as source location and comments. + /// + public sealed class DescriptorDeclaration + { + /// + /// The descriptor this declaration relates to. + /// + public IDescriptor Descriptor { get; } + + /// + /// The start line of the declaration within the source file. This value is 1-based. + /// + public int StartLine { get; } + /// + /// The start column of the declaration within the source file. This value is 1-based. + /// + public int StartColumn { get; } + + /// + /// // The end line of the declaration within the source file. This value is 1-based. + /// + public int EndLine { get; } + /// + /// The end column of the declaration within the source file. This value is 1-based, and + /// exclusive. (The final character of the declaration is on the column before this value.) + /// + public int EndColumn { get; } + + /// + /// Comments appearing before the declaration. Never null, but may be empty. Multi-line comments + /// are represented as a newline-separated string. Leading whitespace and the comment marker ("//") + /// are removed from each line. + /// + public string LeadingComments { get; } + + /// + /// Comments appearing after the declaration. Never null, but may be empty. Multi-line comments + /// are represented as a newline-separated string. Leading whitespace and the comment marker ("//") + /// are removed from each line. + /// + public string TrailingComments { get; } + + /// + /// Comments appearing before the declaration, but separated from it by blank + /// lines. Each string represents a newline-separated paragraph of comments. + /// Leading whitespace and the comment marker ("//") are removed from each line. + /// The list is never null, but may be empty. Likewise each element is never null, but may be empty. + /// + public IReadOnlyList LeadingDetachedComments { get; } + + private DescriptorDeclaration(IDescriptor descriptor, Location location) + { + // TODO: Validation + Descriptor = descriptor; + bool hasEndLine = location.Span.Count == 4; + // Lines and columns are 0-based in the proto. + StartLine = location.Span[0] + 1; + StartColumn = location.Span[1] + 1; + EndLine = hasEndLine ? location.Span[2] + 1 : StartLine; + EndColumn = location.Span[hasEndLine ? 3 : 2] + 1; + LeadingComments = location.LeadingComments; + TrailingComments = location.TrailingComments; + LeadingDetachedComments = new ReadOnlyCollection(location.LeadingDetachedComments.ToList()); + } + + internal static DescriptorDeclaration FromProto(IDescriptor descriptor, Location location) => + new DescriptorDeclaration(descriptor, location); + } +} diff --git a/Libs/Google.Protobuf/Reflection/DescriptorPool.cs b/Libs/Google.Protobuf/Reflection/DescriptorPool.cs new file mode 100644 index 0000000..c6660d0 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/DescriptorPool.cs @@ -0,0 +1,334 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Contains lookup tables containing all the descriptors defined in a particular file. + /// + internal sealed class DescriptorPool + { + private readonly IDictionary descriptorsByName = + new Dictionary(); + + private readonly IDictionary, FieldDescriptor> fieldsByNumber = + new Dictionary, FieldDescriptor>(); + + private readonly IDictionary, EnumValueDescriptor> enumValuesByNumber = + new Dictionary, EnumValueDescriptor>(); + + private readonly HashSet dependencies; + + internal DescriptorPool(IEnumerable dependencyFiles) + { + dependencies = new HashSet(); + foreach (var dependencyFile in dependencyFiles) + { + dependencies.Add(dependencyFile); + ImportPublicDependencies(dependencyFile); + } + + foreach (FileDescriptor dependency in dependencyFiles) + { + AddPackage(dependency.Package, dependency); + } + } + + private void ImportPublicDependencies(FileDescriptor file) + { + foreach (FileDescriptor dependency in file.PublicDependencies) + { + if (dependencies.Add(dependency)) + { + ImportPublicDependencies(dependency); + } + } + } + + /// + /// Finds a symbol of the given name within the pool. + /// + /// The type of symbol to look for + /// Fully-qualified name to look up + /// The symbol with the given name and type, + /// or null if the symbol doesn't exist or has the wrong type + internal T FindSymbol(string fullName) where T : class + { + IDescriptor result; + descriptorsByName.TryGetValue(fullName, out result); + T descriptor = result as T; + if (descriptor != null) + { + return descriptor; + } + + // dependencies contains direct dependencies and any *public* dependencies + // of those dependencies (transitively)... so we don't need to recurse here. + foreach (FileDescriptor dependency in dependencies) + { + dependency.DescriptorPool.descriptorsByName.TryGetValue(fullName, out result); + descriptor = result as T; + if (descriptor != null) + { + return descriptor; + } + } + + return null; + } + + /// + /// Adds a package to the symbol tables. If a package by the same name + /// already exists, that is fine, but if some other kind of symbol + /// exists under the same name, an exception is thrown. If the package + /// has multiple components, this also adds the parent package(s). + /// + internal void AddPackage(string fullName, FileDescriptor file) + { + int dotpos = fullName.LastIndexOf('.'); + String name; + if (dotpos != -1) + { + AddPackage(fullName.Substring(0, dotpos), file); + name = fullName.Substring(dotpos + 1); + } + else + { + name = fullName; + } + + IDescriptor old; + if (descriptorsByName.TryGetValue(fullName, out old)) + { + if (!(old is PackageDescriptor)) + { + throw new DescriptorValidationException(file, + "\"" + name + + "\" is already defined (as something other than a " + + "package) in file \"" + old.File.Name + "\"."); + } + } + descriptorsByName[fullName] = new PackageDescriptor(name, fullName, file); + } + + /// + /// Adds a symbol to the symbol table. + /// + /// The symbol already existed + /// in the symbol table. + internal void AddSymbol(IDescriptor descriptor) + { + ValidateSymbolName(descriptor); + String fullName = descriptor.FullName; + + IDescriptor old; + if (descriptorsByName.TryGetValue(fullName, out old)) + { + int dotPos = fullName.LastIndexOf('.'); + string message; + if (descriptor.File == old.File) + { + if (dotPos == -1) + { + message = "\"" + fullName + "\" is already defined."; + } + else + { + message = "\"" + fullName.Substring(dotPos + 1) + "\" is already defined in \"" + + fullName.Substring(0, dotPos) + "\"."; + } + } + else + { + message = "\"" + fullName + "\" is already defined in file \"" + old.File.Name + "\"."; + } + throw new DescriptorValidationException(descriptor, message); + } + descriptorsByName[fullName] = descriptor; + } + + private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", + FrameworkPortability.CompiledRegexWhereAvailable); + + /// + /// Verifies that the descriptor's name is valid (i.e. it contains + /// only letters, digits and underscores, and does not start with a digit). + /// + /// + private static void ValidateSymbolName(IDescriptor descriptor) + { + if (descriptor.Name == "") + { + throw new DescriptorValidationException(descriptor, "Missing name."); + } + if (!ValidationRegex.IsMatch(descriptor.Name)) + { + throw new DescriptorValidationException(descriptor, + "\"" + descriptor.Name + "\" is not a valid identifier."); + } + } + + /// + /// Returns the field with the given number in the given descriptor, + /// or null if it can't be found. + /// + internal FieldDescriptor FindFieldByNumber(MessageDescriptor messageDescriptor, int number) + { + FieldDescriptor ret; + fieldsByNumber.TryGetValue(new ObjectIntPair(messageDescriptor, number), out ret); + return ret; + } + + internal EnumValueDescriptor FindEnumValueByNumber(EnumDescriptor enumDescriptor, int number) + { + EnumValueDescriptor ret; + enumValuesByNumber.TryGetValue(new ObjectIntPair(enumDescriptor, number), out ret); + return ret; + } + + /// + /// Adds a field to the fieldsByNumber table. + /// + /// A field with the same + /// containing type and number already exists. + internal void AddFieldByNumber(FieldDescriptor field) + { + // for extensions, we use the extended type, otherwise we use the containing type + ObjectIntPair key = new ObjectIntPair(field.Proto.HasExtendee ? field.ExtendeeType : field.ContainingType, field.FieldNumber); + FieldDescriptor old; + if (fieldsByNumber.TryGetValue(key, out old)) + { + throw new DescriptorValidationException(field, "Field number " + field.FieldNumber + + "has already been used in \"" + + field.ContainingType.FullName + + "\" by field \"" + old.Name + "\"."); + } + fieldsByNumber[key] = field; + } + + /// + /// Adds an enum value to the enumValuesByNumber table. If an enum value + /// with the same type and number already exists, this method does nothing. + /// (This is allowed; the first value defined with the number takes precedence.) + /// + internal void AddEnumValueByNumber(EnumValueDescriptor enumValue) + { + ObjectIntPair key = new ObjectIntPair(enumValue.EnumDescriptor, enumValue.Number); + if (!enumValuesByNumber.ContainsKey(key)) + { + enumValuesByNumber[key] = enumValue; + } + } + + /// + /// Looks up a descriptor by name, relative to some other descriptor. + /// The name may be fully-qualified (with a leading '.'), partially-qualified, + /// or unqualified. C++-like name lookup semantics are used to search for the + /// matching descriptor. + /// + /// + /// This isn't heavily optimized, but it's only used during cross linking anyway. + /// If it starts being used more widely, we should look at performance more carefully. + /// + internal IDescriptor LookupSymbol(string name, IDescriptor relativeTo) + { + IDescriptor result; + if (name.StartsWith(".")) + { + // Fully-qualified name. + result = FindSymbol(name.Substring(1)); + } + else + { + // If "name" is a compound identifier, we want to search for the + // first component of it, then search within it for the rest. + int firstPartLength = name.IndexOf('.'); + string firstPart = firstPartLength == -1 ? name : name.Substring(0, firstPartLength); + + // We will search each parent scope of "relativeTo" looking for the + // symbol. + StringBuilder scopeToTry = new StringBuilder(relativeTo.FullName); + + while (true) + { + // Chop off the last component of the scope. + + int dotpos = scopeToTry.ToString().LastIndexOf("."); + if (dotpos == -1) + { + result = FindSymbol(name); + break; + } + else + { + scopeToTry.Length = dotpos + 1; + + // Append firstPart and try to find. + scopeToTry.Append(firstPart); + result = FindSymbol(scopeToTry.ToString()); + + if (result != null) + { + if (firstPartLength != -1) + { + // We only found the first part of the symbol. Now look for + // the whole thing. If this fails, we *don't* want to keep + // searching parent scopes. + scopeToTry.Length = dotpos + 1; + scopeToTry.Append(name); + result = FindSymbol(scopeToTry.ToString()); + } + break; + } + + // Not found. Remove the name so we can try again. + scopeToTry.Length = dotpos; + } + } + } + + if (result == null) + { + throw new DescriptorValidationException(relativeTo, "\"" + name + "\" is not defined."); + } + else + { + return result; + } + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/DescriptorUtil.cs b/Libs/Google.Protobuf/Reflection/DescriptorUtil.cs new file mode 100644 index 0000000..f5da0ff --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/DescriptorUtil.cs @@ -0,0 +1,64 @@ +#region Copyright notice and license +// 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. +#endregion + +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Internal class containing utility methods when working with descriptors. + /// + internal static class DescriptorUtil + { + /// + /// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert + /// arrays. + /// + internal delegate TOutput IndexedConverter(TInput element, int index); + + /// + /// Converts the given array into a read-only list, applying the specified conversion to + /// each input element. + /// + internal static IList ConvertAndMakeReadOnly + (IList input, IndexedConverter converter) + { + TOutput[] array = new TOutput[input.Count]; + for (int i = 0; i < array.Length; i++) + { + array[i] = converter(input[i], i); + } + return new ReadOnlyCollection(array); + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/DescriptorValidationException.cs b/Libs/Google.Protobuf/Reflection/DescriptorValidationException.cs new file mode 100644 index 0000000..bdaf396 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/DescriptorValidationException.cs @@ -0,0 +1,80 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Thrown when building descriptors fails because the source DescriptorProtos + /// are not valid. + /// + public sealed class DescriptorValidationException : Exception + { + private readonly String name; + private readonly string description; + + /// + /// The full name of the descriptor where the error occurred. + /// + public String ProblemSymbolName + { + get { return name; } + } + + /// + /// A human-readable description of the error. (The Message property + /// is made up of the descriptor's name and this description.) + /// + public string Description + { + get { return description; } + } + + internal DescriptorValidationException(IDescriptor problemDescriptor, string description) : + base(problemDescriptor.FullName + ": " + description) + { + // Note that problemDescriptor may be partially uninitialized, so we + // don't want to expose it directly to the user. So, we only provide + // the name and the original proto. + name = problemDescriptor.FullName; + this.description = description; + } + + internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) : + base(problemDescriptor.FullName + ": " + description, cause) + { + name = problemDescriptor.FullName; + this.description = description; + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/EnumDescriptor.cs b/Libs/Google.Protobuf/Reflection/EnumDescriptor.cs new file mode 100644 index 0000000..09a5ebb --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -0,0 +1,161 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; +using System.Collections.Generic; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Descriptor for an enum type in a .proto file. + /// + public sealed class EnumDescriptor : DescriptorBase + { + private readonly EnumDescriptorProto proto; + private readonly MessageDescriptor containingType; + private readonly IList values; + private readonly Type clrType; + + internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType) + : base(file, file.ComputeFullName(parent, proto.Name), index) + { + this.proto = proto; + this.clrType = clrType; + containingType = parent; + + if (proto.Value.Count == 0) + { + // We cannot allow enums with no values because this would mean there + // would be no valid default value for fields of this type. + throw new DescriptorValidationException(this, "Enums must contain at least one value."); + } + + values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value, + (value, i) => new EnumValueDescriptor(value, file, this, i)); + + File.DescriptorPool.AddSymbol(this); + } + + internal EnumDescriptorProto Proto { get { return proto; } } + + /// + /// The brief name of the descriptor's target. + /// + public override string Name { get { return proto.Name; } } + + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) + { + case EnumDescriptorProto.ValueFieldNumber: + return (IReadOnlyList) Values; + default: + return null; + } + } + + /// + /// The CLR type for this enum. For generated code, this will be a CLR enum type. + /// + public Type ClrType { get { return clrType; } } + + /// + /// If this is a nested type, get the outer descriptor, otherwise null. + /// + public MessageDescriptor ContainingType + { + get { return containingType; } + } + + /// + /// An unmodifiable list of defined value descriptors for this enum. + /// + public IList Values + { + get { return values; } + } + + /// + /// Finds an enum value by number. If multiple enum values have the + /// same number, this returns the first defined value with that number. + /// If there is no value for the given number, this returns null. + /// + public EnumValueDescriptor FindValueByNumber(int number) + { + return File.DescriptorPool.FindEnumValueByNumber(this, number); + } + + /// + /// Finds an enum value by name. + /// + /// The unqualified name of the value (e.g. "FOO"). + /// The value's descriptor, or null if not found. + public EnumValueDescriptor FindValueByName(string name) + { + return File.DescriptorPool.FindSymbol(FullName + "." + name); + } + + /// + /// The (possibly empty) set of custom options for this enum. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The EnumOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public EnumOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value enum option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value enum option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/Libs/Google.Protobuf/Reflection/EnumValueDescriptor.cs new file mode 100644 index 0000000..5556751 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -0,0 +1,107 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Descriptor for a single enum value within an enum in a .proto file. + /// + public sealed class EnumValueDescriptor : DescriptorBase + { + private readonly EnumDescriptor enumDescriptor; + private readonly EnumValueDescriptorProto proto; + + internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file, + EnumDescriptor parent, int index) + : base(file, parent.FullName + "." + proto.Name, index) + { + this.proto = proto; + enumDescriptor = parent; + file.DescriptorPool.AddSymbol(this); + file.DescriptorPool.AddEnumValueByNumber(this); + } + + internal EnumValueDescriptorProto Proto { get { return proto; } } + + /// + /// Returns the name of the enum value described by this object. + /// + public override string Name { get { return proto.Name; } } + + /// + /// Returns the number associated with this enum value. + /// + public int Number { get { return Proto.Number; } } + + /// + /// Returns the enum descriptor that this value is part of. + /// + public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } } + + /// + /// The (possibly empty) set of custom options for this enum value. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The EnumValueOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public EnumValueOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value enum value option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value enum value option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + } +} + \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/ExtensionAccessor.cs b/Libs/Google.Protobuf/Reflection/ExtensionAccessor.cs new file mode 100644 index 0000000..79c6053 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/ExtensionAccessor.cs @@ -0,0 +1,69 @@ +#region Copyright notice and license +// 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. +#endregion + +namespace LC.Google.Protobuf.Reflection +{ + internal sealed class ExtensionAccessor : IFieldAccessor + { + private readonly Extension extension; + private readonly ReflectionUtil.IExtensionReflectionHelper helper; + + internal ExtensionAccessor(FieldDescriptor descriptor) + { + Descriptor = descriptor; + extension = descriptor.Extension; + helper = ReflectionUtil.CreateExtensionHelper(extension); + } + + public FieldDescriptor Descriptor { get; } + + public void Clear(IMessage message) + { + helper.ClearExtension(message); + } + + public bool HasValue(IMessage message) + { + return helper.HasExtension(message); + } + + public object GetValue(IMessage message) + { + return helper.GetExtension(message); + } + + public void SetValue(IMessage message, object value) + { + helper.SetExtension(message, value); + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/ExtensionCollection.cs b/Libs/Google.Protobuf/Reflection/ExtensionCollection.cs new file mode 100644 index 0000000..288aa19 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/ExtensionCollection.cs @@ -0,0 +1,126 @@ +#region Copyright notice and license +// 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. +#endregion + +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// A collection to simplify retrieving the descriptors of extensions in a descriptor for a message + /// + public sealed class ExtensionCollection + { + private IDictionary> extensionsByTypeInDeclarationOrder; + private IDictionary> extensionsByTypeInNumberOrder; + + internal ExtensionCollection(FileDescriptor file, Extension[] extensions) + { + UnorderedExtensions = DescriptorUtil.ConvertAndMakeReadOnly( + file.Proto.Extension, + (extension, i) => { + if (extensions?.Length != 0) + { + return new FieldDescriptor(extension, file, null, i, null, extensions?[i]); + } + else + { + return new FieldDescriptor(extension, file, null, i, null, null); // return null if there's no extensions in this array for old code-gen + } + }); + } + + internal ExtensionCollection(MessageDescriptor message, Extension[] extensions) + { + UnorderedExtensions = DescriptorUtil.ConvertAndMakeReadOnly( + message.Proto.Extension, + (extension, i) => { + if (extensions?.Length != 0) + { + return new FieldDescriptor(extension, message.File, message, i, null, extensions?[i]); + } + else + { + return new FieldDescriptor(extension, message.File, message, i, null, null); + } + }); + } + + /// + /// Returns a readonly list of all the extensions defined in this type in + /// the order they were defined in the source .proto file + /// + public IList UnorderedExtensions { get; } + + /// + /// Returns a readonly list of all the extensions define in this type that extend + /// the provided descriptor type in the order they were defined in the source .proto file + /// + public IList GetExtensionsInDeclarationOrder(MessageDescriptor descriptor) + { + return extensionsByTypeInDeclarationOrder[descriptor]; + } + + /// + /// Returns a readonly list of all the extensions define in this type that extend + /// the provided descriptor type in accending field order + /// + public IList GetExtensionsInNumberOrder(MessageDescriptor descriptor) + { + return extensionsByTypeInNumberOrder[descriptor]; + } + + internal void CrossLink() + { + Dictionary> declarationOrder = new Dictionary>(); + foreach (FieldDescriptor descriptor in UnorderedExtensions) + { + descriptor.CrossLink(); + + IList list; + if (!declarationOrder.TryGetValue(descriptor.ExtendeeType, out list)) + { + list = new List(); + declarationOrder.Add(descriptor.ExtendeeType, list); + } + + list.Add(descriptor); + } + + extensionsByTypeInDeclarationOrder = declarationOrder + .ToDictionary(kvp => kvp.Key, kvp => (IList)new ReadOnlyCollection(kvp.Value)); + extensionsByTypeInNumberOrder = declarationOrder + .ToDictionary(kvp => kvp.Key, kvp => (IList)new ReadOnlyCollection(kvp.Value.OrderBy(field => field.FieldNumber).ToArray())); + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/FieldAccessorBase.cs b/Libs/Google.Protobuf/Reflection/FieldAccessorBase.cs new file mode 100644 index 0000000..04cc5b1 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/FieldAccessorBase.cs @@ -0,0 +1,64 @@ +#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.Reflection; +using LC.Google.Protobuf.Compatibility; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Base class for field accessors. + /// + internal abstract class FieldAccessorBase : IFieldAccessor + { + private readonly Func getValueDelegate; + private readonly FieldDescriptor descriptor; + + internal FieldAccessorBase(PropertyInfo property, FieldDescriptor descriptor) + { + this.descriptor = descriptor; + getValueDelegate = ReflectionUtil.CreateFuncIMessageObject(property.GetGetMethod()); + } + + public FieldDescriptor Descriptor { get { return descriptor; } } + + public object GetValue(IMessage message) + { + return getValueDelegate(message); + } + + public abstract bool HasValue(IMessage message); + public abstract void Clear(IMessage message); + public abstract void SetValue(IMessage message, object value); + } +} diff --git a/Libs/Google.Protobuf/Reflection/FieldDescriptor.cs b/Libs/Google.Protobuf/Reflection/FieldDescriptor.cs new file mode 100644 index 0000000..ac85195 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -0,0 +1,455 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using LC.Google.Protobuf.Compatibility; +using System; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Descriptor for a field or extension within a message in a .proto file. + /// + public sealed class FieldDescriptor : DescriptorBase, IComparable + { + private EnumDescriptor enumType; + private MessageDescriptor extendeeType; + private MessageDescriptor messageType; + private FieldType fieldType; + private readonly string propertyName; // Annoyingly, needed in Crosslink. + private IFieldAccessor accessor; + + /// + /// Get the field's containing message type, or null if it is a field defined at the top level of a file as an extension. + /// + public MessageDescriptor ContainingType { get; } + + /// + /// Returns the oneof containing this field, or null if it is not part of a oneof. + /// + public OneofDescriptor ContainingOneof { get; } + + /// + /// Returns the oneof containing this field if it's a "real" oneof, or null if either this + /// field is not part of a oneof, or the oneof is synthetic. + /// + public OneofDescriptor RealContainingOneof => ContainingOneof?.IsSynthetic == false ? ContainingOneof : null; + + /// + /// The effective JSON name for this field. This is usually the lower-camel-cased form of the field name, + /// but can be overridden using the json_name option in the .proto file. + /// + public string JsonName { get; } + + /// + /// Indicates whether this field supports presence, either implicitly (e.g. due to it being a message + /// type field) or explicitly via Has/Clear members. If this returns true, it is safe to call + /// and + /// on this field's accessor with a suitable message. + /// + public bool HasPresence => + Extension != null ? !Extension.IsRepeated + : IsRepeated ? false + : IsMap ? false + : FieldType == FieldType.Message ? true + // This covers "real oneof members" and "proto3 optional fields" + : ContainingOneof != null ? true + : File.Syntax == Syntax.Proto2; + + internal FieldDescriptorProto Proto { get; } + + /// + /// An extension identifier for this field, or null if this field isn't an extension. + /// + public Extension Extension { get; } + + internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file, + MessageDescriptor parent, int index, string propertyName, Extension extension) + : base(file, file.ComputeFullName(parent, proto.Name), index) + { + Proto = proto; + if (proto.Type != 0) + { + fieldType = GetFieldTypeFromProtoType(proto.Type); + } + + if (FieldNumber <= 0) + { + throw new DescriptorValidationException(this, "Field numbers must be positive integers."); + } + ContainingType = parent; + if (proto.HasOneofIndex) + { + if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count) + { + throw new DescriptorValidationException(this, + $"FieldDescriptorProto.oneof_index is out of range for type {parent.Name}"); + } + ContainingOneof = parent.Oneofs[proto.OneofIndex]; + } + + file.DescriptorPool.AddSymbol(this); + // We can't create the accessor until we've cross-linked, unfortunately, as we + // may not know whether the type of the field is a map or not. Remember the property name + // for later. + // We could trust the generated code and check whether the type of the property is + // a MapField, but that feels a tad nasty. + this.propertyName = propertyName; + Extension = extension; + JsonName = Proto.JsonName == "" ? JsonFormatter.ToJsonName(Proto.Name) : Proto.JsonName; + } + + + /// + /// The brief name of the descriptor's target. + /// + public override string Name => Proto.Name; + + /// + /// Returns the accessor for this field. + /// + /// + /// + /// While a describes the field, it does not provide + /// any way of obtaining or changing the value of the field within a specific message; + /// that is the responsibility of the accessor. + /// + /// + /// In descriptors for generated code, the value returned by this property will be non-null for all + /// regular fields. However, if a message containing a map field is introspected, the list of nested messages will include + /// an auto-generated nested key/value pair message for the field. This is not represented in any + /// generated type, and the value of the map field itself is represented by a dictionary in the + /// reflection API. There are never instances of those "hidden" messages, so no accessor is provided + /// and this property will return null. + /// + /// + /// In dynamically loaded descriptors, the value returned by this property will current be null; + /// if and when dynamic messages are supported, it will return a suitable accessor to work with + /// them. + /// + /// + public IFieldAccessor Accessor => accessor; + + /// + /// Maps a field type as included in the .proto file to a FieldType. + /// + private static FieldType GetFieldTypeFromProtoType(FieldDescriptorProto.Types.Type type) + { + switch (type) + { + case FieldDescriptorProto.Types.Type.Double: + return FieldType.Double; + case FieldDescriptorProto.Types.Type.Float: + return FieldType.Float; + case FieldDescriptorProto.Types.Type.Int64: + return FieldType.Int64; + case FieldDescriptorProto.Types.Type.Uint64: + return FieldType.UInt64; + case FieldDescriptorProto.Types.Type.Int32: + return FieldType.Int32; + case FieldDescriptorProto.Types.Type.Fixed64: + return FieldType.Fixed64; + case FieldDescriptorProto.Types.Type.Fixed32: + return FieldType.Fixed32; + case FieldDescriptorProto.Types.Type.Bool: + return FieldType.Bool; + case FieldDescriptorProto.Types.Type.String: + return FieldType.String; + case FieldDescriptorProto.Types.Type.Group: + return FieldType.Group; + case FieldDescriptorProto.Types.Type.Message: + return FieldType.Message; + case FieldDescriptorProto.Types.Type.Bytes: + return FieldType.Bytes; + case FieldDescriptorProto.Types.Type.Uint32: + return FieldType.UInt32; + case FieldDescriptorProto.Types.Type.Enum: + return FieldType.Enum; + case FieldDescriptorProto.Types.Type.Sfixed32: + return FieldType.SFixed32; + case FieldDescriptorProto.Types.Type.Sfixed64: + return FieldType.SFixed64; + case FieldDescriptorProto.Types.Type.Sint32: + return FieldType.SInt32; + case FieldDescriptorProto.Types.Type.Sint64: + return FieldType.SInt64; + default: + throw new ArgumentException("Invalid type specified"); + } + } + + /// + /// Returns true if this field is a repeated field; false otherwise. + /// + public bool IsRepeated => Proto.Label == FieldDescriptorProto.Types.Label.Repeated; + + /// + /// Returns true if this field is a required field; false otherwise. + /// + public bool IsRequired => Proto.Label == FieldDescriptorProto.Types.Label.Required; + + /// + /// Returns true if this field is a map field; false otherwise. + /// + public bool IsMap => fieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry; + + /// + /// Returns true if this field is a packed, repeated field; false otherwise. + /// + public bool IsPacked + { + get + { + if (File.Syntax != Syntax.Proto3) + { + return Proto.Options?.Packed ?? false; + } + else + { + return !Proto.Options.HasPacked || Proto.Options.Packed; + } + } + } + + /// + /// Returns true if this field extends another message type; false otherwise. + /// + public bool IsExtension => Proto.HasExtendee; + + /// + /// Returns the type of the field. + /// + public FieldType FieldType => fieldType; + + /// + /// Returns the field number declared in the proto file. + /// + public int FieldNumber => Proto.Number; + + /// + /// Compares this descriptor with another one, ordering in "canonical" order + /// which simply means ascending order by field number. + /// must be a field of the same type, i.e. the of + /// both fields must be the same. + /// + public int CompareTo(FieldDescriptor other) + { + if (other.ContainingType != ContainingType) + { + throw new ArgumentException("FieldDescriptors can only be compared to other FieldDescriptors " + + "for fields of the same message type."); + } + return FieldNumber - other.FieldNumber; + } + + /// + /// For enum fields, returns the field's type. + /// + public EnumDescriptor EnumType + { + get + { + if (fieldType != FieldType.Enum) + { + throw new InvalidOperationException("EnumType is only valid for enum fields."); + } + return enumType; + } + } + + /// + /// For embedded message and group fields, returns the field's type. + /// + public MessageDescriptor MessageType + { + get + { + if (fieldType != FieldType.Message && fieldType != FieldType.Group) + { + throw new InvalidOperationException("MessageType is only valid for message or group fields."); + } + return messageType; + } + } + + /// + /// For extension fields, returns the extended type + /// + public MessageDescriptor ExtendeeType + { + get + { + if (!Proto.HasExtendee) + { + throw new InvalidOperationException("ExtendeeType is only valid for extension fields."); + } + return extendeeType; + } + } + + /// + /// The (possibly empty) set of custom options for this field. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The FieldOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public FieldOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value field option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value field option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + + /// + /// Look up and cross-link all field types etc. + /// + internal void CrossLink() + { + if (Proto.HasTypeName) + { + IDescriptor typeDescriptor = + File.DescriptorPool.LookupSymbol(Proto.TypeName, this); + + if (Proto.HasType) + { + // Choose field type based on symbol. + if (typeDescriptor is MessageDescriptor) + { + fieldType = FieldType.Message; + } + else if (typeDescriptor is EnumDescriptor) + { + fieldType = FieldType.Enum; + } + else + { + throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a type."); + } + } + + if (fieldType == FieldType.Message || fieldType == FieldType.Group) + { + if (!(typeDescriptor is MessageDescriptor)) + { + throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a message type."); + } + messageType = (MessageDescriptor) typeDescriptor; + + if (Proto.HasDefaultValue) + { + throw new DescriptorValidationException(this, "Messages can't have default values."); + } + } + else if (fieldType == FieldType.Enum) + { + if (!(typeDescriptor is EnumDescriptor)) + { + throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not an enum type."); + } + enumType = (EnumDescriptor) typeDescriptor; + } + else + { + throw new DescriptorValidationException(this, "Field with primitive type has type_name."); + } + } + else + { + if (fieldType == FieldType.Message || fieldType == FieldType.Enum) + { + throw new DescriptorValidationException(this, "Field with message or enum type missing type_name."); + } + } + + if (Proto.HasExtendee) + { + extendeeType = File.DescriptorPool.LookupSymbol(Proto.Extendee, this) as MessageDescriptor; + } + + // Note: no attempt to perform any default value parsing + + File.DescriptorPool.AddFieldByNumber(this); + + if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat) + { + throw new DescriptorValidationException(this, "MessageSet format is not supported."); + } + accessor = CreateAccessor(); + } + + private IFieldAccessor CreateAccessor() + { + if (Extension != null) + { + return new ExtensionAccessor(this); + } + + // If we're given no property name, that's because we really don't want an accessor. + // This could be because it's a map message, or it could be that we're loading a FileDescriptor dynamically. + // TODO: Support dynamic messages. + if (propertyName == null) + { + return null; + } + + var property = ContainingType.ClrType.GetProperty(propertyName); + if (property == null) + { + throw new DescriptorValidationException(this, $"Property {propertyName} not found in {ContainingType.ClrType}"); + } + return IsMap ? new MapFieldAccessor(property, this) + : IsRepeated ? new RepeatedFieldAccessor(property, this) + : (IFieldAccessor) new SingleFieldAccessor(property, this); + } + } +} + \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/FieldType.cs b/Libs/Google.Protobuf/Reflection/FieldType.cs new file mode 100644 index 0000000..c6d0c24 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/FieldType.cs @@ -0,0 +1,113 @@ +#region Copyright notice and license +// 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. +#endregion + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Enumeration of all the possible field types. + /// + public enum FieldType + { + /// + /// The double field type. + /// + Double, + /// + /// The float field type. + /// + Float, + /// + /// The int64 field type. + /// + Int64, + /// + /// The uint64 field type. + /// + UInt64, + /// + /// The int32 field type. + /// + Int32, + /// + /// The fixed64 field type. + /// + Fixed64, + /// + /// The fixed32 field type. + /// + Fixed32, + /// + /// The bool field type. + /// + Bool, + /// + /// The string field type. + /// + String, + /// + /// The field type used for groups. + /// + Group, + /// + /// The field type used for message fields. + /// + Message, + /// + /// The bytes field type. + /// + Bytes, + /// + /// The uint32 field type. + /// + UInt32, + /// + /// The sfixed32 field type. + /// + SFixed32, + /// + /// The sfixed64 field type. + /// + SFixed64, + /// + /// The sint32 field type. + /// + SInt32, + /// + /// The sint64 field type. + /// + SInt64, + /// + /// The field type used for enum fields. + /// + Enum + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/FileDescriptor.cs b/Libs/Google.Protobuf/Reflection/FileDescriptor.cs new file mode 100644 index 0000000..6724ef5 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/FileDescriptor.cs @@ -0,0 +1,608 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using LC.Google.Protobuf.WellKnownTypes; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using static LC.Google.Protobuf.Reflection.SourceCodeInfo.Types; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// The syntax of a .proto file + /// + public enum Syntax + { + /// + /// Proto2 syntax + /// + Proto2, + /// + /// Proto3 syntax + /// + Proto3, + /// + /// An unknown declared syntax + /// + Unknown + } + + /// + /// Describes a .proto file, including everything defined within. + /// IDescriptor is implemented such that the File property returns this descriptor, + /// and the FullName is the same as the Name. + /// + public sealed class FileDescriptor : IDescriptor + { + // Prevent linker failures when using IL2CPP with the well-known types. + static FileDescriptor() + { + ForceReflectionInitialization(); + ForceReflectionInitialization(); + ForceReflectionInitialization(); + ForceReflectionInitialization(); + ForceReflectionInitialization(); + } + + private readonly Lazy> declarations; + + private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, IEnumerable dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) + { + SerializedData = descriptorData; + DescriptorPool = pool; + Proto = proto; + Dependencies = new ReadOnlyCollection(dependencies.ToList()); + + PublicDependencies = DeterminePublicDependencies(this, proto, dependencies, allowUnknownDependencies); + + pool.AddPackage(Package, this); + + MessageTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.MessageType, + (message, index) => + new MessageDescriptor(message, this, null, index, generatedCodeInfo?.NestedTypes[index])); + + EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumType, + (enumType, index) => + new EnumDescriptor(enumType, this, null, index, generatedCodeInfo?.NestedEnums[index])); + + Services = DescriptorUtil.ConvertAndMakeReadOnly(proto.Service, + (service, index) => + new ServiceDescriptor(service, this, index)); + + Extensions = new ExtensionCollection(this, generatedCodeInfo?.Extensions); + + declarations = new Lazy>(CreateDeclarationMap, LazyThreadSafetyMode.ExecutionAndPublication); + + if (!proto.HasSyntax || proto.Syntax == "proto2") + { + Syntax = Syntax.Proto2; + } + else if (proto.Syntax == "proto3") + { + Syntax = Syntax.Proto3; + } + else + { + Syntax = Syntax.Unknown; + } + } + + private Dictionary CreateDeclarationMap() + { + var dictionary = new Dictionary(); + foreach (var location in Proto.SourceCodeInfo?.Location ?? Enumerable.Empty()) + { + var descriptor = FindDescriptorForPath(location.Path); + if (descriptor != null) + { + dictionary[descriptor] = DescriptorDeclaration.FromProto(descriptor, location); + } + } + return dictionary; + } + + private IDescriptor FindDescriptorForPath(IList path) + { + // All complete declarations have an even, non-empty path length + // (There can be an empty path for a descriptor declaration, but that can't have any comments, + // so we currently ignore it.) + if (path.Count == 0 || (path.Count & 1) != 0) + { + return null; + } + IReadOnlyList topLevelList = GetNestedDescriptorListForField(path[0]); + DescriptorBase current = GetDescriptorFromList(topLevelList, path[1]); + + for (int i = 2; current != null && i < path.Count; i += 2) + { + var list = current.GetNestedDescriptorListForField(path[i]); + current = GetDescriptorFromList(list, path[i + 1]); + } + return current; + } + + private DescriptorBase GetDescriptorFromList(IReadOnlyList list, int index) + { + // This is fine: it may be a newer version of protobuf than we understand, with a new descriptor + // field. + if (list == null) + { + return null; + } + // We *could* return null to silently continue, but this is basically data corruption. + if (index < 0 || index >= list.Count) + { + // We don't have much extra information to give at this point unfortunately. If this becomes a problem, + // we can pass in the complete path and report that and the file name. + throw new InvalidProtocolBufferException($"Invalid descriptor location path: index out of range"); + } + return list[index]; + } + + private IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) + { + case FileDescriptorProto.ServiceFieldNumber: + return (IReadOnlyList) Services; + case FileDescriptorProto.MessageTypeFieldNumber: + return (IReadOnlyList) MessageTypes; + case FileDescriptorProto.EnumTypeFieldNumber: + return (IReadOnlyList) EnumTypes; + default: + return null; + } + } + + internal DescriptorDeclaration GetDeclaration(IDescriptor descriptor) + { + DescriptorDeclaration declaration; + declarations.Value.TryGetValue(descriptor, out declaration); + return declaration; + } + + /// + /// Computes the full name of a descriptor within this file, with an optional parent message. + /// + internal string ComputeFullName(MessageDescriptor parent, string name) + { + if (parent != null) + { + return parent.FullName + "." + name; + } + if (Package.Length > 0) + { + return Package + "." + name; + } + return name; + } + + /// + /// Extracts public dependencies from direct dependencies. This is a static method despite its + /// first parameter, as the value we're in the middle of constructing is only used for exceptions. + /// + private static IList DeterminePublicDependencies(FileDescriptor @this, FileDescriptorProto proto, IEnumerable dependencies, bool allowUnknownDependencies) + { + var nameToFileMap = dependencies.ToDictionary(file => file.Name); + var publicDependencies = new List(); + for (int i = 0; i < proto.PublicDependency.Count; i++) + { + int index = proto.PublicDependency[i]; + if (index < 0 || index >= proto.Dependency.Count) + { + throw new DescriptorValidationException(@this, "Invalid public dependency index."); + } + string name = proto.Dependency[index]; + FileDescriptor file; + if (!nameToFileMap.TryGetValue(name, out file)) + { + if (!allowUnknownDependencies) + { + throw new DescriptorValidationException(@this, "Invalid public dependency: " + name); + } + // Ignore unknown dependencies. + } + else + { + publicDependencies.Add(file); + } + } + return new ReadOnlyCollection(publicDependencies); + } + + /// + /// The descriptor in its protocol message representation. + /// + internal FileDescriptorProto Proto { get; } + + /// + /// The syntax of the file + /// + public Syntax Syntax { get; } + + /// + /// The file name. + /// + public string Name => Proto.Name; + + /// + /// The package as declared in the .proto file. This may or may not + /// be equivalent to the .NET namespace of the generated classes. + /// + public string Package => Proto.Package; + + /// + /// Unmodifiable list of top-level message types declared in this file. + /// + public IList MessageTypes { get; } + + /// + /// Unmodifiable list of top-level enum types declared in this file. + /// + public IList EnumTypes { get; } + + /// + /// Unmodifiable list of top-level services declared in this file. + /// + public IList Services { get; } + + /// + /// Unmodifiable list of top-level extensions declared in this file. + /// Note that some extensions may be incomplete (FieldDescriptor.Extension may be null) + /// if this descriptor was generated using a version of protoc that did not fully + /// support extensions in C#. + /// + public ExtensionCollection Extensions { get; } + + /// + /// Unmodifiable list of this file's dependencies (imports). + /// + public IList Dependencies { get; } + + /// + /// Unmodifiable list of this file's public dependencies (public imports). + /// + public IList PublicDependencies { get; } + + /// + /// The original serialized binary form of this descriptor. + /// + public ByteString SerializedData { get; } + + /// + /// Implementation of IDescriptor.FullName - just returns the same as Name. + /// + string IDescriptor.FullName => Name; + + /// + /// Implementation of IDescriptor.File - just returns this descriptor. + /// + FileDescriptor IDescriptor.File => this; + + /// + /// Pool containing symbol descriptors. + /// + internal DescriptorPool DescriptorPool { get; } + + /// + /// Finds a type (message, enum, service or extension) in the file by name. Does not find nested types. + /// + /// The unqualified type name to look for. + /// The type of descriptor to look for + /// The type's descriptor, or null if not found. + public T FindTypeByName(String name) + where T : class, IDescriptor + { + // Don't allow looking up nested types. This will make optimization + // easier later. + if (name.IndexOf('.') != -1) + { + return null; + } + if (Package.Length > 0) + { + name = Package + "." + name; + } + T result = DescriptorPool.FindSymbol(name); + if (result != null && result.File == this) + { + return result; + } + return null; + } + + /// + /// Builds a FileDescriptor from its protocol buffer representation. + /// + /// The original serialized descriptor data. + /// We have only limited proto2 support, so serializing FileDescriptorProto + /// would not necessarily give us this. + /// The protocol message form of the FileDescriptor. + /// FileDescriptors corresponding to all of the + /// file's dependencies, in the exact order listed in the .proto file. May be null, + /// in which case it is treated as an empty array. + /// Whether unknown dependencies are ignored (true) or cause an exception to be thrown (false). + /// Details about generated code, for the purposes of reflection. + /// If is not + /// a valid descriptor. This can occur for a number of reasons, such as a field + /// having an undefined type or because two messages were defined with the same name. + private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) + { + // Building descriptors involves two steps: translating and linking. + // In the translation step (implemented by FileDescriptor's + // constructor), we build an object tree mirroring the + // FileDescriptorProto's tree and put all of the descriptors into the + // DescriptorPool's lookup tables. In the linking step, we look up all + // type references in the DescriptorPool, so that, for example, a + // FieldDescriptor for an embedded message contains a pointer directly + // to the Descriptor for that message's type. We also detect undefined + // types in the linking step. + if (dependencies == null) + { + dependencies = new FileDescriptor[0]; + } + + DescriptorPool pool = new DescriptorPool(dependencies); + FileDescriptor result = new FileDescriptor(descriptorData, proto, dependencies, pool, allowUnknownDependencies, generatedCodeInfo); + + // Validate that the dependencies we've been passed (as FileDescriptors) are actually the ones we + // need. + if (dependencies.Length != proto.Dependency.Count) + { + throw new DescriptorValidationException( + result, + "Dependencies passed to FileDescriptor.BuildFrom() don't match " + + "those listed in the FileDescriptorProto."); + } + + result.CrossLink(); + return result; + } + + private void CrossLink() + { + foreach (MessageDescriptor message in MessageTypes) + { + message.CrossLink(); + } + + foreach (ServiceDescriptor service in Services) + { + service.CrossLink(); + } + + Extensions.CrossLink(); + } + + /// + /// Creates a descriptor for generated code. + /// + /// + /// This method is only designed to be used by the results of generating code with protoc, + /// which creates the appropriate dependencies etc. It has to be public because the generated + /// code is "external", but should not be called directly by end users. + /// + public static FileDescriptor FromGeneratedCode( + byte[] descriptorData, + FileDescriptor[] dependencies, + GeneratedClrTypeInfo generatedCodeInfo) + { + ExtensionRegistry registry = new ExtensionRegistry(); + registry.AddRange(GetAllExtensions(dependencies, generatedCodeInfo)); + + FileDescriptorProto proto; + try + { + proto = FileDescriptorProto.Parser.WithExtensionRegistry(registry).ParseFrom(descriptorData); + } + catch (InvalidProtocolBufferException e) + { + throw new ArgumentException("Failed to parse protocol buffer descriptor for generated code.", e); + } + + try + { + // When building descriptors for generated code, we allow unknown + // dependencies by default. + return BuildFrom(ByteString.CopyFrom(descriptorData), proto, dependencies, true, generatedCodeInfo); + } + catch (DescriptorValidationException e) + { + throw new ArgumentException($"Invalid embedded descriptor for \"{proto.Name}\".", e); + } + } + + private static IEnumerable GetAllExtensions(FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedInfo) + { + return dependencies.SelectMany(GetAllDependedExtensions).Distinct(ExtensionRegistry.ExtensionComparer.Instance).Concat(GetAllGeneratedExtensions(generatedInfo)); + } + + private static IEnumerable GetAllGeneratedExtensions(GeneratedClrTypeInfo generated) + { + return generated.Extensions.Concat(generated.NestedTypes.Where(t => t != null).SelectMany(GetAllGeneratedExtensions)); + } + + private static IEnumerable GetAllDependedExtensions(FileDescriptor descriptor) + { + return descriptor.Extensions.UnorderedExtensions + .Select(s => s.Extension) + .Where(e => e != null) + .Concat(descriptor.Dependencies.Concat(descriptor.PublicDependencies).SelectMany(GetAllDependedExtensions)) + .Concat(descriptor.MessageTypes.SelectMany(GetAllDependedExtensionsFromMessage)); + } + + private static IEnumerable GetAllDependedExtensionsFromMessage(MessageDescriptor descriptor) + { + return descriptor.Extensions.UnorderedExtensions + .Select(s => s.Extension) + .Where(e => e != null) + .Concat(descriptor.NestedTypes.SelectMany(GetAllDependedExtensionsFromMessage)); + } + + /// + /// Converts the given descriptor binary data into FileDescriptor objects. + /// Note: reflection using the returned FileDescriptors is not currently supported. + /// + /// The binary file descriptor proto data. Must not be null, and any + /// dependencies must come before the descriptor which depends on them. (If A depends on B, and B + /// depends on C, then the descriptors must be presented in the order C, B, A.) This is compatible + /// with the order in which protoc provides descriptors to plugins. + /// The extension registry to use when parsing, or null if no extensions are required. + /// The file descriptors corresponding to . + public static IReadOnlyList BuildFromByteStrings(IEnumerable descriptorData, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(descriptorData, nameof(descriptorData)); + + var parser = FileDescriptorProto.Parser.WithExtensionRegistry(registry); + + // TODO: See if we can build a single DescriptorPool instead of building lots of them. + // This will all behave correctly, but it's less efficient than we'd like. + var descriptors = new List(); + var descriptorsByName = new Dictionary(); + foreach (var data in descriptorData) + { + var proto = parser.ParseFrom(data); + var dependencies = new List(); + foreach (var dependencyName in proto.Dependency) + { + FileDescriptor dependency; + if (!descriptorsByName.TryGetValue(dependencyName, out dependency)) + { + throw new ArgumentException($"Dependency missing: {dependencyName}"); + } + dependencies.Add(dependency); + } + var pool = new DescriptorPool(dependencies); + FileDescriptor descriptor = new FileDescriptor( + data, proto, dependencies, pool, + allowUnknownDependencies: false, generatedCodeInfo: null); + descriptor.CrossLink(); + descriptors.Add(descriptor); + if (descriptorsByName.ContainsKey(descriptor.Name)) + { + throw new ArgumentException($"Duplicate descriptor name: {descriptor.Name}"); + } + descriptorsByName.Add(descriptor.Name, descriptor); + } + return new ReadOnlyCollection(descriptors); + } + + /// + /// Converts the given descriptor binary data into FileDescriptor objects. + /// Note: reflection using the returned FileDescriptors is not currently supported. + /// + /// The binary file descriptor proto data. Must not be null, and any + /// dependencies must come before the descriptor which depends on them. (If A depends on B, and B + /// depends on C, then the descriptors must be presented in the order C, B, A.) This is compatible + /// with the order in which protoc provides descriptors to plugins. + /// The file descriptors corresponding to . + public static IReadOnlyList BuildFromByteStrings(IEnumerable descriptorData) => + BuildFromByteStrings(descriptorData, null); + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return $"FileDescriptor for {Name}"; + } + + /// + /// Returns the file descriptor for descriptor.proto. + /// + /// + /// This is used for protos which take a direct dependency on descriptor.proto, typically for + /// annotations. While descriptor.proto is a proto2 file, it is built into the Google.Protobuf + /// runtime for reflection purposes. The messages are internal to the runtime as they would require + /// proto2 semantics for full support, but the file descriptor is available via this property. The + /// C# codegen in protoc automatically uses this property when it detects a dependency on descriptor.proto. + /// + /// + /// The file descriptor for descriptor.proto. + /// + public static FileDescriptor DescriptorProtoFileDescriptor { get { return DescriptorReflection.Descriptor; } } + + /// + /// The (possibly empty) set of custom options for this file. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The FileOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public FileOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value file option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value file option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + + /// + /// Performs initialization for the given generic type argument. + /// + /// + /// This method is present for the sake of AOT compilers. It allows code (whether handwritten or generated) + /// to make calls into the reflection machinery of this library to express an intention to use that type + /// reflectively (e.g. for JSON parsing and formatting). The call itself does almost nothing, but AOT compilers + /// attempting to determine which generic type arguments need to be handled will spot the code path and act + /// accordingly. + /// + /// The type to force initialization for. + public static void ForceReflectionInitialization() => ReflectionUtil.ForceInitialize(); + } +} diff --git a/Libs/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs b/Libs/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs new file mode 100644 index 0000000..74666c2 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs @@ -0,0 +1,128 @@ +#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; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Extra information provided by generated code when initializing a message or file descriptor. + /// These are constructed as required, and are not long-lived. Hand-written code should + /// never need to use this type. + /// + public sealed class GeneratedClrTypeInfo + { + private static readonly string[] EmptyNames = new string[0]; + private static readonly GeneratedClrTypeInfo[] EmptyCodeInfo = new GeneratedClrTypeInfo[0]; + private static readonly Extension[] EmptyExtensions = new Extension[0]; + + /// + /// Irrelevant for file descriptors; the CLR type for the message for message descriptors. + /// + public Type ClrType { get; private set; } + + /// + /// Irrelevant for file descriptors; the parser for message descriptors. + /// + public MessageParser Parser { get; } + + /// + /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order) + /// for fields in the message for message descriptors. + /// + public string[] PropertyNames { get; } + + /// + /// The extensions defined within this file/message descriptor + /// + public Extension[] Extensions { get; } + + /// + /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order) + /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo", + /// there will be a "FooCase" property and a "ClearFoo" method. + /// + public string[] OneofNames { get; } + + /// + /// The reflection information for types within this file/message descriptor. Elements may be null + /// if there is no corresponding generated type, e.g. for map entry types. + /// + public GeneratedClrTypeInfo[] NestedTypes { get; } + + /// + /// The CLR types for enums within this file/message descriptor. + /// + public Type[] NestedEnums { get; } + + /// + /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names. + /// Each array parameter may be null, to indicate a lack of values. + /// The parameter order is designed to make it feasible to format the generated code readably. + /// + public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes) + { + NestedTypes = nestedTypes ?? EmptyCodeInfo; + NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes; + ClrType = clrType; + Extensions = extensions ?? EmptyExtensions; + Parser = parser; + PropertyNames = propertyNames ?? EmptyNames; + OneofNames = oneofNames ?? EmptyNames; + } + + /// + /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names. + /// Each array parameter may be null, to indicate a lack of values. + /// The parameter order is designed to make it feasible to format the generated code readably. + /// + public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) + : this(clrType, parser, propertyNames, oneofNames, nestedEnums, null, nestedTypes) + { + } + + /// + /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types, enums, and extensions. + /// + public GeneratedClrTypeInfo(Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes) + : this(null, null, null, null, nestedEnums, extensions, nestedTypes) + { + } + + /// + /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types and enums. + /// + public GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) + : this(null, null, null, null, nestedEnums, nestedTypes) + { + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/IDescriptor.cs b/Libs/Google.Protobuf/Reflection/IDescriptor.cs new file mode 100644 index 0000000..527a39a --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/IDescriptor.cs @@ -0,0 +1,55 @@ +#region Copyright notice and license +// 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. +#endregion + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Interface implemented by all descriptor types. + /// + public interface IDescriptor + { + /// + /// Returns the name of the entity (message, field etc) being described. + /// + string Name { get; } + + /// + /// Returns the fully-qualified name of the entity being described. + /// + string FullName { get; } + + /// + /// Returns the descriptor for the .proto file that this entity is part of. + /// + FileDescriptor File { get; } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/IFieldAccessor.cs b/Libs/Google.Protobuf/Reflection/IFieldAccessor.cs new file mode 100644 index 0000000..e45517b --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/IFieldAccessor.cs @@ -0,0 +1,77 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Allows fields to be reflectively accessed. + /// + public interface IFieldAccessor + { + /// + /// Returns the descriptor associated with this field. + /// + FieldDescriptor Descriptor { get; } + + /// + /// Clears the field in the specified message. (For repeated fields, + /// this clears the list.) + /// + void Clear(IMessage message); + + /// + /// Fetches the field value. For repeated values, this will be an + /// implementation. For map values, this will be an + /// implementation. + /// + object GetValue(IMessage message); + + /// + /// Indicates whether the field in the specified message is set. + /// For proto3 fields that aren't explicitly optional, this throws an + /// + bool HasValue(IMessage message); + + /// + /// Mutator for single "simple" fields only. + /// + /// + /// Repeated fields are mutated by fetching the value and manipulating it as a list. + /// Map fields are mutated by fetching the value and manipulating it as a dictionary. + /// + /// The field is not a "simple" field. + void SetValue(IMessage message, object value); + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/MapFieldAccessor.cs b/Libs/Google.Protobuf/Reflection/MapFieldAccessor.cs new file mode 100644 index 0000000..71a1c3c --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/MapFieldAccessor.cs @@ -0,0 +1,64 @@ +#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.Reflection; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Accessor for map fields. + /// + internal sealed class MapFieldAccessor : FieldAccessorBase + { + internal MapFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor) + { + } + + public override void Clear(IMessage message) + { + IDictionary list = (IDictionary) GetValue(message); + list.Clear(); + } + + public override bool HasValue(IMessage message) + { + throw new InvalidOperationException("HasValue is not implemented for map fields"); + } + + public override void SetValue(IMessage message, object value) + { + throw new InvalidOperationException("SetValue is not implemented for map fields"); + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/MessageDescriptor.cs b/Libs/Google.Protobuf/Reflection/MessageDescriptor.cs new file mode 100644 index 0000000..a2a1dad --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -0,0 +1,420 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +#if NET35 +// Needed for ReadOnlyDictionary, which does not exist in .NET 3.5 +using LC.Google.Protobuf.Collections; +#endif + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Describes a message type. + /// + public sealed class MessageDescriptor : DescriptorBase + { + private static readonly HashSet WellKnownTypeNames = new HashSet + { + "google/protobuf/any.proto", + "google/protobuf/api.proto", + "google/protobuf/duration.proto", + "google/protobuf/empty.proto", + "google/protobuf/wrappers.proto", + "google/protobuf/timestamp.proto", + "google/protobuf/field_mask.proto", + "google/protobuf/source_context.proto", + "google/protobuf/struct.proto", + "google/protobuf/type.proto", + }; + + private readonly IList fieldsInDeclarationOrder; + private readonly IList fieldsInNumberOrder; + private readonly IDictionary jsonFieldMap; + private Func extensionSetIsInitialized; + + internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo) + : base(file, file.ComputeFullName(parent, proto.Name), typeIndex) + { + Proto = proto; + Parser = generatedCodeInfo?.Parser; + ClrType = generatedCodeInfo?.ClrType; + ContainingType = parent; + + // If generatedCodeInfo is null, we just won't generate an accessor for any fields. + Oneofs = DescriptorUtil.ConvertAndMakeReadOnly( + proto.OneofDecl, + (oneof, index) => + new OneofDescriptor(oneof, file, this, index, generatedCodeInfo?.OneofNames[index])); + + int syntheticOneofCount = 0; + foreach (var oneof in Oneofs) + { + if (oneof.IsSynthetic) + { + syntheticOneofCount++; + } + else if (syntheticOneofCount != 0) + { + throw new ArgumentException("All synthetic oneofs should come after real oneofs"); + } + } + RealOneofCount = Oneofs.Count - syntheticOneofCount; + + NestedTypes = DescriptorUtil.ConvertAndMakeReadOnly( + proto.NestedType, + (type, index) => + new MessageDescriptor(type, file, this, index, generatedCodeInfo?.NestedTypes[index])); + + EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly( + proto.EnumType, + (type, index) => + new EnumDescriptor(type, file, this, index, generatedCodeInfo?.NestedEnums[index])); + + Extensions = new ExtensionCollection(this, generatedCodeInfo?.Extensions); + + fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly( + proto.Field, + (field, index) => + new FieldDescriptor(field, file, this, index, generatedCodeInfo?.PropertyNames[index], null)); + fieldsInNumberOrder = new ReadOnlyCollection(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray()); + // TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.) + jsonFieldMap = CreateJsonFieldMap(fieldsInNumberOrder); + file.DescriptorPool.AddSymbol(this); + Fields = new FieldCollection(this); + } + + private static ReadOnlyDictionary CreateJsonFieldMap(IList fields) + { + var map = new Dictionary(); + foreach (var field in fields) + { + map[field.Name] = field; + map[field.JsonName] = field; + } + return new ReadOnlyDictionary(map); + } + + /// + /// The brief name of the descriptor's target. + /// + public override string Name => Proto.Name; + + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) + { + case DescriptorProto.FieldFieldNumber: + return (IReadOnlyList) fieldsInDeclarationOrder; + case DescriptorProto.NestedTypeFieldNumber: + return (IReadOnlyList) NestedTypes; + case DescriptorProto.EnumTypeFieldNumber: + return (IReadOnlyList) EnumTypes; + default: + return null; + } + } + + internal DescriptorProto Proto { get; } + + internal bool IsExtensionsInitialized(IMessage message) + { + if (Proto.ExtensionRange.Count == 0) + { + return true; + } + + if (extensionSetIsInitialized == null) + { + extensionSetIsInitialized = ReflectionUtil.CreateIsInitializedCaller(ClrType); + } + + return extensionSetIsInitialized(message); + } + + /// + /// The CLR type used to represent message instances from this descriptor. + /// + /// + /// + /// The value returned by this property will be non-null for all regular fields. However, + /// if a message containing a map field is introspected, the list of nested messages will include + /// an auto-generated nested key/value pair message for the field. This is not represented in any + /// generated type, so this property will return null in such cases. + /// + /// + /// For wrapper types ( and the like), the type returned here + /// will be the generated message type, not the native type used by reflection for fields of those types. Code + /// using reflection should call to determine whether a message descriptor represents + /// a wrapper type, and handle the result appropriately. + /// + /// + public Type ClrType { get; } + + /// + /// A parser for this message type. + /// + /// + /// + /// As is not generic, this cannot be statically + /// typed to the relevant type, but it should produce objects of a type compatible with . + /// + /// + /// The value returned by this property will be non-null for all regular fields. However, + /// if a message containing a map field is introspected, the list of nested messages will include + /// an auto-generated nested key/value pair message for the field. No message parser object is created for + /// such messages, so this property will return null in such cases. + /// + /// + /// For wrapper types ( and the like), the parser returned here + /// will be the generated message type, not the native type used by reflection for fields of those types. Code + /// using reflection should call to determine whether a message descriptor represents + /// a wrapper type, and handle the result appropriately. + /// + /// + public MessageParser Parser { get; } + + /// + /// Returns whether this message is one of the "well known types" which may have runtime/protoc support. + /// + internal bool IsWellKnownType => File.Package == "google.protobuf" && WellKnownTypeNames.Contains(File.Name); + + /// + /// Returns whether this message is one of the "wrapper types" used for fields which represent primitive values + /// with the addition of presence. + /// + internal bool IsWrapperType => File.Package == "google.protobuf" && File.Name == "google/protobuf/wrappers.proto"; + + /// + /// If this is a nested type, get the outer descriptor, otherwise null. + /// + public MessageDescriptor ContainingType { get; } + + /// + /// A collection of fields, which can be retrieved by name or field number. + /// + public FieldCollection Fields { get; } + + /// + /// An unmodifiable list of extensions defined in this message's scope. + /// Note that some extensions may be incomplete (FieldDescriptor.Extension may be null) + /// if they are declared in a file generated using a version of protoc that did not fully + /// support extensions in C#. + /// + public ExtensionCollection Extensions { get; } + + /// + /// An unmodifiable list of this message type's nested types. + /// + public IList NestedTypes { get; } + + /// + /// An unmodifiable list of this message type's enum types. + /// + public IList EnumTypes { get; } + + /// + /// An unmodifiable list of the "oneof" field collections in this message type. + /// All "real" oneofs (where returns false) + /// come before synthetic ones. + /// + public IList Oneofs { get; } + + /// + /// The number of real "oneof" descriptors in this message type. Every element in + /// with an index less than this will have a property value + /// of false; every element with an index greater than or equal to this will have a + /// property value of true. + /// + public int RealOneofCount { get; } + + /// + /// Finds a field by field name. + /// + /// The unqualified name of the field (e.g. "foo"). + /// The field's descriptor, or null if not found. + public FieldDescriptor FindFieldByName(String name) => File.DescriptorPool.FindSymbol(FullName + "." + name); + + /// + /// Finds a field by field number. + /// + /// The field number within this message type. + /// The field's descriptor, or null if not found. + public FieldDescriptor FindFieldByNumber(int number) => File.DescriptorPool.FindFieldByNumber(this, number); + + /// + /// Finds a nested descriptor by name. The is valid for fields, nested + /// message types, oneofs and enums. + /// + /// The unqualified name of the descriptor, e.g. "Foo" + /// The descriptor, or null if not found. + public T FindDescriptor(string name) where T : class, IDescriptor => + File.DescriptorPool.FindSymbol(FullName + "." + name); + + /// + /// The (possibly empty) set of custom options for this message. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The MessageOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public MessageOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value message option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value message option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public Collections.RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + + /// + /// Looks up and cross-links all fields and nested types. + /// + internal void CrossLink() + { + foreach (MessageDescriptor message in NestedTypes) + { + message.CrossLink(); + } + + foreach (FieldDescriptor field in fieldsInDeclarationOrder) + { + field.CrossLink(); + } + + foreach (OneofDescriptor oneof in Oneofs) + { + oneof.CrossLink(); + } + + Extensions.CrossLink(); + } + + /// + /// A collection to simplify retrieving the field accessor for a particular field. + /// + public sealed class FieldCollection + { + private readonly MessageDescriptor messageDescriptor; + + internal FieldCollection(MessageDescriptor messageDescriptor) + { + this.messageDescriptor = messageDescriptor; + } + + /// + /// Returns the fields in the message as an immutable list, in the order in which they + /// are declared in the source .proto file. + /// + public IList InDeclarationOrder() => messageDescriptor.fieldsInDeclarationOrder; + + /// + /// Returns the fields in the message as an immutable list, in ascending field number + /// order. Field numbers need not be contiguous, so there is no direct mapping from the + /// index in the list to the field number; to retrieve a field by field number, it is better + /// to use the indexer. + /// + public IList InFieldNumberOrder() => messageDescriptor.fieldsInNumberOrder; + + // TODO: consider making this public in the future. (Being conservative for now...) + + /// + /// Returns a read-only dictionary mapping the field names in this message as they're available + /// in the JSON representation to the field descriptors. For example, a field foo_bar + /// in the message would result two entries, one with a key fooBar and one with a key + /// foo_bar, both referring to the same field. + /// + internal IDictionary ByJsonName() => messageDescriptor.jsonFieldMap; + + /// + /// Retrieves the descriptor for the field with the given number. + /// + /// Number of the field to retrieve the descriptor for + /// The accessor for the given field + /// The message descriptor does not contain a field + /// with the given number + public FieldDescriptor this[int number] + { + get + { + var fieldDescriptor = messageDescriptor.FindFieldByNumber(number); + if (fieldDescriptor == null) + { + throw new KeyNotFoundException("No such field number"); + } + return fieldDescriptor; + } + } + + /// + /// Retrieves the descriptor for the field with the given name. + /// + /// Name of the field to retrieve the descriptor for + /// The descriptor for the given field + /// The message descriptor does not contain a field + /// with the given name + public FieldDescriptor this[string name] + { + get + { + var fieldDescriptor = messageDescriptor.FindFieldByName(name); + if (fieldDescriptor == null) + { + throw new KeyNotFoundException("No such field name"); + } + return fieldDescriptor; + } + } + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/MethodDescriptor.cs b/Libs/Google.Protobuf/Reflection/MethodDescriptor.cs new file mode 100644 index 0000000..9051744 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -0,0 +1,140 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Describes a single method in a service. + /// + public sealed class MethodDescriptor : DescriptorBase + { + private readonly MethodDescriptorProto proto; + private readonly ServiceDescriptor service; + private MessageDescriptor inputType; + private MessageDescriptor outputType; + + /// + /// The service this method belongs to. + /// + public ServiceDescriptor Service { get { return service; } } + + /// + /// The method's input type. + /// + public MessageDescriptor InputType { get { return inputType; } } + + /// + /// The method's input type. + /// + public MessageDescriptor OutputType { get { return outputType; } } + + /// + /// Indicates if client streams multiple requests. + /// + public bool IsClientStreaming { get { return proto.ClientStreaming; } } + + /// + /// Indicates if server streams multiple responses. + /// + public bool IsServerStreaming { get { return proto.ServerStreaming; } } + + /// + /// The (possibly empty) set of custom options for this method. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The MethodOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public MethodOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value method option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value method option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + + internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file, + ServiceDescriptor parent, int index) + : base(file, parent.FullName + "." + proto.Name, index) + { + this.proto = proto; + service = parent; + file.DescriptorPool.AddSymbol(this); + } + + internal MethodDescriptorProto Proto { get { return proto; } } + + /// + /// The brief name of the descriptor's target. + /// + public override string Name { get { return proto.Name; } } + + internal void CrossLink() + { + IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this); + if (!(lookup is MessageDescriptor)) + { + throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type."); + } + inputType = (MessageDescriptor) lookup; + + lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this); + if (!(lookup is MessageDescriptor)) + { + throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type."); + } + outputType = (MessageDescriptor) lookup; + } + } +} + \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/OneofAccessor.cs b/Libs/Google.Protobuf/Reflection/OneofAccessor.cs new file mode 100644 index 0000000..e188059 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/OneofAccessor.cs @@ -0,0 +1,97 @@ +#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.Reflection; +using LC.Google.Protobuf.Compatibility; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Reflection access for a oneof, allowing clear and "get case" actions. + /// + public sealed class OneofAccessor + { + private readonly Func caseDelegate; + private readonly Action clearDelegate; + + private OneofAccessor(OneofDescriptor descriptor, Func caseDelegate, Action clearDelegate) + { + Descriptor = descriptor; + this.caseDelegate = caseDelegate; + this.clearDelegate = clearDelegate; + } + + internal static OneofAccessor ForRegularOneof( + OneofDescriptor descriptor, + PropertyInfo caseProperty, + MethodInfo clearMethod) => + new OneofAccessor( + descriptor, + ReflectionUtil.CreateFuncIMessageInt32(caseProperty.GetGetMethod()), + ReflectionUtil.CreateActionIMessage(clearMethod)); + + internal static OneofAccessor ForSyntheticOneof(OneofDescriptor descriptor) + { + // Note: descriptor.Fields will be null when this method is called, because we haven't + // cross-linked yet. But by the time the delegates are called by user code, all will be + // well. (That's why we capture the descriptor itself rather than a field.) + return new OneofAccessor(descriptor, + message => descriptor.Fields[0].Accessor.HasValue(message) ? descriptor.Fields[0].FieldNumber : 0, + message => descriptor.Fields[0].Accessor.Clear(message)); + } + + /// + /// Gets the descriptor for this oneof. + /// + /// + /// The descriptor of the oneof. + /// + public OneofDescriptor Descriptor { get; } + + /// + /// Clears the oneof in the specified message. + /// + public void Clear(IMessage message) => clearDelegate(message); + + /// + /// Indicates which field in the oneof is set for specified message + /// + public FieldDescriptor GetCaseFieldDescriptor(IMessage message) + { + int fieldNumber = caseDelegate(message); + return fieldNumber > 0 + ? Descriptor.ContainingType.FindFieldByNumber(fieldNumber) + : null; + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/OneofDescriptor.cs b/Libs/Google.Protobuf/Reflection/OneofDescriptor.cs new file mode 100644 index 0000000..d8c21df --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -0,0 +1,195 @@ +#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.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using LC.Google.Protobuf.Collections; +using LC.Google.Protobuf.Compatibility; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Describes a "oneof" field collection in a message type: a set of + /// fields of which at most one can be set in any particular message. + /// + public sealed class OneofDescriptor : DescriptorBase + { + private readonly OneofDescriptorProto proto; + private MessageDescriptor containingType; + private IList fields; + private readonly OneofAccessor accessor; + + internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName) + : base(file, file.ComputeFullName(parent, proto.Name), index) + { + this.proto = proto; + containingType = parent; + file.DescriptorPool.AddSymbol(this); + + // It's useful to determine whether or not this is a synthetic oneof before cross-linking. That means + // diving into the proto directly rather than using FieldDescriptor, but that's okay. + var firstFieldInOneof = parent.Proto.Field.FirstOrDefault(fieldProto => fieldProto.HasOneofIndex && fieldProto.OneofIndex == index); + IsSynthetic = firstFieldInOneof?.Proto3Optional ?? false; + + accessor = CreateAccessor(clrName); + } + + /// + /// The brief name of the descriptor's target. + /// + public override string Name { get { return proto.Name; } } + + /// + /// Gets the message type containing this oneof. + /// + /// + /// The message type containing this oneof. + /// + public MessageDescriptor ContainingType + { + get { return containingType; } + } + + /// + /// Gets the fields within this oneof, in declaration order. + /// + /// + /// The fields within this oneof, in declaration order. + /// + public IList Fields { get { return fields; } } + + /// + /// Returns true if this oneof is a synthetic oneof containing a proto3 optional field; + /// false otherwise. + /// + public bool IsSynthetic { get; } + + /// + /// Gets an accessor for reflective access to the values associated with the oneof + /// in a particular message. + /// + /// + /// + /// In descriptors for generated code, the value returned by this property will always be non-null. + /// + /// + /// In dynamically loaded descriptors, the value returned by this property will current be null; + /// if and when dynamic messages are supported, it will return a suitable accessor to work with + /// them. + /// + /// + /// + /// The accessor used for reflective access. + /// + public OneofAccessor Accessor { get { return accessor; } } + + /// + /// The (possibly empty) set of custom options for this oneof. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions method.")] + public CustomOptions CustomOptions => new CustomOptions(proto.Options?._extensions?.ValuesByNumber); + + /// + /// The OneofOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public OneofOptions GetOptions() => proto.Options?.Clone(); + + /// + /// Gets a single value oneof option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value oneof option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return proto.Options.GetExtension(extension).Clone(); + } + + internal void CrossLink() + { + List fieldCollection = new List(); + foreach (var field in ContainingType.Fields.InDeclarationOrder()) + { + if (field.ContainingOneof == this) + { + fieldCollection.Add(field); + } + } + fields = new ReadOnlyCollection(fieldCollection); + } + + private OneofAccessor CreateAccessor(string clrName) + { + // We won't have a CLR name if this is from a dynamically-loaded FileDescriptor. + // TODO: Support dynamic messages. + if (clrName == null) + { + return null; + } + if (IsSynthetic) + { + return OneofAccessor.ForSyntheticOneof(this); + } + else + { + var caseProperty = containingType.ClrType.GetProperty(clrName + "Case"); + if (caseProperty == null) + { + throw new DescriptorValidationException(this, $"Property {clrName}Case not found in {containingType.ClrType}"); + } + if (!caseProperty.CanRead) + { + throw new ArgumentException($"Cannot read from property {clrName}Case in {containingType.ClrType}"); + } + var clearMethod = containingType.ClrType.GetMethod("Clear" + clrName); + if (clearMethod == null) + { + throw new DescriptorValidationException(this, $"Method Clear{clrName} not found in {containingType.ClrType}"); + } + return OneofAccessor.ForRegularOneof(this, caseProperty, clearMethod); + } + } + } +} diff --git a/Libs/Google.Protobuf/Reflection/OriginalNameAttribute.cs b/Libs/Google.Protobuf/Reflection/OriginalNameAttribute.cs new file mode 100644 index 0000000..a5ea860 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/OriginalNameAttribute.cs @@ -0,0 +1,65 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Specifies the original name (in the .proto file) of a named element, + /// such as an enum value. + /// + [AttributeUsage(AttributeTargets.Field)] + public class OriginalNameAttribute : Attribute + { + /// + /// The name of the element in the .proto file. + /// + public string Name { get; set; } + + /// + /// If the name is preferred in the .proto file. + /// + public bool PreferredAlias { get; set; } + + /// + /// Constructs a new attribute instance for the given name. + /// + /// The name of the element in the .proto file. + public OriginalNameAttribute(string name) + { + Name = ProtoPreconditions.CheckNotNull(name, nameof(name)); + PreferredAlias = true; + } + + } +} diff --git a/Libs/Google.Protobuf/Reflection/PackageDescriptor.cs b/Libs/Google.Protobuf/Reflection/PackageDescriptor.cs new file mode 100644 index 0000000..74847d3 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/PackageDescriptor.cs @@ -0,0 +1,68 @@ +#region Copyright notice and license +// 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. +#endregion + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Represents a package in the symbol table. We use PackageDescriptors + /// just as placeholders so that someone cannot define, say, a message type + /// that has the same name as an existing package. + /// + internal sealed class PackageDescriptor : IDescriptor + { + private readonly string name; + private readonly string fullName; + private readonly FileDescriptor file; + + internal PackageDescriptor(string name, string fullName, FileDescriptor file) + { + this.file = file; + this.fullName = fullName; + this.name = name; + } + + public string Name + { + get { return name; } + } + + public string FullName + { + get { return fullName; } + } + + public FileDescriptor File + { + get { return file; } + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/ReflectionUtil.cs b/Libs/Google.Protobuf/Reflection/ReflectionUtil.cs new file mode 100644 index 0000000..620b421 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/ReflectionUtil.cs @@ -0,0 +1,363 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Compatibility; +using System; +using System.Reflection; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// The methods in this class are somewhat evil, and should not be tampered with lightly. + /// Basically they allow the creation of relatively weakly typed delegates from MethodInfos + /// which are more strongly typed. They do this by creating an appropriate strongly typed + /// delegate from the MethodInfo, and then calling that within an anonymous method. + /// Mind-bending stuff (at least to your humble narrator) but the resulting delegates are + /// very fast compared with calling Invoke later on. + /// + internal static class ReflectionUtil + { + static ReflectionUtil() + { + ForceInitialize(); // Handles all reference types + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + SampleEnumMethod(); + } + + internal static void ForceInitialize() => new ReflectionHelper(); + + /// + /// Empty Type[] used when calling GetProperty to force property instead of indexer fetching. + /// + internal static readonly Type[] EmptyTypes = new Type[0]; + + /// + /// Creates a delegate which will cast the argument to the type that declares the method, + /// call the method on it, then convert the result to object. + /// + /// The method to create a delegate for, which must be declared in an IMessage + /// implementation. + internal static Func CreateFuncIMessageObject(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageObject(method); + + /// + /// Creates a delegate which will cast the argument to the type that declares the method, + /// call the method on it, then convert the result to the specified type. The method is expected + /// to actually return an enum (because of where we're calling it - for oneof cases). Sometimes that + /// means we need some extra work to perform conversions. + /// + /// The method to create a delegate for, which must be declared in an IMessage + /// implementation. + internal static Func CreateFuncIMessageInt32(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageInt32(method); + + /// + /// Creates a delegate which will execute the given method after casting the first argument to + /// the type that declares the method, and the second argument to the first parameter type of the method. + /// + /// The method to create a delegate for, which must be declared in an IMessage + /// implementation. + internal static Action CreateActionIMessageObject(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.GetParameters()[0].ParameterType).CreateActionIMessageObject(method); + + /// + /// Creates a delegate which will execute the given method after casting the first argument to + /// type that declares the method. + /// + /// The method to create a delegate for, which must be declared in an IMessage + /// implementation. + internal static Action CreateActionIMessage(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, typeof(object)).CreateActionIMessage(method); + + internal static Func CreateFuncIMessageBool(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageBool(method); + + internal static Func CreateIsInitializedCaller(Type msg) => + ((IExtensionSetReflector)Activator.CreateInstance(typeof(ExtensionSetReflector<>).MakeGenericType(msg))).CreateIsInitializedCaller(); + + /// + /// Creates a delegate which will execute the given method after casting the first argument to + /// the type that declares the method, and the second argument to the first parameter type of the method. + /// + internal static IExtensionReflectionHelper CreateExtensionHelper(Extension extension) => + (IExtensionReflectionHelper)Activator.CreateInstance(typeof(ExtensionReflectionHelper<,>).MakeGenericType(extension.TargetType, extension.GetType().GenericTypeArguments[1]), extension); + + /// + /// Creates a reflection helper for the given type arguments. Currently these are created on demand + /// rather than cached; this will be "busy" when initially loading a message's descriptor, but after that + /// they can be garbage collected. We could cache them by type if that proves to be important, but creating + /// an object is pretty cheap. + /// + private static IReflectionHelper GetReflectionHelper(Type t1, Type t2) => + (IReflectionHelper) Activator.CreateInstance(typeof(ReflectionHelper<,>).MakeGenericType(t1, t2)); + + // Non-generic interface allowing us to use an instance of ReflectionHelper without statically + // knowing the types involved. + private interface IReflectionHelper + { + Func CreateFuncIMessageInt32(MethodInfo method); + Action CreateActionIMessage(MethodInfo method); + Func CreateFuncIMessageObject(MethodInfo method); + Action CreateActionIMessageObject(MethodInfo method); + Func CreateFuncIMessageBool(MethodInfo method); + } + + internal interface IExtensionReflectionHelper + { + object GetExtension(IMessage message); + void SetExtension(IMessage message, object value); + bool HasExtension(IMessage message); + void ClearExtension(IMessage message); + } + + private interface IExtensionSetReflector + { + Func CreateIsInitializedCaller(); + } + + private class ReflectionHelper : IReflectionHelper + { + + public Func CreateFuncIMessageInt32(MethodInfo method) + { + // On pleasant runtimes, we can create a Func from a method returning + // an enum based on an int. That's the fast path. + if (CanConvertEnumFuncToInt32Func) + { + var del = (Func) method.CreateDelegate(typeof(Func)); + return message => del((T1) message); + } + else + { + // On some runtimes (e.g. old Mono) the return type has to be exactly correct, + // so we go via boxing. Reflection is already fairly inefficient, and this is + // only used for one-of case checking, fortunately. + var del = (Func) method.CreateDelegate(typeof(Func)); + return message => (int) (object) del((T1) message); + } + } + + public Action CreateActionIMessage(MethodInfo method) + { + var del = (Action) method.CreateDelegate(typeof(Action)); + return message => del((T1) message); + } + + public Func CreateFuncIMessageObject(MethodInfo method) + { + var del = (Func) method.CreateDelegate(typeof(Func)); + return message => del((T1) message); + } + + public Action CreateActionIMessageObject(MethodInfo method) + { + var del = (Action) method.CreateDelegate(typeof(Action)); + return (message, arg) => del((T1) message, (T2) arg); + } + + public Func CreateFuncIMessageBool(MethodInfo method) + { + var del = (Func)method.CreateDelegate(typeof(Func)); + return message => del((T1)message); + } + } + + private class ExtensionReflectionHelper : IExtensionReflectionHelper + where T1 : IExtendableMessage + { + private readonly Extension extension; + + public ExtensionReflectionHelper(Extension extension) + { + this.extension = extension; + } + + public object GetExtension(IMessage message) + { + if (!(message is T1)) + { + throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); + } + + T1 extensionMessage = (T1)message; + + if (extension is Extension) + { + return extensionMessage.GetExtension(extension as Extension); + } + else if (extension is RepeatedExtension) + { + return extensionMessage.GetOrInitializeExtension(extension as RepeatedExtension); + } + else + { + throw new InvalidCastException("The provided extension is not a valid extension identifier type"); + } + } + + public bool HasExtension(IMessage message) + { + if (!(message is T1)) + { + throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); + } + + T1 extensionMessage = (T1)message; + + if (extension is Extension) + { + return extensionMessage.HasExtension(extension as Extension); + } + else if (extension is RepeatedExtension) + { + throw new InvalidOperationException("HasValue is not implemented for repeated extensions"); + } + else + { + throw new InvalidCastException("The provided extension is not a valid extension identifier type"); + } + } + + public void SetExtension(IMessage message, object value) + { + if (!(message is T1)) + { + throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); + } + + T1 extensionMessage = (T1)message; + + if (extension is Extension) + { + extensionMessage.SetExtension(extension as Extension, (T3)value); + } + else if (extension is RepeatedExtension) + { + throw new InvalidOperationException("SetValue is not implemented for repeated extensions"); + } + else + { + throw new InvalidCastException("The provided extension is not a valid extension identifier type"); + } + } + + public void ClearExtension(IMessage message) + { + if (!(message is T1)) + { + throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); + } + + T1 extensionMessage = (T1)message; + + if (extension is Extension) + { + extensionMessage.ClearExtension(extension as Extension); + } + else if (extension is RepeatedExtension) + { + extensionMessage.GetExtension(extension as RepeatedExtension).Clear(); + } + else + { + throw new InvalidCastException("The provided extension is not a valid extension identifier type"); + } + } + } + + private class ExtensionSetReflector : IExtensionSetReflector where T1 : IExtendableMessage + { + public Func CreateIsInitializedCaller() + { + var prop = typeof(T1).GetTypeInfo().GetDeclaredProperty("_Extensions"); +#if NET35 + var getFunc = (Func>)prop.GetGetMethod(true).CreateDelegate(typeof(Func>)); +#else + var getFunc = (Func>)prop.GetMethod.CreateDelegate(typeof(Func>)); +#endif + var initializedFunc = (Func, bool>) + typeof(ExtensionSet) + .GetTypeInfo() + .GetDeclaredMethod("IsInitialized") + .CreateDelegate(typeof(Func, bool>)); + return (m) => { + var set = getFunc((T1)m); + return set == null || initializedFunc(set); + }; + } + } + + // Runtime compatibility checking code - see ReflectionHelper.CreateFuncIMessageInt32 for + // details about why we're doing this. + + // Deliberately not inside the generic type. We only want to check this once. + private static bool CanConvertEnumFuncToInt32Func { get; } = CheckCanConvertEnumFuncToInt32Func(); + + private static bool CheckCanConvertEnumFuncToInt32Func() + { + try + { + // Try to do the conversion using reflection, so we can see whether it's supported. + MethodInfo method = typeof(ReflectionUtil).GetMethod(nameof(SampleEnumMethod)); + // If this passes, we're in a reasonable runtime. + method.CreateDelegate(typeof(Func)); + return true; + } + catch (ArgumentException) + { + return false; + } + } + + public enum SampleEnum + { + X + } + + // Public to make the reflection simpler. + public static SampleEnum SampleEnumMethod() => SampleEnum.X; + } +} diff --git a/Libs/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs b/Libs/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs new file mode 100644 index 0000000..bc1a24c --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs @@ -0,0 +1,65 @@ +#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.Reflection; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Accessor for repeated fields. + /// + internal sealed class RepeatedFieldAccessor : FieldAccessorBase + { + internal RepeatedFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor) + { + } + + public override void Clear(IMessage message) + { + IList list = (IList) GetValue(message); + list.Clear(); + } + + public override bool HasValue(IMessage message) + { + throw new InvalidOperationException("HasValue is not implemented for repeated fields"); + } + + public override void SetValue(IMessage message, object value) + { + throw new InvalidOperationException("SetValue is not implemented for repeated fields"); + } + + } +} diff --git a/Libs/Google.Protobuf/Reflection/ServiceDescriptor.cs b/Libs/Google.Protobuf/Reflection/ServiceDescriptor.cs new file mode 100644 index 0000000..79e4edb --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -0,0 +1,136 @@ +#region Copyright notice and license +// 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. +#endregion + +using LC.Google.Protobuf.Collections; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Describes a service type. + /// + public sealed class ServiceDescriptor : DescriptorBase + { + private readonly ServiceDescriptorProto proto; + private readonly IList methods; + + internal ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index) + : base(file, file.ComputeFullName(null, proto.Name), index) + { + this.proto = proto; + methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.Method, + (method, i) => new MethodDescriptor(method, file, this, i)); + + file.DescriptorPool.AddSymbol(this); + } + + /// + /// The brief name of the descriptor's target. + /// + public override string Name { get { return proto.Name; } } + + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) + { + case ServiceDescriptorProto.MethodFieldNumber: + return (IReadOnlyList) methods; + default: + return null; + } + } + + internal ServiceDescriptorProto Proto { get { return proto; } } + + /// + /// An unmodifiable list of methods in this service. + /// + public IList Methods + { + get { return methods; } + } + + /// + /// Finds a method by name. + /// + /// The unqualified name of the method (e.g. "Foo"). + /// The method's descriptor, or null if not found. + public MethodDescriptor FindMethodByName(String name) + { + return File.DescriptorPool.FindSymbol(FullName + "." + name); + } + + /// + /// The (possibly empty) set of custom options for this service. + /// + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + + /// + /// The ServiceOptions, defined in descriptor.proto. + /// If the options message is not present (i.e. there are no options), null is returned. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. + /// + public ServiceOptions GetOptions() => Proto.Options?.Clone(); + + /// + /// Gets a single value service option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public T GetOption(Extension extension) + { + var value = Proto.Options.GetExtension(extension); + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; + } + + /// + /// Gets a repeated value service option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + + internal void CrossLink() + { + foreach (MethodDescriptor method in methods) + { + method.CrossLink(); + } + } + } +} + \ No newline at end of file diff --git a/Libs/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/Libs/Google.Protobuf/Reflection/SingleFieldAccessor.cs new file mode 100644 index 0000000..1fad54f --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/SingleFieldAccessor.cs @@ -0,0 +1,124 @@ +#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.Reflection; +using LC.Google.Protobuf.Compatibility; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// Accessor for single fields. + /// + internal sealed class SingleFieldAccessor : FieldAccessorBase + { + // All the work here is actually done in the constructor - it creates the appropriate delegates. + // There are various cases to consider, based on the property type (message, string/bytes, or "genuine" primitive) + // and proto2 vs proto3 for non-message types, as proto3 doesn't support "full" presence detection or default + // values. + + private readonly Action setValueDelegate; + private readonly Action clearDelegate; + private readonly Func hasDelegate; + + internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor) + { + if (!property.CanWrite) + { + throw new ArgumentException("Not all required properties/methods available"); + } + setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod()); + + // Note: this looks worrying in that we access the containing oneof, which isn't valid until cross-linking + // is complete... but field accessors aren't created until after cross-linking. + // The oneof itself won't be cross-linked yet, but that's okay: the oneof accessor is created + // earlier. + + // Message fields always support presence, via null checks. + if (descriptor.FieldType == FieldType.Message) + { + hasDelegate = message => GetValue(message) != null; + clearDelegate = message => SetValue(message, null); + } + // Oneof fields always support presence, via case checks. + // Note that clearing the field is a no-op unless that specific field is the current "case". + else if (descriptor.RealContainingOneof != null) + { + var oneofAccessor = descriptor.RealContainingOneof.Accessor; + hasDelegate = message => oneofAccessor.GetCaseFieldDescriptor(message) == descriptor; + clearDelegate = message => + { + // Clear on a field only affects the oneof itself if the current case is the field we're accessing. + if (oneofAccessor.GetCaseFieldDescriptor(message) == descriptor) + { + oneofAccessor.Clear(message); + } + }; + } + // Primitive fields always support presence in proto2, and support presence in proto3 for optional fields. + else if (descriptor.File.Syntax == Syntax.Proto2 || descriptor.Proto.Proto3Optional) + { + MethodInfo hasMethod = property.DeclaringType.GetRuntimeProperty("Has" + property.Name).GetMethod; + if (hasMethod == null) + { + throw new ArgumentException("Not all required properties/methods are available"); + } + hasDelegate = ReflectionUtil.CreateFuncIMessageBool(hasMethod); + MethodInfo clearMethod = property.DeclaringType.GetRuntimeMethod("Clear" + property.Name, ReflectionUtil.EmptyTypes); + if (clearMethod == null) + { + throw new ArgumentException("Not all required properties/methods are available"); + } + clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod); + } + // What's left? + // Primitive proto3 fields without the optional keyword, which aren't in oneofs. + else + { + hasDelegate = message => { throw new InvalidOperationException("Presence is not implemented for this field"); }; + + // While presence isn't supported, clearing still is; it's just setting to a default value. + var clrType = property.PropertyType; + + object defaultValue = + clrType == typeof(string) ? "" + : clrType == typeof(ByteString) ? ByteString.Empty + : Activator.CreateInstance(clrType); + clearDelegate = message => SetValue(message, defaultValue); + } + } + + public override void Clear(IMessage message) => clearDelegate(message); + public override bool HasValue(IMessage message) => hasDelegate(message); + public override void SetValue(IMessage message, object value) => setValueDelegate(message, value); + } +} diff --git a/Libs/Google.Protobuf/Reflection/TypeRegistry.cs b/Libs/Google.Protobuf/Reflection/TypeRegistry.cs new file mode 100644 index 0000000..0d3c556 --- /dev/null +++ b/Libs/Google.Protobuf/Reflection/TypeRegistry.cs @@ -0,0 +1,183 @@ +#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.Collections.Generic; +using System.Linq; + +namespace LC.Google.Protobuf.Reflection +{ + /// + /// An immutable registry of types which can be looked up by their full name. + /// + public sealed class TypeRegistry + { + /// + /// An empty type registry, containing no types. + /// + public static TypeRegistry Empty { get; } = new TypeRegistry(new Dictionary()); + + private readonly Dictionary fullNameToMessageMap; + + private TypeRegistry(Dictionary fullNameToMessageMap) + { + this.fullNameToMessageMap = fullNameToMessageMap; + } + + /// + /// Attempts to find a message descriptor by its full name. + /// + /// The full name of the message, which is the dot-separated + /// combination of package, containing messages and message name + /// The message descriptor corresponding to or null + /// if there is no such message descriptor. + public MessageDescriptor Find(string fullName) + { + MessageDescriptor ret; + // Ignore the return value as ret will end up with the right value either way. + fullNameToMessageMap.TryGetValue(fullName, out ret); + return ret; + } + + /// + /// Creates a type registry from the specified set of file descriptors. + /// + /// + /// This is a convenience overload for + /// to allow calls such as TypeRegistry.FromFiles(descriptor1, descriptor2). + /// + /// The set of files to include in the registry. Must not contain null values. + /// A type registry for the given files. + public static TypeRegistry FromFiles(params FileDescriptor[] fileDescriptors) + { + return FromFiles((IEnumerable) fileDescriptors); + } + + /// + /// Creates a type registry from the specified set of file descriptors. + /// + /// + /// All message types within all the specified files are added to the registry, and + /// the dependencies of the specified files are also added, recursively. + /// + /// The set of files to include in the registry. Must not contain null values. + /// A type registry for the given files. + public static TypeRegistry FromFiles(IEnumerable fileDescriptors) + { + ProtoPreconditions.CheckNotNull(fileDescriptors, nameof(fileDescriptors)); + var builder = new Builder(); + foreach (var file in fileDescriptors) + { + builder.AddFile(file); + } + return builder.Build(); + } + + /// + /// Creates a type registry from the file descriptor parents of the specified set of message descriptors. + /// + /// + /// This is a convenience overload for + /// to allow calls such as TypeRegistry.FromFiles(descriptor1, descriptor2). + /// + /// The set of message descriptors to use to identify file descriptors to include in the registry. + /// Must not contain null values. + /// A type registry for the given files. + public static TypeRegistry FromMessages(params MessageDescriptor[] messageDescriptors) + { + return FromMessages((IEnumerable) messageDescriptors); + } + + /// + /// Creates a type registry from the file descriptor parents of the specified set of message descriptors. + /// + /// + /// The specified message descriptors are only used to identify their file descriptors; the returned registry + /// contains all the types within the file descriptors which contain the specified message descriptors (and + /// the dependencies of those files), not just the specified messages. + /// + /// The set of message descriptors to use to identify file descriptors to include in the registry. + /// Must not contain null values. + /// A type registry for the given files. + public static TypeRegistry FromMessages(IEnumerable messageDescriptors) + { + ProtoPreconditions.CheckNotNull(messageDescriptors, nameof(messageDescriptors)); + return FromFiles(messageDescriptors.Select(md => md.File)); + } + + /// + /// Builder class which isn't exposed, but acts as a convenient alternative to passing round two dictionaries in recursive calls. + /// + private class Builder + { + private readonly Dictionary types; + private readonly HashSet fileDescriptorNames; + + internal Builder() + { + types = new Dictionary(); + fileDescriptorNames = new HashSet(); + } + + internal void AddFile(FileDescriptor fileDescriptor) + { + if (!fileDescriptorNames.Add(fileDescriptor.Name)) + { + return; + } + foreach (var dependency in fileDescriptor.Dependencies) + { + AddFile(dependency); + } + foreach (var message in fileDescriptor.MessageTypes) + { + AddMessage(message); + } + } + + private void AddMessage(MessageDescriptor messageDescriptor) + { + foreach (var nestedType in messageDescriptor.NestedTypes) + { + AddMessage(nestedType); + } + // This will overwrite any previous entry. Given that each file should + // only be added once, this could be a problem such as package A.B with type C, + // and package A with type B.C... it's unclear what we should do in that case. + types[messageDescriptor.FullName] = messageDescriptor; + } + + internal TypeRegistry Build() + { + return new TypeRegistry(types); + } + } + } +} diff --git a/Libs/Google.Protobuf/SegmentedBufferHelper.cs b/Libs/Google.Protobuf/SegmentedBufferHelper.cs new file mode 100644 index 0000000..b6fe363 --- /dev/null +++ b/Libs/Google.Protobuf/SegmentedBufferHelper.cs @@ -0,0 +1,296 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Buffers; +using System.IO; +using System.Runtime.CompilerServices; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// Abstraction for reading from a stream / read only sequence. + /// Parsing from the buffer is a loop of reading from current buffer / refreshing the buffer once done. + /// + [SecuritySafeCritical] + internal struct SegmentedBufferHelper + { + private int? totalLength; + private ReadOnlySequence.Enumerator readOnlySequenceEnumerator; + private CodedInputStream codedInputStream; + + /// + /// Initialize an instance with a coded input stream. + /// This approach is faster than using a constructor because the instance to initialize is passed by reference + /// and we can write directly into it without copying. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Initialize(CodedInputStream codedInputStream, out SegmentedBufferHelper instance) + { + instance.totalLength = codedInputStream.InternalInputStream == null ? (int?)codedInputStream.InternalBuffer.Length : null; + instance.readOnlySequenceEnumerator = default; + instance.codedInputStream = codedInputStream; + } + + /// + /// Initialize an instance with a read only sequence. + /// This approach is faster than using a constructor because the instance to initialize is passed by reference + /// and we can write directly into it without copying. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Initialize(ReadOnlySequence sequence, out SegmentedBufferHelper instance, out ReadOnlySpan firstSpan) + { + instance.codedInputStream = null; + if (sequence.IsSingleSegment) + { + firstSpan = sequence.First.Span; + instance.totalLength = firstSpan.Length; + instance.readOnlySequenceEnumerator = default; + } + else + { + instance.readOnlySequenceEnumerator = sequence.GetEnumerator(); + instance.totalLength = (int) sequence.Length; + + // set firstSpan to the first segment + instance.readOnlySequenceEnumerator.MoveNext(); + firstSpan = instance.readOnlySequenceEnumerator.Current.Span; + } + } + + public bool RefillBuffer(ref ReadOnlySpan buffer, ref ParserInternalState state, bool mustSucceed) + { + if (codedInputStream != null) + { + return RefillFromCodedInputStream(ref buffer, ref state, mustSucceed); + } + else + { + return RefillFromReadOnlySequence(ref buffer, ref state, mustSucceed); + } + } + + public int? TotalLength => totalLength; + + public CodedInputStream CodedInputStream => codedInputStream; + + /// + /// Sets currentLimit to (current position) + byteLimit. This is called + /// when descending into a length-delimited embedded message. The previous + /// limit is returned. + /// + /// The old limit. + public static int PushLimit(ref ParserInternalState state, int byteLimit) + { + if (byteLimit < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + byteLimit += state.totalBytesRetired + state.bufferPos; + int oldLimit = state.currentLimit; + if (byteLimit > oldLimit) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + state.currentLimit = byteLimit; + + RecomputeBufferSizeAfterLimit(ref state); + + return oldLimit; + } + + /// + /// Discards the current limit, returning the previous limit. + /// + public static void PopLimit(ref ParserInternalState state, int oldLimit) + { + state.currentLimit = oldLimit; + RecomputeBufferSizeAfterLimit(ref state); + } + + /// + /// Returns whether or not all the data before the limit has been read. + /// + /// + public static bool IsReachedLimit(ref ParserInternalState state) + { + if (state.currentLimit == int.MaxValue) + { + return false; + } + int currentAbsolutePosition = state.totalBytesRetired + state.bufferPos; + return currentAbsolutePosition >= state.currentLimit; + } + + /// + /// Returns true if the stream has reached the end of the input. This is the + /// case if either the end of the underlying input source has been reached or + /// the stream has reached a limit created using PushLimit. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsAtEnd(ref ReadOnlySpan buffer, ref ParserInternalState state) + { + return state.bufferPos == state.bufferSize && !state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, false); + } + + private bool RefillFromReadOnlySequence(ref ReadOnlySpan buffer, ref ParserInternalState state, bool mustSucceed) + { + CheckCurrentBufferIsEmpty(ref state); + + if (state.totalBytesRetired + state.bufferSize == state.currentLimit) + { + // Oops, we hit a limit. + if (mustSucceed) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + else + { + return false; + } + } + + state.totalBytesRetired += state.bufferSize; + + state.bufferPos = 0; + state.bufferSize = 0; + while (readOnlySequenceEnumerator.MoveNext()) + { + buffer = readOnlySequenceEnumerator.Current.Span; + state.bufferSize = buffer.Length; + if (buffer.Length != 0) + { + break; + } + } + + if (state.bufferSize == 0) + { + if (mustSucceed) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + else + { + return false; + } + } + else + { + RecomputeBufferSizeAfterLimit(ref state); + int totalBytesRead = + state.totalBytesRetired + state.bufferSize + state.bufferSizeAfterLimit; + if (totalBytesRead < 0 || totalBytesRead > state.sizeLimit) + { + throw InvalidProtocolBufferException.SizeLimitExceeded(); + } + return true; + } + } + + private bool RefillFromCodedInputStream(ref ReadOnlySpan buffer, ref ParserInternalState state, bool mustSucceed) + { + CheckCurrentBufferIsEmpty(ref state); + + if (state.totalBytesRetired + state.bufferSize == state.currentLimit) + { + // Oops, we hit a limit. + if (mustSucceed) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + else + { + return false; + } + } + + Stream input = codedInputStream.InternalInputStream; + + state.totalBytesRetired += state.bufferSize; + + state.bufferPos = 0; + state.bufferSize = (input == null) ? 0 : input.Read(codedInputStream.InternalBuffer, 0, buffer.Length); + if (state.bufferSize < 0) + { + throw new InvalidOperationException("Stream.Read returned a negative count"); + } + if (state.bufferSize == 0) + { + if (mustSucceed) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + else + { + return false; + } + } + else + { + RecomputeBufferSizeAfterLimit(ref state); + int totalBytesRead = + state.totalBytesRetired + state.bufferSize + state.bufferSizeAfterLimit; + if (totalBytesRead < 0 || totalBytesRead > state.sizeLimit) + { + throw InvalidProtocolBufferException.SizeLimitExceeded(); + } + return true; + } + } + + private static void RecomputeBufferSizeAfterLimit(ref ParserInternalState state) + { + state.bufferSize += state.bufferSizeAfterLimit; + int bufferEnd = state.totalBytesRetired + state.bufferSize; + if (bufferEnd > state.currentLimit) + { + // Limit is in current buffer. + state.bufferSizeAfterLimit = bufferEnd - state.currentLimit; + state.bufferSize -= state.bufferSizeAfterLimit; + } + else + { + state.bufferSizeAfterLimit = 0; + } + } + + private static void CheckCurrentBufferIsEmpty(ref ParserInternalState state) + { + if (state.bufferPos < state.bufferSize) + { + throw new InvalidOperationException("RefillBuffer() called when buffer wasn't empty."); + } + } + } +} \ No newline at end of file diff --git a/Libs/Google.Protobuf/UnknownField.cs b/Libs/Google.Protobuf/UnknownField.cs new file mode 100644 index 0000000..6a386d4 --- /dev/null +++ b/Libs/Google.Protobuf/UnknownField.cs @@ -0,0 +1,290 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2017 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.Generic; +using System.Collections.ObjectModel; +using LC.Google.Protobuf.Collections; + +namespace LC.Google.Protobuf +{ + /// + /// Represents a single field in an UnknownFieldSet. + /// + /// An UnknownField consists of four lists of values. The lists correspond + /// to the four "wire types" used in the protocol buffer binary format. + /// Normally, only one of the four lists will contain any values, since it + /// is impossible to define a valid message type that declares two different + /// types for the same field number. However, the code is designed to allow + /// for the case where the same unknown field number is encountered using + /// multiple different wire types. + /// + /// + internal sealed class UnknownField + { + private List varintList; + private List fixed32List; + private List fixed64List; + private List lengthDelimitedList; + private List groupList; + + /// + /// Creates a new UnknownField. + /// + public UnknownField() + { + } + + /// + /// Checks if two unknown field are equal. + /// + public override bool Equals(object other) + { + if (ReferenceEquals(this, other)) + { + return true; + } + UnknownField otherField = other as UnknownField; + return otherField != null + && Lists.Equals(varintList, otherField.varintList) + && Lists.Equals(fixed32List, otherField.fixed32List) + && Lists.Equals(fixed64List, otherField.fixed64List) + && Lists.Equals(lengthDelimitedList, otherField.lengthDelimitedList) + && Lists.Equals(groupList, otherField.groupList); + } + + /// + /// Get the hash code of the unknown field. + /// + public override int GetHashCode() + { + int hash = 43; + hash = hash * 47 + Lists.GetHashCode(varintList); + hash = hash * 47 + Lists.GetHashCode(fixed32List); + hash = hash * 47 + Lists.GetHashCode(fixed64List); + hash = hash * 47 + Lists.GetHashCode(lengthDelimitedList); + hash = hash * 47 + Lists.GetHashCode(groupList); + return hash; + } + + /// + /// Serializes the field, including the field number, and writes it to + /// + /// + /// The unknown field number. + /// The write context to write to. + internal void WriteTo(int fieldNumber, ref WriteContext output) + { + if (varintList != null) + { + foreach (ulong value in varintList) + { + output.WriteTag(fieldNumber, WireFormat.WireType.Varint); + output.WriteUInt64(value); + } + } + if (fixed32List != null) + { + foreach (uint value in fixed32List) + { + output.WriteTag(fieldNumber, WireFormat.WireType.Fixed32); + output.WriteFixed32(value); + } + } + if (fixed64List != null) + { + foreach (ulong value in fixed64List) + { + output.WriteTag(fieldNumber, WireFormat.WireType.Fixed64); + output.WriteFixed64(value); + } + } + if (lengthDelimitedList != null) + { + foreach (ByteString value in lengthDelimitedList) + { + output.WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); + output.WriteBytes(value); + } + } + if (groupList != null) + { + foreach (UnknownFieldSet value in groupList) + { + output.WriteTag(fieldNumber, WireFormat.WireType.StartGroup); + value.WriteTo(ref output); + output.WriteTag(fieldNumber, WireFormat.WireType.EndGroup); + } + } + } + + /// + /// Computes the number of bytes required to encode this field, including field + /// number. + /// + internal int GetSerializedSize(int fieldNumber) + { + int result = 0; + if (varintList != null) + { + result += CodedOutputStream.ComputeTagSize(fieldNumber) * varintList.Count; + foreach (ulong value in varintList) + { + result += CodedOutputStream.ComputeUInt64Size(value); + } + } + if (fixed32List != null) + { + result += CodedOutputStream.ComputeTagSize(fieldNumber) * fixed32List.Count; + result += CodedOutputStream.ComputeFixed32Size(1) * fixed32List.Count; + } + if (fixed64List != null) + { + result += CodedOutputStream.ComputeTagSize(fieldNumber) * fixed64List.Count; + result += CodedOutputStream.ComputeFixed64Size(1) * fixed64List.Count; + } + if (lengthDelimitedList != null) + { + result += CodedOutputStream.ComputeTagSize(fieldNumber) * lengthDelimitedList.Count; + foreach (ByteString value in lengthDelimitedList) + { + result += CodedOutputStream.ComputeBytesSize(value); + } + } + if (groupList != null) + { + result += CodedOutputStream.ComputeTagSize(fieldNumber) * 2 * groupList.Count; + foreach (UnknownFieldSet value in groupList) + { + result += value.CalculateSize(); + } + } + return result; + } + + /// + /// Merge the values in into this field. For each list + /// of values, 's values are append to the ones in this + /// field. + /// + internal UnknownField MergeFrom(UnknownField other) + { + varintList = AddAll(varintList, other.varintList); + fixed32List = AddAll(fixed32List, other.fixed32List); + fixed64List = AddAll(fixed64List, other.fixed64List); + lengthDelimitedList = AddAll(lengthDelimitedList, other.lengthDelimitedList); + groupList = AddAll(groupList, other.groupList); + return this; + } + + /// + /// Returns a new list containing all of the given specified values from + /// both the and lists. + /// If is null and is null or empty, + /// null is returned. Otherwise, either a new list is created (if + /// is null) or the elements of are added to . + /// + private static List AddAll(List current, IList extras) + { + if (extras == null || extras.Count == 0) + { + return current; + } + if (current == null) + { + current = new List(extras); + } + else + { + current.AddRange(extras); + } + return current; + } + + /// + /// Adds a varint value. + /// + internal UnknownField AddVarint(ulong value) + { + varintList = Add(varintList, value); + return this; + } + + /// + /// Adds a fixed32 value. + /// + internal UnknownField AddFixed32(uint value) + { + fixed32List = Add(fixed32List, value); + return this; + } + + /// + /// Adds a fixed64 value. + /// + internal UnknownField AddFixed64(ulong value) + { + fixed64List = Add(fixed64List, value); + return this; + } + + /// + /// Adds a length-delimited value. + /// + internal UnknownField AddLengthDelimited(ByteString value) + { + lengthDelimitedList = Add(lengthDelimitedList, value); + return this; + } + + internal UnknownField AddGroup(UnknownFieldSet value) + { + groupList = Add(groupList, value); + return this; + } + + /// + /// Adds to the , creating + /// a new list if is null. The list is returned - either + /// the original reference or the new list. + /// + private static List Add(List list, T value) + { + if (list == null) + { + list = new List(); + } + list.Add(value); + return list; + } + } +} diff --git a/Libs/Google.Protobuf/UnknownFieldSet.cs b/Libs/Google.Protobuf/UnknownFieldSet.cs new file mode 100644 index 0000000..039d396 --- /dev/null +++ b/Libs/Google.Protobuf/UnknownFieldSet.cs @@ -0,0 +1,393 @@ +#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.Generic; +using System.IO; +using System.Security; +using LC.Google.Protobuf.Reflection; + +namespace LC.Google.Protobuf +{ + /// + /// Used to keep track of fields which were seen when parsing a protocol message + /// but whose field numbers or types are unrecognized. This most frequently + /// occurs when new fields are added to a message type and then messages containing + /// those fields are read by old software that was built before the new types were + /// added. + /// + /// Most users will never need to use this class directly. + /// + public sealed partial class UnknownFieldSet + { + private readonly IDictionary fields; + + /// + /// Creates a new UnknownFieldSet. + /// + internal UnknownFieldSet() + { + this.fields = new Dictionary(); + } + + /// + /// Checks whether or not the given field number is present in the set. + /// + internal bool HasField(int field) + { + return fields.ContainsKey(field); + } + + /// + /// Serializes the set and writes it to . + /// + public void WriteTo(CodedOutputStream output) + { + WriteContext.Initialize(output, out WriteContext ctx); + try + { + WriteTo(ref ctx); + } + finally + { + ctx.CopyStateTo(output); + } + } + + /// + /// Serializes the set and writes it to . + /// + [SecuritySafeCritical] + public void WriteTo(ref WriteContext ctx) + { + foreach (KeyValuePair entry in fields) + { + entry.Value.WriteTo(entry.Key, ref ctx); + } + } + + /// + /// Gets the number of bytes required to encode this set. + /// + public int CalculateSize() + { + int result = 0; + foreach (KeyValuePair entry in fields) + { + result += entry.Value.GetSerializedSize(entry.Key); + } + return result; + } + + /// + /// Checks if two unknown field sets are equal. + /// + public override bool Equals(object other) + { + if (ReferenceEquals(this, other)) + { + return true; + } + UnknownFieldSet otherSet = other as UnknownFieldSet; + IDictionary otherFields = otherSet.fields; + if (fields.Count != otherFields.Count) + { + return false; + } + foreach (KeyValuePair leftEntry in fields) + { + UnknownField rightValue; + if (!otherFields.TryGetValue(leftEntry.Key, out rightValue)) + { + return false; + } + if (!leftEntry.Value.Equals(rightValue)) + { + return false; + } + } + return true; + } + + /// + /// Gets the unknown field set's hash code. + /// + public override int GetHashCode() + { + int ret = 1; + foreach (KeyValuePair field in fields) + { + // Use ^ here to make the field order irrelevant. + int hash = field.Key.GetHashCode() ^ field.Value.GetHashCode(); + ret ^= hash; + } + return ret; + } + + // Optimization: We keep around the last field that was + // modified so that we can efficiently add to it multiple times in a + // row (important when parsing an unknown repeated field). + private int lastFieldNumber; + private UnknownField lastField; + + private UnknownField GetOrAddField(int number) + { + if (lastField != null && number == lastFieldNumber) + { + return lastField; + } + if (number == 0) + { + return null; + } + + UnknownField existing; + if (fields.TryGetValue(number, out existing)) + { + return existing; + } + lastField = new UnknownField(); + AddOrReplaceField(number, lastField); + lastFieldNumber = number; + return lastField; + } + + /// + /// Adds a field to the set. If a field with the same number already exists, it + /// is replaced. + /// + internal UnknownFieldSet AddOrReplaceField(int number, UnknownField field) + { + if (number == 0) + { + throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number."); + } + fields[number] = field; + return this; + } + + /// + /// Parse a single field from and merge it + /// into this set. + /// + /// The parse context from which to read the field + /// false if the tag is an "end group" tag, true otherwise + private bool MergeFieldFrom(ref ParseContext ctx) + { + uint tag = ctx.LastTag; + int number = WireFormat.GetTagFieldNumber(tag); + switch (WireFormat.GetTagWireType(tag)) + { + case WireFormat.WireType.Varint: + { + ulong uint64 = ctx.ReadUInt64(); + GetOrAddField(number).AddVarint(uint64); + return true; + } + case WireFormat.WireType.Fixed32: + { + uint uint32 = ctx.ReadFixed32(); + GetOrAddField(number).AddFixed32(uint32); + return true; + } + case WireFormat.WireType.Fixed64: + { + ulong uint64 = ctx.ReadFixed64(); + GetOrAddField(number).AddFixed64(uint64); + return true; + } + case WireFormat.WireType.LengthDelimited: + { + ByteString bytes = ctx.ReadBytes(); + GetOrAddField(number).AddLengthDelimited(bytes); + return true; + } + case WireFormat.WireType.StartGroup: + { + UnknownFieldSet set = new UnknownFieldSet(); + ParsingPrimitivesMessages.ReadGroup(ref ctx, number, set); + GetOrAddField(number).AddGroup(set); + return true; + } + case WireFormat.WireType.EndGroup: + { + return false; + } + default: + throw InvalidProtocolBufferException.InvalidWireType(); + } + } + + internal void MergeGroupFrom(ref ParseContext ctx) + { + while (true) + { + uint tag = ctx.ReadTag(); + if (tag == 0) + { + break; + } + if (!MergeFieldFrom(ref ctx)) + { + break; + } + } + } + + /// + /// Create a new UnknownFieldSet if unknownFields is null. + /// Parse a single field from and merge it + /// into unknownFields. If is configured to discard unknown fields, + /// will be returned as-is and the field will be skipped. + /// + /// The UnknownFieldSet which need to be merged + /// The coded input stream containing the field + /// The merged UnknownFieldSet + public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields, + CodedInputStream input) + { + ParseContext.Initialize(input, out ParseContext ctx); + try + { + return MergeFieldFrom(unknownFields, ref ctx); + } + finally + { + ctx.CopyStateTo(input); + } + } + + /// + /// Create a new UnknownFieldSet if unknownFields is null. + /// Parse a single field from and merge it + /// into unknownFields. If is configured to discard unknown fields, + /// will be returned as-is and the field will be skipped. + /// + /// The UnknownFieldSet which need to be merged + /// The parse context from which to read the field + /// The merged UnknownFieldSet + [SecuritySafeCritical] + public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields, + ref ParseContext ctx) + { + if (ctx.DiscardUnknownFields) + { + ParsingPrimitivesMessages.SkipLastField(ref ctx.buffer, ref ctx.state); + return unknownFields; + } + if (unknownFields == null) + { + unknownFields = new UnknownFieldSet(); + } + if (!unknownFields.MergeFieldFrom(ref ctx)) + { + throw new InvalidProtocolBufferException("Merge an unknown field of end-group tag, indicating that the corresponding start-group was missing."); // match the old code-gen + } + return unknownFields; + } + + /// + /// Merges the fields from into this set. + /// If a field number exists in both sets, the values in + /// will be appended to the values in this set. + /// + private UnknownFieldSet MergeFrom(UnknownFieldSet other) + { + if (other != null) + { + foreach (KeyValuePair entry in other.fields) + { + MergeField(entry.Key, entry.Value); + } + } + return this; + } + + /// + /// Created a new UnknownFieldSet to if + /// needed and merges the fields from into the first set. + /// If a field number exists in both sets, the values in + /// will be appended to the values in this set. + /// + public static UnknownFieldSet MergeFrom(UnknownFieldSet unknownFields, + UnknownFieldSet other) + { + if (other == null) + { + return unknownFields; + } + if (unknownFields == null) + { + unknownFields = new UnknownFieldSet(); + } + unknownFields.MergeFrom(other); + return unknownFields; + } + + + /// + /// Adds a field to the unknown field set. If a field with the same + /// number already exists, the two are merged. + /// + private UnknownFieldSet MergeField(int number, UnknownField field) + { + if (number == 0) + { + throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number."); + } + if (HasField(number)) + { + GetOrAddField(number).MergeFrom(field); + } + else + { + AddOrReplaceField(number, field); + } + return this; + } + + /// + /// Clone an unknown field set from . + /// + public static UnknownFieldSet Clone(UnknownFieldSet other) + { + if (other == null) + { + return null; + } + UnknownFieldSet unknownFields = new UnknownFieldSet(); + unknownFields.MergeFrom(other); + return unknownFields; + } + } +} + diff --git a/Libs/Google.Protobuf/UnsafeByteOperations.cs b/Libs/Google.Protobuf/UnsafeByteOperations.cs new file mode 100644 index 0000000..42cc138 --- /dev/null +++ b/Libs/Google.Protobuf/UnsafeByteOperations.cs @@ -0,0 +1,81 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Security; + +namespace LC.Google.Protobuf +{ + /// + /// Provides a number of unsafe byte operations to be used by advanced applications with high performance + /// requirements. These methods are referred to as "unsafe" due to the fact that they potentially expose + /// the backing buffer of a to the application. + /// + /// + /// + /// The methods in this class should only be called if it is guaranteed that the buffer backing the + /// will never change! Mutation of a can lead to unexpected + /// and undesirable consequences in your application, and will likely be difficult to debug. Proceed with caution! + /// + /// + /// This can have a number of significant side affects that have spooky-action-at-a-distance-like behavior. In + /// particular, if the bytes value changes out from under a Protocol Buffer: + /// + /// + /// + /// serialization may throw + /// + /// + /// serialization may succeed but the wrong bytes may be written out + /// + /// + /// objects that are normally immutable (such as ByteString) are no longer immutable + /// + /// + /// hashCode may be incorrect + /// + /// + /// + [SecuritySafeCritical] + public static class UnsafeByteOperations + { + /// + /// Constructs a new from the given bytes. The bytes are not copied, + /// and must not be modified while the is in use. + /// This API is experimental and subject to change. + /// + public static ByteString UnsafeWrap(ReadOnlyMemory bytes) + { + return ByteString.AttachBytes(bytes); + } + } +} diff --git a/Libs/Google.Protobuf/WellKnownTypes/Any.cs b/Libs/Google.Protobuf/WellKnownTypes/Any.cs new file mode 100644 index 0000000..c4d0b7d --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Any.cs @@ -0,0 +1,369 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/any.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/any.proto + public static partial class AnyReflection { + + #region Descriptor + /// File descriptor for google/protobuf/any.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static AnyReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Chlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYi", + "JgoDQW55EhAKCHR5cGVfdXJsGAEgASgJEg0KBXZhbHVlGAIgASgMQnYKE2Nv", + "bS5nb29nbGUucHJvdG9idWZCCEFueVByb3RvUAFaLGdvb2dsZS5nb2xhbmcu", + "b3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL2FueXBiogIDR1BCqgIeR29vZ2xl", + "LlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Any), global::LC.Google.Protobuf.WellKnownTypes.Any.Parser, new[]{ "TypeUrl", "Value" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// `Any` contains an arbitrary serialized protocol buffer message along with a + /// URL that describes the type of the serialized message. + /// + /// Protobuf library provides support to pack/unpack Any values in the form + /// of utility functions or additional generated methods of the Any type. + /// + /// Example 1: Pack and unpack a message in C++. + /// + /// Foo foo = ...; + /// Any any; + /// any.PackFrom(foo); + /// ... + /// if (any.UnpackTo(&foo)) { + /// ... + /// } + /// + /// Example 2: Pack and unpack a message in Java. + /// + /// Foo foo = ...; + /// Any any = Any.pack(foo); + /// ... + /// if (any.is(Foo.class)) { + /// foo = any.unpack(Foo.class); + /// } + /// + /// Example 3: Pack and unpack a message in Python. + /// + /// foo = Foo(...) + /// any = Any() + /// any.Pack(foo) + /// ... + /// if any.Is(Foo.DESCRIPTOR): + /// any.Unpack(foo) + /// ... + /// + /// Example 4: Pack and unpack a message in Go + /// + /// foo := &pb.Foo{...} + /// any, err := anypb.New(foo) + /// if err != nil { + /// ... + /// } + /// ... + /// foo := &pb.Foo{} + /// if err := any.UnmarshalTo(foo); err != nil { + /// ... + /// } + /// + /// The pack methods provided by protobuf library will by default use + /// 'type.googleapis.com/full.type.name' as the type URL and the unpack + /// methods only use the fully qualified type name after the last '/' + /// in the type URL, for example "foo.bar.com/x/y.z" will yield type + /// name "y.z". + /// + /// JSON + /// ==== + /// The JSON representation of an `Any` value uses the regular + /// representation of the deserialized, embedded message, with an + /// additional field `@type` which contains the type URL. Example: + /// + /// package google.profile; + /// message Person { + /// string first_name = 1; + /// string last_name = 2; + /// } + /// + /// { + /// "@type": "type.googleapis.com/google.profile.Person", + /// "firstName": <string>, + /// "lastName": <string> + /// } + /// + /// If the embedded message type is well-known and has a custom JSON + /// representation, that representation will be embedded adding a field + /// `value` which holds the custom JSON in addition to the `@type` + /// field. Example (for message [google.protobuf.Duration][]): + /// + /// { + /// "@type": "type.googleapis.com/google.protobuf.Duration", + /// "value": "1.212s" + /// } + /// + public sealed partial class Any : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Any()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Any() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Any(Any other) : this() { + typeUrl_ = other.typeUrl_; + value_ = other.value_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Any Clone() { + return new Any(this); + } + + /// Field number for the "type_url" field. + public const int TypeUrlFieldNumber = 1; + private string typeUrl_ = ""; + /// + /// A URL/resource name that uniquely identifies the type of the serialized + /// protocol buffer message. This string must contain at least + /// one "/" character. The last segment of the URL's path must represent + /// the fully qualified name of the type (as in + /// `path/google.protobuf.Duration`). The name should be in a canonical form + /// (e.g., leading "." is not accepted). + /// + /// In practice, teams usually precompile into the binary all types that they + /// expect it to use in the context of Any. However, for URLs which use the + /// scheme `http`, `https`, or no scheme, one can optionally set up a type + /// server that maps type URLs to message definitions as follows: + /// + /// * If no scheme is provided, `https` is assumed. + /// * An HTTP GET on the URL must yield a [google.protobuf.Type][] + /// value in binary format, or produce an error. + /// * Applications are allowed to cache lookup results based on the + /// URL, or have them precompiled into a binary to avoid any + /// lookup. Therefore, binary compatibility needs to be preserved + /// on changes to types. (Use versioned type names to manage + /// breaking changes.) + /// + /// Note: this functionality is not currently available in the official + /// protobuf release, and it is not used for type URLs beginning with + /// type.googleapis.com. + /// + /// Schemes other than `http`, `https` (or the empty scheme) might be + /// used with implementation specific semantics. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TypeUrl { + get { return typeUrl_; } + set { + typeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "value" field. + public const int ValueFieldNumber = 2; + private pb::ByteString value_ = pb::ByteString.Empty; + /// + /// Must be a valid serialized protocol buffer of the above specified type. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString Value { + get { return value_; } + set { + value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Any); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Any other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (TypeUrl != other.TypeUrl) return false; + if (Value != other.Value) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (TypeUrl.Length != 0) hash ^= TypeUrl.GetHashCode(); + if (Value.Length != 0) hash ^= Value.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (TypeUrl.Length != 0) { + output.WriteRawTag(10); + output.WriteString(TypeUrl); + } + if (Value.Length != 0) { + output.WriteRawTag(18); + output.WriteBytes(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (TypeUrl.Length != 0) { + output.WriteRawTag(10); + output.WriteString(TypeUrl); + } + if (Value.Length != 0) { + output.WriteRawTag(18); + output.WriteBytes(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (TypeUrl.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeUrl); + } + if (Value.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(Value); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Any other) { + if (other == null) { + return; + } + if (other.TypeUrl.Length != 0) { + TypeUrl = other.TypeUrl; + } + if (other.Value.Length != 0) { + Value = other.Value; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + TypeUrl = input.ReadString(); + break; + } + case 18: { + Value = input.ReadBytes(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + TypeUrl = input.ReadString(); + break; + } + case 18: { + Value = input.ReadBytes(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/AnyPartial.cs b/Libs/Google.Protobuf/WellKnownTypes/AnyPartial.cs new file mode 100644 index 0000000..cfd6760 --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/AnyPartial.cs @@ -0,0 +1,147 @@ +#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 LC.Google.Protobuf.Reflection; + +namespace LC.Google.Protobuf.WellKnownTypes +{ + public partial class Any + { + private const string DefaultPrefix = "type.googleapis.com"; + + // This could be moved to MessageDescriptor if we wanted to, but keeping it here means + // all the Any-specific code is in the same place. + private static string GetTypeUrl(MessageDescriptor descriptor, string prefix) => + prefix.EndsWith("/") ? prefix + descriptor.FullName : prefix + "/" + descriptor.FullName; + + /// + /// Retrieves the type name for a type URL, matching the + /// of the packed message type. + /// + /// + /// + /// This is always just the last part of the URL, after the final slash. No validation of + /// anything before the trailing slash is performed. If the type URL does not include a slash, + /// an empty string is returned rather than an exception being thrown; this won't match any types, + /// and the calling code is probably in a better position to give a meaningful error. + /// + /// + /// There is no handling of fragments or queries at the moment. + /// + /// + /// The URL to extract the type name from + /// The type name + public static string GetTypeName(string typeUrl) + { + ProtoPreconditions.CheckNotNull(typeUrl, nameof(typeUrl)); + int lastSlash = typeUrl.LastIndexOf('/'); + return lastSlash == -1 ? "" : typeUrl.Substring(lastSlash + 1); + } + + /// + /// Returns a bool indictating whether this Any message is of the target message type + /// + /// The descriptor of the message type + /// true if the type name matches the descriptor's full name or false otherwise + public bool Is(MessageDescriptor descriptor) + { + ProtoPreconditions.CheckNotNull(descriptor, nameof(descriptor)); + return GetTypeName(TypeUrl) == descriptor.FullName; + } + + /// + /// Unpacks the content of this Any message into the target message type, + /// which must match the type URL within this Any message. + /// + /// The type of message to unpack the content into. + /// The unpacked message. + /// The target message type doesn't match the type URL in this message + public T Unpack() where T : IMessage, new() + { + // Note: this doesn't perform as well is it might. We could take a MessageParser in an alternative overload, + // which would be expected to perform slightly better... although the difference is likely to be negligible. + T target = new T(); + if (GetTypeName(TypeUrl) != target.Descriptor.FullName) + { + throw new InvalidProtocolBufferException( + $"Full type name for {target.Descriptor.Name} is {target.Descriptor.FullName}; Any message's type url is {TypeUrl}"); + } + target.MergeFrom(Value); + return target; + } + + /// + /// Attempts to unpack the content of this Any message into the target message type, + /// if it matches the type URL within this Any message. + /// + /// The type of message to attempt to unpack the content into. + /// true if the message was successfully unpacked; false if the type name didn't match + public bool TryUnpack(out T result) where T : IMessage, new() + { + // Note: deliberately avoid writing anything to result until the end, in case it's being + // monitored by other threads. (That would be a bug in the calling code, but let's not make it worse.) + T target = new T(); + if (GetTypeName(TypeUrl) != target.Descriptor.FullName) + { + result = default(T); // Can't use null as there's no class constraint, but this always *will* be null in real usage. + return false; + } + target.MergeFrom(Value); + result = target; + return true; + } + + /// + /// Packs the specified message into an Any message using a type URL prefix of "type.googleapis.com". + /// + /// The message to pack. + /// An Any message with the content and type URL of . + public static Any Pack(IMessage message) => Pack(message, DefaultPrefix); + + /// + /// Packs the specified message into an Any message using the specified type URL prefix. + /// + /// The message to pack. + /// The prefix for the type URL. + /// An Any message with the content and type URL of . + public static Any Pack(IMessage message, string typeUrlPrefix) + { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + ProtoPreconditions.CheckNotNull(typeUrlPrefix, nameof(typeUrlPrefix)); + return new Any + { + TypeUrl = GetTypeUrl(message.Descriptor, typeUrlPrefix), + Value = message.ToByteString() + }; + } + } +} diff --git a/Libs/Google.Protobuf/WellKnownTypes/Api.cs b/Libs/Google.Protobuf/WellKnownTypes/Api.cs new file mode 100644 index 0000000..176d509 --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Api.cs @@ -0,0 +1,1172 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/api.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/api.proto + public static partial class ApiReflection { + + #region Descriptor + /// File descriptor for google/protobuf/api.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static ApiReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Chlnb29nbGUvcHJvdG9idWYvYXBpLnByb3RvEg9nb29nbGUucHJvdG9idWYa", + "JGdvb2dsZS9wcm90b2J1Zi9zb3VyY2VfY29udGV4dC5wcm90bxoaZ29vZ2xl", + "L3Byb3RvYnVmL3R5cGUucHJvdG8igQIKA0FwaRIMCgRuYW1lGAEgASgJEigK", + "B21ldGhvZHMYAiADKAsyFy5nb29nbGUucHJvdG9idWYuTWV0aG9kEigKB29w", + "dGlvbnMYAyADKAsyFy5nb29nbGUucHJvdG9idWYuT3B0aW9uEg8KB3ZlcnNp", + "b24YBCABKAkSNgoOc291cmNlX2NvbnRleHQYBSABKAsyHi5nb29nbGUucHJv", + "dG9idWYuU291cmNlQ29udGV4dBImCgZtaXhpbnMYBiADKAsyFi5nb29nbGUu", + "cHJvdG9idWYuTWl4aW4SJwoGc3ludGF4GAcgASgOMhcuZ29vZ2xlLnByb3Rv", + "YnVmLlN5bnRheCLVAQoGTWV0aG9kEgwKBG5hbWUYASABKAkSGAoQcmVxdWVz", + "dF90eXBlX3VybBgCIAEoCRIZChFyZXF1ZXN0X3N0cmVhbWluZxgDIAEoCBIZ", + "ChFyZXNwb25zZV90eXBlX3VybBgEIAEoCRIaChJyZXNwb25zZV9zdHJlYW1p", + "bmcYBSABKAgSKAoHb3B0aW9ucxgGIAMoCzIXLmdvb2dsZS5wcm90b2J1Zi5P", + "cHRpb24SJwoGc3ludGF4GAcgASgOMhcuZ29vZ2xlLnByb3RvYnVmLlN5bnRh", + "eCIjCgVNaXhpbhIMCgRuYW1lGAEgASgJEgwKBHJvb3QYAiABKAlCdgoTY29t", + "Lmdvb2dsZS5wcm90b2J1ZkIIQXBpUHJvdG9QAVosZ29vZ2xlLmdvbGFuZy5v", + "cmcvcHJvdG9idWYvdHlwZXMva25vd24vYXBpcGKiAgNHUEKqAh5Hb29nbGUu", + "UHJvdG9idWYuV2VsbEtub3duVHlwZXNiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::LC.Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor, global::LC.Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Api), global::LC.Google.Protobuf.WellKnownTypes.Api.Parser, new[]{ "Name", "Methods", "Options", "Version", "SourceContext", "Mixins", "Syntax" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Method), global::LC.Google.Protobuf.WellKnownTypes.Method.Parser, new[]{ "Name", "RequestTypeUrl", "RequestStreaming", "ResponseTypeUrl", "ResponseStreaming", "Options", "Syntax" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Mixin), global::LC.Google.Protobuf.WellKnownTypes.Mixin.Parser, new[]{ "Name", "Root" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// Api is a light-weight descriptor for an API Interface. + /// + /// Interfaces are also described as "protocol buffer services" in some contexts, + /// such as by the "service" keyword in a .proto file, but they are different + /// from API Services, which represent a concrete implementation of an interface + /// as opposed to simply a description of methods and bindings. They are also + /// sometimes simply referred to as "APIs" in other contexts, such as the name of + /// this message itself. See https://cloud.google.com/apis/design/glossary for + /// detailed terminology. + /// + public sealed partial class Api : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Api()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Api() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Api(Api other) : this() { + name_ = other.name_; + methods_ = other.methods_.Clone(); + options_ = other.options_.Clone(); + version_ = other.version_; + sourceContext_ = other.sourceContext_ != null ? other.sourceContext_.Clone() : null; + mixins_ = other.mixins_.Clone(); + syntax_ = other.syntax_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Api Clone() { + return new Api(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// The fully qualified name of this interface, including package name + /// followed by the interface's simple name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "methods" field. + public const int MethodsFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_methods_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.WellKnownTypes.Method.Parser); + private readonly pbc::RepeatedField methods_ = new pbc::RepeatedField(); + /// + /// The methods of this interface, in unspecified order. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Methods { + get { return methods_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_options_codec + = pb::FieldCodec.ForMessage(26, global::LC.Google.Protobuf.WellKnownTypes.Option.Parser); + private readonly pbc::RepeatedField options_ = new pbc::RepeatedField(); + /// + /// Any metadata attached to the interface. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Options { + get { return options_; } + } + + /// Field number for the "version" field. + public const int VersionFieldNumber = 4; + private string version_ = ""; + /// + /// A version string for this interface. If specified, must have the form + /// `major-version.minor-version`, as in `1.10`. If the minor version is + /// omitted, it defaults to zero. If the entire version field is empty, the + /// major version is derived from the package name, as outlined below. If the + /// field is not empty, the version in the package name will be verified to be + /// consistent with what is provided here. + /// + /// The versioning schema uses [semantic + /// versioning](http://semver.org) where the major version number + /// indicates a breaking change and the minor version an additive, + /// non-breaking change. Both version numbers are signals to users + /// what to expect from different versions, and should be carefully + /// chosen based on the product plan. + /// + /// The major version is also reflected in the package name of the + /// interface, which must end in `v<major-version>`, as in + /// `google.feature.v1`. For major versions 0 and 1, the suffix can + /// be omitted. Zero major versions must only be used for + /// experimental, non-GA interfaces. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Version { + get { return version_; } + set { + version_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "source_context" field. + public const int SourceContextFieldNumber = 5; + private global::LC.Google.Protobuf.WellKnownTypes.SourceContext sourceContext_; + /// + /// Source context for the protocol buffer service represented by this + /// message. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.SourceContext SourceContext { + get { return sourceContext_; } + set { + sourceContext_ = value; + } + } + + /// Field number for the "mixins" field. + public const int MixinsFieldNumber = 6; + private static readonly pb::FieldCodec _repeated_mixins_codec + = pb::FieldCodec.ForMessage(50, global::LC.Google.Protobuf.WellKnownTypes.Mixin.Parser); + private readonly pbc::RepeatedField mixins_ = new pbc::RepeatedField(); + /// + /// Included interfaces. See [Mixin][]. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Mixins { + get { return mixins_; } + } + + /// Field number for the "syntax" field. + public const int SyntaxFieldNumber = 7; + private global::LC.Google.Protobuf.WellKnownTypes.Syntax syntax_ = global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2; + /// + /// The source syntax of the service. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Syntax Syntax { + get { return syntax_; } + set { + syntax_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Api); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Api other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!methods_.Equals(other.methods_)) return false; + if(!options_.Equals(other.options_)) return false; + if (Version != other.Version) return false; + if (!object.Equals(SourceContext, other.SourceContext)) return false; + if(!mixins_.Equals(other.mixins_)) return false; + if (Syntax != other.Syntax) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + hash ^= methods_.GetHashCode(); + hash ^= options_.GetHashCode(); + if (Version.Length != 0) hash ^= Version.GetHashCode(); + if (sourceContext_ != null) hash ^= SourceContext.GetHashCode(); + hash ^= mixins_.GetHashCode(); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) hash ^= Syntax.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + methods_.WriteTo(output, _repeated_methods_codec); + options_.WriteTo(output, _repeated_options_codec); + if (Version.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Version); + } + if (sourceContext_ != null) { + output.WriteRawTag(42); + output.WriteMessage(SourceContext); + } + mixins_.WriteTo(output, _repeated_mixins_codec); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(56); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + methods_.WriteTo(ref output, _repeated_methods_codec); + options_.WriteTo(ref output, _repeated_options_codec); + if (Version.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Version); + } + if (sourceContext_ != null) { + output.WriteRawTag(42); + output.WriteMessage(SourceContext); + } + mixins_.WriteTo(ref output, _repeated_mixins_codec); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(56); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += methods_.CalculateSize(_repeated_methods_codec); + size += options_.CalculateSize(_repeated_options_codec); + if (Version.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Version); + } + if (sourceContext_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContext); + } + size += mixins_.CalculateSize(_repeated_mixins_codec); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Api other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + methods_.Add(other.methods_); + options_.Add(other.options_); + if (other.Version.Length != 0) { + Version = other.Version; + } + if (other.sourceContext_ != null) { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + SourceContext.MergeFrom(other.SourceContext); + } + mixins_.Add(other.mixins_); + if (other.Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + Syntax = other.Syntax; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + methods_.AddEntriesFrom(input, _repeated_methods_codec); + break; + } + case 26: { + options_.AddEntriesFrom(input, _repeated_options_codec); + break; + } + case 34: { + Version = input.ReadString(); + break; + } + case 42: { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 50: { + mixins_.AddEntriesFrom(input, _repeated_mixins_codec); + break; + } + case 56: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + methods_.AddEntriesFrom(ref input, _repeated_methods_codec); + break; + } + case 26: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 34: { + Version = input.ReadString(); + break; + } + case 42: { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 50: { + mixins_.AddEntriesFrom(ref input, _repeated_mixins_codec); + break; + } + case 56: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + + } + + /// + /// Method represents a method of an API interface. + /// + public sealed partial class Method : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Method()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Method() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Method(Method other) : this() { + name_ = other.name_; + requestTypeUrl_ = other.requestTypeUrl_; + requestStreaming_ = other.requestStreaming_; + responseTypeUrl_ = other.responseTypeUrl_; + responseStreaming_ = other.responseStreaming_; + options_ = other.options_.Clone(); + syntax_ = other.syntax_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Method Clone() { + return new Method(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// The simple name of this method. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "request_type_url" field. + public const int RequestTypeUrlFieldNumber = 2; + private string requestTypeUrl_ = ""; + /// + /// A URL of the input message type. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string RequestTypeUrl { + get { return requestTypeUrl_; } + set { + requestTypeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "request_streaming" field. + public const int RequestStreamingFieldNumber = 3; + private bool requestStreaming_; + /// + /// If true, the request is streamed. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool RequestStreaming { + get { return requestStreaming_; } + set { + requestStreaming_ = value; + } + } + + /// Field number for the "response_type_url" field. + public const int ResponseTypeUrlFieldNumber = 4; + private string responseTypeUrl_ = ""; + /// + /// The URL of the output message type. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ResponseTypeUrl { + get { return responseTypeUrl_; } + set { + responseTypeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "response_streaming" field. + public const int ResponseStreamingFieldNumber = 5; + private bool responseStreaming_; + /// + /// If true, the response is streamed. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool ResponseStreaming { + get { return responseStreaming_; } + set { + responseStreaming_ = value; + } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 6; + private static readonly pb::FieldCodec _repeated_options_codec + = pb::FieldCodec.ForMessage(50, global::LC.Google.Protobuf.WellKnownTypes.Option.Parser); + private readonly pbc::RepeatedField options_ = new pbc::RepeatedField(); + /// + /// Any metadata attached to the method. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Options { + get { return options_; } + } + + /// Field number for the "syntax" field. + public const int SyntaxFieldNumber = 7; + private global::LC.Google.Protobuf.WellKnownTypes.Syntax syntax_ = global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2; + /// + /// The source syntax of this method. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Syntax Syntax { + get { return syntax_; } + set { + syntax_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Method); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Method other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (RequestTypeUrl != other.RequestTypeUrl) return false; + if (RequestStreaming != other.RequestStreaming) return false; + if (ResponseTypeUrl != other.ResponseTypeUrl) return false; + if (ResponseStreaming != other.ResponseStreaming) return false; + if(!options_.Equals(other.options_)) return false; + if (Syntax != other.Syntax) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (RequestTypeUrl.Length != 0) hash ^= RequestTypeUrl.GetHashCode(); + if (RequestStreaming != false) hash ^= RequestStreaming.GetHashCode(); + if (ResponseTypeUrl.Length != 0) hash ^= ResponseTypeUrl.GetHashCode(); + if (ResponseStreaming != false) hash ^= ResponseStreaming.GetHashCode(); + hash ^= options_.GetHashCode(); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) hash ^= Syntax.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (RequestTypeUrl.Length != 0) { + output.WriteRawTag(18); + output.WriteString(RequestTypeUrl); + } + if (RequestStreaming != false) { + output.WriteRawTag(24); + output.WriteBool(RequestStreaming); + } + if (ResponseTypeUrl.Length != 0) { + output.WriteRawTag(34); + output.WriteString(ResponseTypeUrl); + } + if (ResponseStreaming != false) { + output.WriteRawTag(40); + output.WriteBool(ResponseStreaming); + } + options_.WriteTo(output, _repeated_options_codec); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(56); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (RequestTypeUrl.Length != 0) { + output.WriteRawTag(18); + output.WriteString(RequestTypeUrl); + } + if (RequestStreaming != false) { + output.WriteRawTag(24); + output.WriteBool(RequestStreaming); + } + if (ResponseTypeUrl.Length != 0) { + output.WriteRawTag(34); + output.WriteString(ResponseTypeUrl); + } + if (ResponseStreaming != false) { + output.WriteRawTag(40); + output.WriteBool(ResponseStreaming); + } + options_.WriteTo(ref output, _repeated_options_codec); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(56); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (RequestTypeUrl.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(RequestTypeUrl); + } + if (RequestStreaming != false) { + size += 1 + 1; + } + if (ResponseTypeUrl.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ResponseTypeUrl); + } + if (ResponseStreaming != false) { + size += 1 + 1; + } + size += options_.CalculateSize(_repeated_options_codec); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Method other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.RequestTypeUrl.Length != 0) { + RequestTypeUrl = other.RequestTypeUrl; + } + if (other.RequestStreaming != false) { + RequestStreaming = other.RequestStreaming; + } + if (other.ResponseTypeUrl.Length != 0) { + ResponseTypeUrl = other.ResponseTypeUrl; + } + if (other.ResponseStreaming != false) { + ResponseStreaming = other.ResponseStreaming; + } + options_.Add(other.options_); + if (other.Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + Syntax = other.Syntax; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + RequestTypeUrl = input.ReadString(); + break; + } + case 24: { + RequestStreaming = input.ReadBool(); + break; + } + case 34: { + ResponseTypeUrl = input.ReadString(); + break; + } + case 40: { + ResponseStreaming = input.ReadBool(); + break; + } + case 50: { + options_.AddEntriesFrom(input, _repeated_options_codec); + break; + } + case 56: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + RequestTypeUrl = input.ReadString(); + break; + } + case 24: { + RequestStreaming = input.ReadBool(); + break; + } + case 34: { + ResponseTypeUrl = input.ReadString(); + break; + } + case 40: { + ResponseStreaming = input.ReadBool(); + break; + } + case 50: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 56: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + + } + + /// + /// Declares an API Interface to be included in this interface. The including + /// interface must redeclare all the methods from the included interface, but + /// documentation and options are inherited as follows: + /// + /// - If after comment and whitespace stripping, the documentation + /// string of the redeclared method is empty, it will be inherited + /// from the original method. + /// + /// - Each annotation belonging to the service config (http, + /// visibility) which is not set in the redeclared method will be + /// inherited. + /// + /// - If an http annotation is inherited, the path pattern will be + /// modified as follows. Any version prefix will be replaced by the + /// version of the including interface plus the [root][] path if + /// specified. + /// + /// Example of a simple mixin: + /// + /// package google.acl.v1; + /// service AccessControl { + /// // Get the underlying ACL object. + /// rpc GetAcl(GetAclRequest) returns (Acl) { + /// option (google.api.http).get = "/v1/{resource=**}:getAcl"; + /// } + /// } + /// + /// package google.storage.v2; + /// service Storage { + /// rpc GetAcl(GetAclRequest) returns (Acl); + /// + /// // Get a data record. + /// rpc GetData(GetDataRequest) returns (Data) { + /// option (google.api.http).get = "/v2/{resource=**}"; + /// } + /// } + /// + /// Example of a mixin configuration: + /// + /// apis: + /// - name: google.storage.v2.Storage + /// mixins: + /// - name: google.acl.v1.AccessControl + /// + /// The mixin construct implies that all methods in `AccessControl` are + /// also declared with same name and request/response types in + /// `Storage`. A documentation generator or annotation processor will + /// see the effective `Storage.GetAcl` method after inheriting + /// documentation and annotations as follows: + /// + /// service Storage { + /// // Get the underlying ACL object. + /// rpc GetAcl(GetAclRequest) returns (Acl) { + /// option (google.api.http).get = "/v2/{resource=**}:getAcl"; + /// } + /// ... + /// } + /// + /// Note how the version in the path pattern changed from `v1` to `v2`. + /// + /// If the `root` field in the mixin is specified, it should be a + /// relative path under which inherited HTTP paths are placed. Example: + /// + /// apis: + /// - name: google.storage.v2.Storage + /// mixins: + /// - name: google.acl.v1.AccessControl + /// root: acls + /// + /// This implies the following inherited HTTP annotation: + /// + /// service Storage { + /// // Get the underlying ACL object. + /// rpc GetAcl(GetAclRequest) returns (Acl) { + /// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; + /// } + /// ... + /// } + /// + public sealed partial class Mixin : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Mixin()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Mixin() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Mixin(Mixin other) : this() { + name_ = other.name_; + root_ = other.root_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Mixin Clone() { + return new Mixin(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// The fully qualified name of the interface which is included. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "root" field. + public const int RootFieldNumber = 2; + private string root_ = ""; + /// + /// If non-empty specifies a path under which inherited HTTP paths + /// are rooted. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Root { + get { return root_; } + set { + root_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Mixin); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Mixin other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Root != other.Root) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (Root.Length != 0) hash ^= Root.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Root.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Root); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Root.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Root); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (Root.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Root); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Mixin other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.Root.Length != 0) { + Root = other.Root; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Root = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Root = input.ReadString(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/Duration.cs b/Libs/Google.Protobuf/WellKnownTypes/Duration.cs new file mode 100644 index 0000000..4df6c97 --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Duration.cs @@ -0,0 +1,328 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/duration.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/duration.proto + public static partial class DurationReflection { + + #region Descriptor + /// File descriptor for google/protobuf/duration.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static DurationReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ch5nb29nbGUvcHJvdG9idWYvZHVyYXRpb24ucHJvdG8SD2dvb2dsZS5wcm90", + "b2J1ZiIqCghEdXJhdGlvbhIPCgdzZWNvbmRzGAEgASgDEg0KBW5hbm9zGAIg", + "ASgFQoMBChNjb20uZ29vZ2xlLnByb3RvYnVmQg1EdXJhdGlvblByb3RvUAFa", + "MWdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL2R1cmF0", + "aW9ucGL4AQGiAgNHUEKqAh5Hb29nbGUuUHJvdG9idWYuV2VsbEtub3duVHlw", + "ZXNiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Duration), global::LC.Google.Protobuf.WellKnownTypes.Duration.Parser, new[]{ "Seconds", "Nanos" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// A Duration represents a signed, fixed-length span of time represented + /// as a count of seconds and fractions of seconds at nanosecond + /// resolution. It is independent of any calendar and concepts like "day" + /// or "month". It is related to Timestamp in that the difference between + /// two Timestamp values is a Duration and it can be added or subtracted + /// from a Timestamp. Range is approximately +-10,000 years. + /// + /// # Examples + /// + /// Example 1: Compute Duration from two Timestamps in pseudo code. + /// + /// Timestamp start = ...; + /// Timestamp end = ...; + /// Duration duration = ...; + /// + /// duration.seconds = end.seconds - start.seconds; + /// duration.nanos = end.nanos - start.nanos; + /// + /// if (duration.seconds < 0 && duration.nanos > 0) { + /// duration.seconds += 1; + /// duration.nanos -= 1000000000; + /// } else if (duration.seconds > 0 && duration.nanos < 0) { + /// duration.seconds -= 1; + /// duration.nanos += 1000000000; + /// } + /// + /// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + /// + /// Timestamp start = ...; + /// Duration duration = ...; + /// Timestamp end = ...; + /// + /// end.seconds = start.seconds + duration.seconds; + /// end.nanos = start.nanos + duration.nanos; + /// + /// if (end.nanos < 0) { + /// end.seconds -= 1; + /// end.nanos += 1000000000; + /// } else if (end.nanos >= 1000000000) { + /// end.seconds += 1; + /// end.nanos -= 1000000000; + /// } + /// + /// Example 3: Compute Duration from datetime.timedelta in Python. + /// + /// td = datetime.timedelta(days=3, minutes=10) + /// duration = Duration() + /// duration.FromTimedelta(td) + /// + /// # JSON Mapping + /// + /// In JSON format, the Duration type is encoded as a string rather than an + /// object, where the string ends in the suffix "s" (indicating seconds) and + /// is preceded by the number of seconds, with nanoseconds expressed as + /// fractional seconds. For example, 3 seconds with 0 nanoseconds should be + /// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + /// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + /// microsecond should be expressed in JSON format as "3.000001s". + /// + public sealed partial class Duration : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Duration()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.DurationReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Duration() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Duration(Duration other) : this() { + seconds_ = other.seconds_; + nanos_ = other.nanos_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Duration Clone() { + return new Duration(this); + } + + /// Field number for the "seconds" field. + public const int SecondsFieldNumber = 1; + private long seconds_; + /// + /// Signed seconds of the span of time. Must be from -315,576,000,000 + /// to +315,576,000,000 inclusive. Note: these bounds are computed from: + /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Seconds { + get { return seconds_; } + set { + seconds_ = value; + } + } + + /// Field number for the "nanos" field. + public const int NanosFieldNumber = 2; + private int nanos_; + /// + /// Signed fractions of a second at nanosecond resolution of the span + /// of time. Durations less than one second are represented with a 0 + /// `seconds` field and a positive or negative `nanos` field. For durations + /// of one second or more, a non-zero value for the `nanos` field must be + /// of the same sign as the `seconds` field. Must be from -999,999,999 + /// to +999,999,999 inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Nanos { + get { return nanos_; } + set { + nanos_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Duration); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Duration other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Seconds != other.Seconds) return false; + if (Nanos != other.Nanos) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Seconds != 0L) hash ^= Seconds.GetHashCode(); + if (Nanos != 0) hash ^= Nanos.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Seconds != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Seconds); + } + if (Nanos != 0) { + output.WriteRawTag(16); + output.WriteInt32(Nanos); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Seconds != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Seconds); + } + if (Nanos != 0) { + output.WriteRawTag(16); + output.WriteInt32(Nanos); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Seconds != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Seconds); + } + if (Nanos != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Nanos); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Duration other) { + if (other == null) { + return; + } + if (other.Seconds != 0L) { + Seconds = other.Seconds; + } + if (other.Nanos != 0) { + Nanos = other.Nanos; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Seconds = input.ReadInt64(); + break; + } + case 16: { + Nanos = input.ReadInt32(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Seconds = input.ReadInt64(); + break; + } + case 16: { + Nanos = input.ReadInt32(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/DurationPartial.cs b/Libs/Google.Protobuf/WellKnownTypes/DurationPartial.cs new file mode 100644 index 0000000..4c031ea --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/DurationPartial.cs @@ -0,0 +1,270 @@ +#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.Globalization; +using System.Text; + +namespace LC.Google.Protobuf.WellKnownTypes +{ + // Manually-written partial class for the Duration well-known type, + // providing a conversion to TimeSpan and convenience operators. + public partial class Duration : ICustomDiagnosticMessage + { + /// + /// The number of nanoseconds in a second. + /// + public const int NanosecondsPerSecond = 1000000000; + /// + /// The number of nanoseconds in a BCL tick (as used by and ). + /// + public const int NanosecondsPerTick = 100; + + /// + /// The maximum permitted number of seconds. + /// + public const long MaxSeconds = 315576000000L; + + /// + /// The minimum permitted number of seconds. + /// + public const long MinSeconds = -315576000000L; + + internal const int MaxNanoseconds = NanosecondsPerSecond - 1; + internal const int MinNanoseconds = -NanosecondsPerSecond + 1; + + internal static bool IsNormalized(long seconds, int nanoseconds) + { + // Simple boundaries + if (seconds < MinSeconds || seconds > MaxSeconds || + nanoseconds < MinNanoseconds || nanoseconds > MaxNanoseconds) + { + return false; + } + // We only have a problem is one is strictly negative and the other is + // strictly positive. + return Math.Sign(seconds) * Math.Sign(nanoseconds) != -1; + } + + /// + /// Converts this to a . + /// + /// If the duration is not a precise number of ticks, it is truncated towards 0. + /// The value of this duration, as a TimeSpan. + /// This value isn't a valid normalized duration, as + /// described in the documentation. + public TimeSpan ToTimeSpan() + { + checked + { + if (!IsNormalized(Seconds, Nanos)) + { + throw new InvalidOperationException("Duration was not a valid normalized duration"); + } + long ticks = Seconds * TimeSpan.TicksPerSecond + Nanos / NanosecondsPerTick; + return TimeSpan.FromTicks(ticks); + } + } + + /// + /// Converts the given to a . + /// + /// The TimeSpan to convert. + /// The value of the given TimeSpan, as a Duration. + public static Duration FromTimeSpan(TimeSpan timeSpan) + { + checked + { + long ticks = timeSpan.Ticks; + long seconds = ticks / TimeSpan.TicksPerSecond; + int nanos = (int) (ticks % TimeSpan.TicksPerSecond) * NanosecondsPerTick; + return new Duration { Seconds = seconds, Nanos = nanos }; + } + } + + /// + /// Returns the result of negating the duration. For example, the negation of 5 minutes is -5 minutes. + /// + /// The duration to negate. Must not be null. + /// The negated value of this duration. + public static Duration operator -(Duration value) + { + ProtoPreconditions.CheckNotNull(value, "value"); + checked + { + return Normalize(-value.Seconds, -value.Nanos); + } + } + + /// + /// Adds the two specified values together. + /// + /// The first value to add. Must not be null. + /// The second value to add. Must not be null. + /// + public static Duration operator +(Duration lhs, Duration rhs) + { + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos); + } + } + + /// + /// Subtracts one from another. + /// + /// The duration to subtract from. Must not be null. + /// The duration to subtract. Must not be null. + /// The difference between the two specified durations. + public static Duration operator -(Duration lhs, Duration rhs) + { + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); + } + } + + /// + /// Creates a duration with the normalized values from the given number of seconds and + /// nanoseconds, conforming with the description in the proto file. + /// + internal static Duration Normalize(long seconds, int nanoseconds) + { + // Ensure that nanoseconds is in the range (-1,000,000,000, +1,000,000,000) + int extraSeconds = nanoseconds / NanosecondsPerSecond; + seconds += extraSeconds; + nanoseconds -= extraSeconds * NanosecondsPerSecond; + + // Now make sure that Sign(seconds) == Sign(nanoseconds) if Sign(seconds) != 0. + if (seconds < 0 && nanoseconds > 0) + { + seconds += 1; + nanoseconds -= NanosecondsPerSecond; + } + else if (seconds > 0 && nanoseconds < 0) + { + seconds -= 1; + nanoseconds += NanosecondsPerSecond; + } + return new Duration { Seconds = seconds, Nanos = nanoseconds }; + } + + /// + /// Converts a duration specified in seconds/nanoseconds to a string. + /// + /// + /// If the value is a normalized duration in the range described in duration.proto, + /// is ignored. Otherwise, if the parameter is true, + /// a JSON object with a warning is returned; if it is false, an is thrown. + /// + /// Seconds portion of the duration. + /// Nanoseconds portion of the duration. + /// Determines the handling of non-normalized values + /// The represented duration is invalid, and is false. + internal static string ToJson(long seconds, int nanoseconds, bool diagnosticOnly) + { + if (IsNormalized(seconds, nanoseconds)) + { + var builder = new StringBuilder(); + builder.Append('"'); + // The seconds part will normally provide the minus sign if we need it, but not if it's 0... + if (seconds == 0 && nanoseconds < 0) + { + builder.Append('-'); + } + + builder.Append(seconds.ToString("d", CultureInfo.InvariantCulture)); + AppendNanoseconds(builder, Math.Abs(nanoseconds)); + builder.Append("s\""); + return builder.ToString(); + } + if (diagnosticOnly) + { + // Note: the double braces here are escaping for braces in format strings. + return string.Format(CultureInfo.InvariantCulture, + "{{ \"@warning\": \"Invalid Duration\", \"seconds\": \"{0}\", \"nanos\": {1} }}", + seconds, + nanoseconds); + } + else + { + throw new InvalidOperationException("Non-normalized duration value"); + } + } + + /// + /// Returns a string representation of this for diagnostic purposes. + /// + /// + /// Normally the returned value will be a JSON string value (including leading and trailing quotes) but + /// when the value is non-normalized or out of range, a JSON object representation will be returned + /// instead, including a warning. This is to avoid exceptions being thrown when trying to + /// diagnose problems - the regular JSON formatter will still throw an exception for non-normalized + /// values. + /// + /// A string representation of this value. + public string ToDiagnosticString() + { + return ToJson(Seconds, Nanos, true); + } + + /// + /// Appends a number of nanoseconds to a StringBuilder. Either 0 digits are added (in which + /// case no "." is appended), or 3 6 or 9 digits. This is internal for use in Timestamp as well + /// as Duration. + /// + internal static void AppendNanoseconds(StringBuilder builder, int nanos) + { + if (nanos != 0) + { + builder.Append('.'); + // Output to 3, 6 or 9 digits. + if (nanos % 1000000 == 0) + { + builder.Append((nanos / 1000000).ToString("d3", CultureInfo.InvariantCulture)); + } + else if (nanos % 1000 == 0) + { + builder.Append((nanos / 1000).ToString("d6", CultureInfo.InvariantCulture)); + } + else + { + builder.Append(nanos.ToString("d9", CultureInfo.InvariantCulture)); + } + } + } + } +} diff --git a/Libs/Google.Protobuf/WellKnownTypes/Empty.cs b/Libs/Google.Protobuf/WellKnownTypes/Empty.cs new file mode 100644 index 0000000..cbcbe5e --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Empty.cs @@ -0,0 +1,193 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/empty.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/empty.proto + public static partial class EmptyReflection { + + #region Descriptor + /// File descriptor for google/protobuf/empty.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static EmptyReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Chtnb29nbGUvcHJvdG9idWYvZW1wdHkucHJvdG8SD2dvb2dsZS5wcm90b2J1", + "ZiIHCgVFbXB0eUJ9ChNjb20uZ29vZ2xlLnByb3RvYnVmQgpFbXB0eVByb3Rv", + "UAFaLmdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL2Vt", + "cHR5cGL4AQGiAgNHUEKqAh5Hb29nbGUuUHJvdG9idWYuV2VsbEtub3duVHlw", + "ZXNiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Empty), global::LC.Google.Protobuf.WellKnownTypes.Empty.Parser, null, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// A generic empty message that you can re-use to avoid defining duplicated + /// empty messages in your APIs. A typical example is to use it as the request + /// or the response type of an API method. For instance: + /// + /// service Foo { + /// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + /// } + /// + /// The JSON representation for `Empty` is empty JSON object `{}`. + /// + public sealed partial class Empty : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Empty()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.EmptyReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Empty() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Empty(Empty other) : this() { + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Empty Clone() { + return new Empty(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Empty); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Empty other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Empty other) { + if (other == null) { + return; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/FieldMask.cs b/Libs/Google.Protobuf/WellKnownTypes/FieldMask.cs new file mode 100644 index 0000000..56b3a33 --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/FieldMask.cs @@ -0,0 +1,410 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/field_mask.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/field_mask.proto + public static partial class FieldMaskReflection { + + #region Descriptor + /// File descriptor for google/protobuf/field_mask.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static FieldMaskReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "CiBnb29nbGUvcHJvdG9idWYvZmllbGRfbWFzay5wcm90bxIPZ29vZ2xlLnBy", + "b3RvYnVmIhoKCUZpZWxkTWFzaxINCgVwYXRocxgBIAMoCUKFAQoTY29tLmdv", + "b2dsZS5wcm90b2J1ZkIORmllbGRNYXNrUHJvdG9QAVoyZ29vZ2xlLmdvbGFu", + "Zy5vcmcvcHJvdG9idWYvdHlwZXMva25vd24vZmllbGRtYXNrcGL4AQGiAgNH", + "UEKqAh5Hb29nbGUuUHJvdG9idWYuV2VsbEtub3duVHlwZXNiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.FieldMask), global::LC.Google.Protobuf.WellKnownTypes.FieldMask.Parser, new[]{ "Paths" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// `FieldMask` represents a set of symbolic field paths, for example: + /// + /// paths: "f.a" + /// paths: "f.b.d" + /// + /// Here `f` represents a field in some root message, `a` and `b` + /// fields in the message found in `f`, and `d` a field found in the + /// message in `f.b`. + /// + /// Field masks are used to specify a subset of fields that should be + /// returned by a get operation or modified by an update operation. + /// Field masks also have a custom JSON encoding (see below). + /// + /// # Field Masks in Projections + /// + /// When used in the context of a projection, a response message or + /// sub-message is filtered by the API to only contain those fields as + /// specified in the mask. For example, if the mask in the previous + /// example is applied to a response message as follows: + /// + /// f { + /// a : 22 + /// b { + /// d : 1 + /// x : 2 + /// } + /// y : 13 + /// } + /// z: 8 + /// + /// The result will not contain specific values for fields x,y and z + /// (their value will be set to the default, and omitted in proto text + /// output): + /// + /// f { + /// a : 22 + /// b { + /// d : 1 + /// } + /// } + /// + /// A repeated field is not allowed except at the last position of a + /// paths string. + /// + /// If a FieldMask object is not present in a get operation, the + /// operation applies to all fields (as if a FieldMask of all fields + /// had been specified). + /// + /// Note that a field mask does not necessarily apply to the + /// top-level response message. In case of a REST get operation, the + /// field mask applies directly to the response, but in case of a REST + /// list operation, the mask instead applies to each individual message + /// in the returned resource list. In case of a REST custom method, + /// other definitions may be used. Where the mask applies will be + /// clearly documented together with its declaration in the API. In + /// any case, the effect on the returned resource/resources is required + /// behavior for APIs. + /// + /// # Field Masks in Update Operations + /// + /// A field mask in update operations specifies which fields of the + /// targeted resource are going to be updated. The API is required + /// to only change the values of the fields as specified in the mask + /// and leave the others untouched. If a resource is passed in to + /// describe the updated values, the API ignores the values of all + /// fields not covered by the mask. + /// + /// If a repeated field is specified for an update operation, new values will + /// be appended to the existing repeated field in the target resource. Note that + /// a repeated field is only allowed in the last position of a `paths` string. + /// + /// If a sub-message is specified in the last position of the field mask for an + /// update operation, then new value will be merged into the existing sub-message + /// in the target resource. + /// + /// For example, given the target message: + /// + /// f { + /// b { + /// d: 1 + /// x: 2 + /// } + /// c: [1] + /// } + /// + /// And an update message: + /// + /// f { + /// b { + /// d: 10 + /// } + /// c: [2] + /// } + /// + /// then if the field mask is: + /// + /// paths: ["f.b", "f.c"] + /// + /// then the result will be: + /// + /// f { + /// b { + /// d: 10 + /// x: 2 + /// } + /// c: [1, 2] + /// } + /// + /// An implementation may provide options to override this default behavior for + /// repeated and message fields. + /// + /// In order to reset a field's value to the default, the field must + /// be in the mask and set to the default value in the provided resource. + /// Hence, in order to reset all fields of a resource, provide a default + /// instance of the resource and set all fields in the mask, or do + /// not provide a mask as described below. + /// + /// If a field mask is not present on update, the operation applies to + /// all fields (as if a field mask of all fields has been specified). + /// Note that in the presence of schema evolution, this may mean that + /// fields the client does not know and has therefore not filled into + /// the request will be reset to their default. If this is unwanted + /// behavior, a specific service may require a client to always specify + /// a field mask, producing an error if not. + /// + /// As with get operations, the location of the resource which + /// describes the updated values in the request message depends on the + /// operation kind. In any case, the effect of the field mask is + /// required to be honored by the API. + /// + /// ## Considerations for HTTP REST + /// + /// The HTTP kind of an update operation which uses a field mask must + /// be set to PATCH instead of PUT in order to satisfy HTTP semantics + /// (PUT must only be used for full updates). + /// + /// # JSON Encoding of Field Masks + /// + /// In JSON, a field mask is encoded as a single string where paths are + /// separated by a comma. Fields name in each path are converted + /// to/from lower-camel naming conventions. + /// + /// As an example, consider the following message declarations: + /// + /// message Profile { + /// User user = 1; + /// Photo photo = 2; + /// } + /// message User { + /// string display_name = 1; + /// string address = 2; + /// } + /// + /// In proto a field mask for `Profile` may look as such: + /// + /// mask { + /// paths: "user.display_name" + /// paths: "photo" + /// } + /// + /// In JSON, the same mask is represented as below: + /// + /// { + /// mask: "user.displayName,photo" + /// } + /// + /// # Field Masks and Oneof Fields + /// + /// Field masks treat fields in oneofs just as regular fields. Consider the + /// following message: + /// + /// message SampleMessage { + /// oneof test_oneof { + /// string name = 4; + /// SubMessage sub_message = 9; + /// } + /// } + /// + /// The field mask can be: + /// + /// mask { + /// paths: "name" + /// } + /// + /// Or: + /// + /// mask { + /// paths: "sub_message" + /// } + /// + /// Note that oneof type names ("test_oneof" in this case) cannot be used in + /// paths. + /// + /// ## Field Mask Verification + /// + /// The implementation of any API method which has a FieldMask type field in the + /// request should verify the included field paths, and return an + /// `INVALID_ARGUMENT` error if any path is unmappable. + /// + public sealed partial class FieldMask : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldMask()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.FieldMaskReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldMask() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldMask(FieldMask other) : this() { + paths_ = other.paths_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public FieldMask Clone() { + return new FieldMask(this); + } + + /// Field number for the "paths" field. + public const int PathsFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_paths_codec + = pb::FieldCodec.ForString(10); + private readonly pbc::RepeatedField paths_ = new pbc::RepeatedField(); + /// + /// The set of field mask paths. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Paths { + get { return paths_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as FieldMask); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(FieldMask other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!paths_.Equals(other.paths_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= paths_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + paths_.WriteTo(output, _repeated_paths_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + paths_.WriteTo(ref output, _repeated_paths_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += paths_.CalculateSize(_repeated_paths_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(FieldMask other) { + if (other == null) { + return; + } + paths_.Add(other.paths_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + paths_.AddEntriesFrom(input, _repeated_paths_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + paths_.AddEntriesFrom(ref input, _repeated_paths_codec); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs b/Libs/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs new file mode 100644 index 0000000..fdc4dd8 --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs @@ -0,0 +1,370 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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.IO; +using System.Linq; +using LC.Google.Protobuf.Reflection; + +namespace LC.Google.Protobuf.WellKnownTypes +{ + // Manually-written partial class for the FieldMask well-known type. + public partial class FieldMask : ICustomDiagnosticMessage + { + private const char FIELD_PATH_SEPARATOR = ','; + private const char FIELD_SEPARATOR_REGEX = '.'; + + /// + /// Converts a field mask specified by paths to a string. + /// + /// + /// If the value is a normalized duration in the range described in field_mask.proto, + /// is ignored. Otherwise, if the parameter is true, + /// a JSON object with a warning is returned; if it is false, an is thrown. + /// + /// Paths in the field mask + /// Determines the handling of non-normalized values + /// The represented field mask is invalid, and is false. + internal static string ToJson(IList paths, bool diagnosticOnly) + { + var firstInvalid = paths.FirstOrDefault(p => !IsPathValid(p)); + if (firstInvalid == null) + { + var writer = new StringWriter(); +#if NET35 + var query = paths.Select(JsonFormatter.ToJsonName); + JsonFormatter.WriteString(writer, string.Join(",", query.ToArray())); +#else + JsonFormatter.WriteString(writer, string.Join(",", paths.Select(JsonFormatter.ToJsonName))); +#endif + return writer.ToString(); + } + else + { + if (diagnosticOnly) + { + var writer = new StringWriter(); + writer.Write("{ \"@warning\": \"Invalid FieldMask\", \"paths\": "); + JsonFormatter.Default.WriteList(writer, (IList)paths); + writer.Write(" }"); + return writer.ToString(); + } + else + { + throw new InvalidOperationException($"Invalid field mask to be converted to JSON: {firstInvalid}"); + } + } + } + + /// + /// Returns a string representation of this for diagnostic purposes. + /// + /// + /// Normally the returned value will be a JSON string value (including leading and trailing quotes) but + /// when the value is non-normalized or out of range, a JSON object representation will be returned + /// instead, including a warning. This is to avoid exceptions being thrown when trying to + /// diagnose problems - the regular JSON formatter will still throw an exception for non-normalized + /// values. + /// + /// A string representation of this value. + public string ToDiagnosticString() + { + return ToJson(Paths, true); + } + + /// + /// Parses from a string to a FieldMask. + /// + public static FieldMask FromString(string value) + { + return FromStringEnumerable(new List(value.Split(FIELD_PATH_SEPARATOR))); + } + + /// + /// Parses from a string to a FieldMask and validates all field paths. + /// + /// The type to validate the field paths against. + public static FieldMask FromString(string value) where T : IMessage + { + return FromStringEnumerable(new List(value.Split(FIELD_PATH_SEPARATOR))); + } + + /// + /// Constructs a FieldMask for a list of field paths in a certain type. + /// + /// The type to validate the field paths against. + public static FieldMask FromStringEnumerable(IEnumerable paths) where T : IMessage + { + var mask = new FieldMask(); + foreach (var path in paths) + { + if (path.Length == 0) + { + // Ignore empty field paths. + continue; + } + + if (typeof(T) != typeof(Empty) + && !IsValid(path)) + { + throw new InvalidProtocolBufferException(path + " is not a valid path for " + typeof(T)); + } + + mask.Paths.Add(path); + } + + return mask; + } + + /// + /// Constructs a FieldMask from the passed field numbers. + /// + /// The type to validate the field paths against. + public static FieldMask FromFieldNumbers(params int[] fieldNumbers) where T : IMessage + { + return FromFieldNumbers((IEnumerable)fieldNumbers); + } + + /// + /// Constructs a FieldMask from the passed field numbers. + /// + /// The type to validate the field paths against. + public static FieldMask FromFieldNumbers(IEnumerable fieldNumbers) where T : IMessage + { + var descriptor = Activator.CreateInstance().Descriptor; + + var mask = new FieldMask(); + foreach (var fieldNumber in fieldNumbers) + { + var field = descriptor.FindFieldByNumber(fieldNumber); + if (field == null) + { + throw new ArgumentNullException($"{fieldNumber} is not a valid field number for {descriptor.Name}"); + } + + mask.Paths.Add(field.Name); + } + + return mask; + } + + /// + /// Checks whether the given path is valid for a field mask. + /// + /// true if the path is valid; false otherwise + private static bool IsPathValid(string input) + { + for (int i = 0; i < input.Length; i++) + { + char c = input[i]; + if (c >= 'A' && c <= 'Z') + { + return false; + } + if (c == '_' && i < input.Length - 1) + { + char next = input[i + 1]; + if (next < 'a' || next > 'z') + { + return false; + } + } + } + return true; + } + + /// + /// Checks whether paths in a given fields mask are valid. + /// + /// The type to validate the field paths against. + public static bool IsValid(FieldMask fieldMask) where T : IMessage + { + var descriptor = Activator.CreateInstance().Descriptor; + + return IsValid(descriptor, fieldMask); + } + + /// + /// Checks whether paths in a given fields mask are valid. + /// + public static bool IsValid(MessageDescriptor descriptor, FieldMask fieldMask) + { + foreach (var path in fieldMask.Paths) + { + if (!IsValid(descriptor, path)) + { + return false; + } + } + + return true; + } + + /// + /// Checks whether a given field path is valid. + /// + /// The type to validate the field paths against. + public static bool IsValid(string path) where T : IMessage + { + var descriptor = Activator.CreateInstance().Descriptor; + + return IsValid(descriptor, path); + } + + /// + /// Checks whether paths in a given fields mask are valid. + /// + public static bool IsValid(MessageDescriptor descriptor, string path) + { + var parts = path.Split(FIELD_SEPARATOR_REGEX); + if (parts.Length == 0) + { + return false; + } + + foreach (var name in parts) + { + var field = descriptor?.FindFieldByName(name); + if (field == null) + { + return false; + } + + if (!field.IsRepeated + && field.FieldType == FieldType.Message) + { + descriptor = field.MessageType; + } + else + { + descriptor = null; + } + } + + return true; + } + + /// + /// Converts this FieldMask to its canonical form. In the canonical form of a + /// FieldMask, all field paths are sorted alphabetically and redundant field + /// paths are removed. + /// + public FieldMask Normalize() + { + return new FieldMaskTree(this).ToFieldMask(); + } + + /// + /// Creates a union of two or more FieldMasks. + /// + public FieldMask Union(params FieldMask[] otherMasks) + { + var maskTree = new FieldMaskTree(this); + foreach (var mask in otherMasks) + { + maskTree.MergeFromFieldMask(mask); + } + + return maskTree.ToFieldMask(); + } + + /// + /// Calculates the intersection of two FieldMasks. + /// + public FieldMask Intersection(FieldMask additionalMask) + { + var tree = new FieldMaskTree(this); + var result = new FieldMaskTree(); + foreach (var path in additionalMask.Paths) + { + tree.IntersectFieldPath(path, result); + } + + return result.ToFieldMask(); + } + + /// + /// Merges fields specified by this FieldMask from one message to another with the + /// specified merge options. + /// + public void Merge(IMessage source, IMessage destination, MergeOptions options) + { + new FieldMaskTree(this).Merge(source, destination, options); + } + + /// + /// Merges fields specified by this FieldMask from one message to another. + /// + public void Merge(IMessage source, IMessage destination) + { + Merge(source, destination, new MergeOptions()); + } + + /// + /// Options to customize merging behavior. + /// + public sealed class MergeOptions + { + /// + /// Whether to replace message fields(i.e., discard existing content in + /// destination message fields) when merging. + /// Default behavior is to merge the source message field into the + /// destination message field. + /// + public bool ReplaceMessageFields { get; set; } = false; + + /// + /// Whether to replace repeated fields (i.e., discard existing content in + /// destination repeated fields) when merging. + /// Default behavior is to append elements from source repeated field to the + /// destination repeated field. + /// + public bool ReplaceRepeatedFields { get; set; } = false; + + /// + /// Whether to replace primitive (non-repeated and non-message) fields in + /// destination message fields with the source primitive fields (i.e., if the + /// field is set in the source, the value is copied to the + /// destination; if the field is unset in the source, the field is cleared + /// from the destination) when merging. + /// + /// Default behavior is to always set the value of the source primitive + /// field to the destination primitive field, and if the source field is + /// unset, the default value of the source field is copied to the + /// destination. + /// + public bool ReplacePrimitiveFields { get; set; } = false; + } + } +} diff --git a/Libs/Google.Protobuf/WellKnownTypes/SourceContext.cs b/Libs/Google.Protobuf/WellKnownTypes/SourceContext.cs new file mode 100644 index 0000000..48debca --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/SourceContext.cs @@ -0,0 +1,227 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/source_context.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/source_context.proto + public static partial class SourceContextReflection { + + #region Descriptor + /// File descriptor for google/protobuf/source_context.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static SourceContextReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "CiRnb29nbGUvcHJvdG9idWYvc291cmNlX2NvbnRleHQucHJvdG8SD2dvb2ds", + "ZS5wcm90b2J1ZiIiCg1Tb3VyY2VDb250ZXh0EhEKCWZpbGVfbmFtZRgBIAEo", + "CUKKAQoTY29tLmdvb2dsZS5wcm90b2J1ZkISU291cmNlQ29udGV4dFByb3Rv", + "UAFaNmdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL3Nv", + "dXJjZWNvbnRleHRwYqICA0dQQqoCHkdvb2dsZS5Qcm90b2J1Zi5XZWxsS25v", + "d25UeXBlc2IGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.SourceContext), global::LC.Google.Protobuf.WellKnownTypes.SourceContext.Parser, new[]{ "FileName" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// `SourceContext` represents information about the source of a + /// protobuf element, like the file in which it is defined. + /// + public sealed partial class SourceContext : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SourceContext()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceContext() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceContext(SourceContext other) : this() { + fileName_ = other.fileName_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceContext Clone() { + return new SourceContext(this); + } + + /// Field number for the "file_name" field. + public const int FileNameFieldNumber = 1; + private string fileName_ = ""; + /// + /// The path-qualified name of the .proto file that contained the associated + /// protobuf element. For example: `"google/protobuf/source_context.proto"`. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string FileName { + get { return fileName_; } + set { + fileName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as SourceContext); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(SourceContext other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (FileName != other.FileName) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (FileName.Length != 0) hash ^= FileName.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (FileName.Length != 0) { + output.WriteRawTag(10); + output.WriteString(FileName); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (FileName.Length != 0) { + output.WriteRawTag(10); + output.WriteString(FileName); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (FileName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(FileName); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(SourceContext other) { + if (other == null) { + return; + } + if (other.FileName.Length != 0) { + FileName = other.FileName; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + FileName = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + FileName = input.ReadString(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/Struct.cs b/Libs/Google.Protobuf/WellKnownTypes/Struct.cs new file mode 100644 index 0000000..c4e09c2 --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Struct.cs @@ -0,0 +1,866 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/struct.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/struct.proto + public static partial class StructReflection { + + #region Descriptor + /// File descriptor for google/protobuf/struct.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static StructReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Chxnb29nbGUvcHJvdG9idWYvc3RydWN0LnByb3RvEg9nb29nbGUucHJvdG9i", + "dWYihAEKBlN0cnVjdBIzCgZmaWVsZHMYASADKAsyIy5nb29nbGUucHJvdG9i", + "dWYuU3RydWN0LkZpZWxkc0VudHJ5GkUKC0ZpZWxkc0VudHJ5EgsKA2tleRgB", + "IAEoCRIlCgV2YWx1ZRgCIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZToC", + "OAEi6gEKBVZhbHVlEjAKCm51bGxfdmFsdWUYASABKA4yGi5nb29nbGUucHJv", + "dG9idWYuTnVsbFZhbHVlSAASFgoMbnVtYmVyX3ZhbHVlGAIgASgBSAASFgoM", + "c3RyaW5nX3ZhbHVlGAMgASgJSAASFAoKYm9vbF92YWx1ZRgEIAEoCEgAEi8K", + "DHN0cnVjdF92YWx1ZRgFIAEoCzIXLmdvb2dsZS5wcm90b2J1Zi5TdHJ1Y3RI", + "ABIwCgpsaXN0X3ZhbHVlGAYgASgLMhouZ29vZ2xlLnByb3RvYnVmLkxpc3RW", + "YWx1ZUgAQgYKBGtpbmQiMwoJTGlzdFZhbHVlEiYKBnZhbHVlcxgBIAMoCzIW", + "Lmdvb2dsZS5wcm90b2J1Zi5WYWx1ZSobCglOdWxsVmFsdWUSDgoKTlVMTF9W", + "QUxVRRAAQn8KE2NvbS5nb29nbGUucHJvdG9idWZCC1N0cnVjdFByb3RvUAFa", + "L2dvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL3N0cnVj", + "dHBi+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVz", + "YgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::LC.Google.Protobuf.WellKnownTypes.NullValue), }, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Struct), global::LC.Google.Protobuf.WellKnownTypes.Struct.Parser, new[]{ "Fields" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, }), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Value), global::LC.Google.Protobuf.WellKnownTypes.Value.Parser, new[]{ "NullValue", "NumberValue", "StringValue", "BoolValue", "StructValue", "ListValue" }, new[]{ "Kind" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.ListValue), global::LC.Google.Protobuf.WellKnownTypes.ListValue.Parser, new[]{ "Values" }, null, null, null, null) + })); + } + #endregion + + } + #region Enums + /// + /// `NullValue` is a singleton enumeration to represent the null value for the + /// `Value` type union. + /// + /// The JSON representation for `NullValue` is JSON `null`. + /// + public enum NullValue { + /// + /// Null value. + /// + [pbr::OriginalName("NULL_VALUE")] NullValue = 0, + } + + #endregion + + #region Messages + /// + /// `Struct` represents a structured data value, consisting of fields + /// which map to dynamically typed values. In some languages, `Struct` + /// might be supported by a native representation. For example, in + /// scripting languages like JS a struct is represented as an + /// object. The details of that representation are described together + /// with the proto support for the language. + /// + /// The JSON representation for `Struct` is JSON object. + /// + public sealed partial class Struct : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Struct()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.StructReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Struct() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Struct(Struct other) : this() { + fields_ = other.fields_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Struct Clone() { + return new Struct(this); + } + + /// Field number for the "fields" field. + public const int FieldsFieldNumber = 1; + private static readonly pbc::MapField.Codec _map_fields_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForString(10, ""), pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.WellKnownTypes.Value.Parser), 10); + private readonly pbc::MapField fields_ = new pbc::MapField(); + /// + /// Unordered map of dynamically typed values. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::MapField Fields { + get { return fields_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Struct); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Struct other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!Fields.Equals(other.Fields)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= Fields.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + fields_.WriteTo(output, _map_fields_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + fields_.WriteTo(ref output, _map_fields_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += fields_.CalculateSize(_map_fields_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Struct other) { + if (other == null) { + return; + } + fields_.Add(other.fields_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + fields_.AddEntriesFrom(input, _map_fields_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + fields_.AddEntriesFrom(ref input, _map_fields_codec); + break; + } + } + } + } + #endif + + } + + /// + /// `Value` represents a dynamically typed value which can be either + /// null, a number, a string, a boolean, a recursive struct value, or a + /// list of values. A producer of value is expected to set one of that + /// variants, absence of any variant indicates an error. + /// + /// The JSON representation for `Value` is JSON value. + /// + public sealed partial class Value : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Value()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.StructReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Value() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Value(Value other) : this() { + switch (other.KindCase) { + case KindOneofCase.NullValue: + NullValue = other.NullValue; + break; + case KindOneofCase.NumberValue: + NumberValue = other.NumberValue; + break; + case KindOneofCase.StringValue: + StringValue = other.StringValue; + break; + case KindOneofCase.BoolValue: + BoolValue = other.BoolValue; + break; + case KindOneofCase.StructValue: + StructValue = other.StructValue.Clone(); + break; + case KindOneofCase.ListValue: + ListValue = other.ListValue.Clone(); + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Value Clone() { + return new Value(this); + } + + /// Field number for the "null_value" field. + public const int NullValueFieldNumber = 1; + /// + /// Represents a null value. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.NullValue NullValue { + get { return kindCase_ == KindOneofCase.NullValue ? (global::LC.Google.Protobuf.WellKnownTypes.NullValue) kind_ : global::LC.Google.Protobuf.WellKnownTypes.NullValue.NullValue; } + set { + kind_ = value; + kindCase_ = KindOneofCase.NullValue; + } + } + + /// Field number for the "number_value" field. + public const int NumberValueFieldNumber = 2; + /// + /// Represents a double value. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double NumberValue { + get { return kindCase_ == KindOneofCase.NumberValue ? (double) kind_ : 0D; } + set { + kind_ = value; + kindCase_ = KindOneofCase.NumberValue; + } + } + + /// Field number for the "string_value" field. + public const int StringValueFieldNumber = 3; + /// + /// Represents a string value. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string StringValue { + get { return kindCase_ == KindOneofCase.StringValue ? (string) kind_ : ""; } + set { + kind_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + kindCase_ = KindOneofCase.StringValue; + } + } + + /// Field number for the "bool_value" field. + public const int BoolValueFieldNumber = 4; + /// + /// Represents a boolean value. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool BoolValue { + get { return kindCase_ == KindOneofCase.BoolValue ? (bool) kind_ : false; } + set { + kind_ = value; + kindCase_ = KindOneofCase.BoolValue; + } + } + + /// Field number for the "struct_value" field. + public const int StructValueFieldNumber = 5; + /// + /// Represents a structured value. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Struct StructValue { + get { return kindCase_ == KindOneofCase.StructValue ? (global::LC.Google.Protobuf.WellKnownTypes.Struct) kind_ : null; } + set { + kind_ = value; + kindCase_ = value == null ? KindOneofCase.None : KindOneofCase.StructValue; + } + } + + /// Field number for the "list_value" field. + public const int ListValueFieldNumber = 6; + /// + /// Represents a repeated `Value`. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.ListValue ListValue { + get { return kindCase_ == KindOneofCase.ListValue ? (global::LC.Google.Protobuf.WellKnownTypes.ListValue) kind_ : null; } + set { + kind_ = value; + kindCase_ = value == null ? KindOneofCase.None : KindOneofCase.ListValue; + } + } + + private object kind_; + /// Enum of possible cases for the "kind" oneof. + public enum KindOneofCase { + None = 0, + NullValue = 1, + NumberValue = 2, + StringValue = 3, + BoolValue = 4, + StructValue = 5, + ListValue = 6, + } + private KindOneofCase kindCase_ = KindOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public KindOneofCase KindCase { + get { return kindCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearKind() { + kindCase_ = KindOneofCase.None; + kind_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Value); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Value other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (NullValue != other.NullValue) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(NumberValue, other.NumberValue)) return false; + if (StringValue != other.StringValue) return false; + if (BoolValue != other.BoolValue) return false; + if (!object.Equals(StructValue, other.StructValue)) return false; + if (!object.Equals(ListValue, other.ListValue)) return false; + if (KindCase != other.KindCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (kindCase_ == KindOneofCase.NullValue) hash ^= NullValue.GetHashCode(); + if (kindCase_ == KindOneofCase.NumberValue) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(NumberValue); + if (kindCase_ == KindOneofCase.StringValue) hash ^= StringValue.GetHashCode(); + if (kindCase_ == KindOneofCase.BoolValue) hash ^= BoolValue.GetHashCode(); + if (kindCase_ == KindOneofCase.StructValue) hash ^= StructValue.GetHashCode(); + if (kindCase_ == KindOneofCase.ListValue) hash ^= ListValue.GetHashCode(); + hash ^= (int) kindCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (kindCase_ == KindOneofCase.NullValue) { + output.WriteRawTag(8); + output.WriteEnum((int) NullValue); + } + if (kindCase_ == KindOneofCase.NumberValue) { + output.WriteRawTag(17); + output.WriteDouble(NumberValue); + } + if (kindCase_ == KindOneofCase.StringValue) { + output.WriteRawTag(26); + output.WriteString(StringValue); + } + if (kindCase_ == KindOneofCase.BoolValue) { + output.WriteRawTag(32); + output.WriteBool(BoolValue); + } + if (kindCase_ == KindOneofCase.StructValue) { + output.WriteRawTag(42); + output.WriteMessage(StructValue); + } + if (kindCase_ == KindOneofCase.ListValue) { + output.WriteRawTag(50); + output.WriteMessage(ListValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (kindCase_ == KindOneofCase.NullValue) { + output.WriteRawTag(8); + output.WriteEnum((int) NullValue); + } + if (kindCase_ == KindOneofCase.NumberValue) { + output.WriteRawTag(17); + output.WriteDouble(NumberValue); + } + if (kindCase_ == KindOneofCase.StringValue) { + output.WriteRawTag(26); + output.WriteString(StringValue); + } + if (kindCase_ == KindOneofCase.BoolValue) { + output.WriteRawTag(32); + output.WriteBool(BoolValue); + } + if (kindCase_ == KindOneofCase.StructValue) { + output.WriteRawTag(42); + output.WriteMessage(StructValue); + } + if (kindCase_ == KindOneofCase.ListValue) { + output.WriteRawTag(50); + output.WriteMessage(ListValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (kindCase_ == KindOneofCase.NullValue) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) NullValue); + } + if (kindCase_ == KindOneofCase.NumberValue) { + size += 1 + 8; + } + if (kindCase_ == KindOneofCase.StringValue) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(StringValue); + } + if (kindCase_ == KindOneofCase.BoolValue) { + size += 1 + 1; + } + if (kindCase_ == KindOneofCase.StructValue) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(StructValue); + } + if (kindCase_ == KindOneofCase.ListValue) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(ListValue); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Value other) { + if (other == null) { + return; + } + switch (other.KindCase) { + case KindOneofCase.NullValue: + NullValue = other.NullValue; + break; + case KindOneofCase.NumberValue: + NumberValue = other.NumberValue; + break; + case KindOneofCase.StringValue: + StringValue = other.StringValue; + break; + case KindOneofCase.BoolValue: + BoolValue = other.BoolValue; + break; + case KindOneofCase.StructValue: + if (StructValue == null) { + StructValue = new global::LC.Google.Protobuf.WellKnownTypes.Struct(); + } + StructValue.MergeFrom(other.StructValue); + break; + case KindOneofCase.ListValue: + if (ListValue == null) { + ListValue = new global::LC.Google.Protobuf.WellKnownTypes.ListValue(); + } + ListValue.MergeFrom(other.ListValue); + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + kind_ = input.ReadEnum(); + kindCase_ = KindOneofCase.NullValue; + break; + } + case 17: { + NumberValue = input.ReadDouble(); + break; + } + case 26: { + StringValue = input.ReadString(); + break; + } + case 32: { + BoolValue = input.ReadBool(); + break; + } + case 42: { + global::LC.Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::LC.Google.Protobuf.WellKnownTypes.Struct(); + if (kindCase_ == KindOneofCase.StructValue) { + subBuilder.MergeFrom(StructValue); + } + input.ReadMessage(subBuilder); + StructValue = subBuilder; + break; + } + case 50: { + global::LC.Google.Protobuf.WellKnownTypes.ListValue subBuilder = new global::LC.Google.Protobuf.WellKnownTypes.ListValue(); + if (kindCase_ == KindOneofCase.ListValue) { + subBuilder.MergeFrom(ListValue); + } + input.ReadMessage(subBuilder); + ListValue = subBuilder; + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + kind_ = input.ReadEnum(); + kindCase_ = KindOneofCase.NullValue; + break; + } + case 17: { + NumberValue = input.ReadDouble(); + break; + } + case 26: { + StringValue = input.ReadString(); + break; + } + case 32: { + BoolValue = input.ReadBool(); + break; + } + case 42: { + global::LC.Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::LC.Google.Protobuf.WellKnownTypes.Struct(); + if (kindCase_ == KindOneofCase.StructValue) { + subBuilder.MergeFrom(StructValue); + } + input.ReadMessage(subBuilder); + StructValue = subBuilder; + break; + } + case 50: { + global::LC.Google.Protobuf.WellKnownTypes.ListValue subBuilder = new global::LC.Google.Protobuf.WellKnownTypes.ListValue(); + if (kindCase_ == KindOneofCase.ListValue) { + subBuilder.MergeFrom(ListValue); + } + input.ReadMessage(subBuilder); + ListValue = subBuilder; + break; + } + } + } + } + #endif + + } + + /// + /// `ListValue` is a wrapper around a repeated field of values. + /// + /// The JSON representation for `ListValue` is JSON array. + /// + public sealed partial class ListValue : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ListValue()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.StructReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ListValue() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ListValue(ListValue other) : this() { + values_ = other.values_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ListValue Clone() { + return new ListValue(this); + } + + /// Field number for the "values" field. + public const int ValuesFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_values_codec + = pb::FieldCodec.ForMessage(10, global::LC.Google.Protobuf.WellKnownTypes.Value.Parser); + private readonly pbc::RepeatedField values_ = new pbc::RepeatedField(); + /// + /// Repeated field of dynamically typed values. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Values { + get { return values_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ListValue); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ListValue other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!values_.Equals(other.values_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= values_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + values_.WriteTo(output, _repeated_values_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + values_.WriteTo(ref output, _repeated_values_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += values_.CalculateSize(_repeated_values_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ListValue other) { + if (other == null) { + return; + } + values_.Add(other.values_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + values_.AddEntriesFrom(input, _repeated_values_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + values_.AddEntriesFrom(ref input, _repeated_values_codec); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/TimeExtensions.cs b/Libs/Google.Protobuf/WellKnownTypes/TimeExtensions.cs new file mode 100644 index 0000000..2111dcf --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/TimeExtensions.cs @@ -0,0 +1,76 @@ +#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; + +namespace LC.Google.Protobuf.WellKnownTypes +{ + /// + /// Extension methods on BCL time-related types, converting to protobuf types. + /// + public static class TimeExtensions + { + /// + /// Converts the given to a . + /// + /// The date and time to convert to a timestamp. + /// The value has a other than Utc. + /// The converted timestamp. + public static Timestamp ToTimestamp(this DateTime dateTime) + { + return Timestamp.FromDateTime(dateTime); + } + + /// + /// Converts the given to a + /// + /// The offset is taken into consideration when converting the value (so the same instant in time + /// is represented) but is not a separate part of the resulting value. In other words, there is no + /// roundtrip operation to retrieve the original DateTimeOffset. + /// The date and time (with UTC offset) to convert to a timestamp. + /// The converted timestamp. + public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset) + { + return Timestamp.FromDateTimeOffset(dateTimeOffset); + } + + /// + /// Converts the given to a . + /// + /// The time span to convert. + /// The converted duration. + public static Duration ToDuration(this TimeSpan timeSpan) + { + return Duration.FromTimeSpan(timeSpan); + } + } +} diff --git a/Libs/Google.Protobuf/WellKnownTypes/Timestamp.cs b/Libs/Google.Protobuf/WellKnownTypes/Timestamp.cs new file mode 100644 index 0000000..f2974ea --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Timestamp.cs @@ -0,0 +1,357 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/timestamp.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/timestamp.proto + public static partial class TimestampReflection { + + #region Descriptor + /// File descriptor for google/protobuf/timestamp.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static TimestampReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ch9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1wLnByb3RvEg9nb29nbGUucHJv", + "dG9idWYiKwoJVGltZXN0YW1wEg8KB3NlY29uZHMYASABKAMSDQoFbmFub3MY", + "AiABKAVChQEKE2NvbS5nb29nbGUucHJvdG9idWZCDlRpbWVzdGFtcFByb3Rv", + "UAFaMmdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL3Rp", + "bWVzdGFtcHBi+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93", + "blR5cGVzYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Timestamp), global::LC.Google.Protobuf.WellKnownTypes.Timestamp.Parser, new[]{ "Seconds", "Nanos" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// A Timestamp represents a point in time independent of any time zone or local + /// calendar, encoded as a count of seconds and fractions of seconds at + /// nanosecond resolution. The count is relative to an epoch at UTC midnight on + /// January 1, 1970, in the proleptic Gregorian calendar which extends the + /// Gregorian calendar backwards to year one. + /// + /// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + /// second table is needed for interpretation, using a [24-hour linear + /// smear](https://developers.google.com/time/smear). + /// + /// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + /// restricting to that range, we ensure that we can convert to and from [RFC + /// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + /// + /// # Examples + /// + /// Example 1: Compute Timestamp from POSIX `time()`. + /// + /// Timestamp timestamp; + /// timestamp.set_seconds(time(NULL)); + /// timestamp.set_nanos(0); + /// + /// Example 2: Compute Timestamp from POSIX `gettimeofday()`. + /// + /// struct timeval tv; + /// gettimeofday(&tv, NULL); + /// + /// Timestamp timestamp; + /// timestamp.set_seconds(tv.tv_sec); + /// timestamp.set_nanos(tv.tv_usec * 1000); + /// + /// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + /// + /// FILETIME ft; + /// GetSystemTimeAsFileTime(&ft); + /// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + /// + /// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + /// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + /// Timestamp timestamp; + /// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + /// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + /// + /// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + /// + /// long millis = System.currentTimeMillis(); + /// + /// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + /// .setNanos((int) ((millis % 1000) * 1000000)).build(); + /// + /// Example 5: Compute Timestamp from Java `Instant.now()`. + /// + /// Instant now = Instant.now(); + /// + /// Timestamp timestamp = + /// Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + /// .setNanos(now.getNano()).build(); + /// + /// Example 6: Compute Timestamp from current time in Python. + /// + /// timestamp = Timestamp() + /// timestamp.GetCurrentTime() + /// + /// # JSON Mapping + /// + /// In JSON format, the Timestamp type is encoded as a string in the + /// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + /// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + /// where {year} is always expressed using four digits while {month}, {day}, + /// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + /// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + /// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + /// is required. A proto3 JSON serializer should always use UTC (as indicated by + /// "Z") when printing the Timestamp type and a proto3 JSON parser should be + /// able to accept both UTC and other timezones (as indicated by an offset). + /// + /// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + /// 01:30 UTC on January 15, 2017. + /// + /// In JavaScript, one can convert a Date object to this format using the + /// standard + /// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + /// method. In Python, a standard `datetime.datetime` object can be converted + /// to this format using + /// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + /// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + /// the Joda Time's [`ISODateTimeFormat.dateTime()`]( + /// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + /// ) to obtain a formatter capable of generating timestamps in this format. + /// + public sealed partial class Timestamp : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Timestamp()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Timestamp() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Timestamp(Timestamp other) : this() { + seconds_ = other.seconds_; + nanos_ = other.nanos_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Timestamp Clone() { + return new Timestamp(this); + } + + /// Field number for the "seconds" field. + public const int SecondsFieldNumber = 1; + private long seconds_; + /// + /// Represents seconds of UTC time since Unix epoch + /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + /// 9999-12-31T23:59:59Z inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Seconds { + get { return seconds_; } + set { + seconds_ = value; + } + } + + /// Field number for the "nanos" field. + public const int NanosFieldNumber = 2; + private int nanos_; + /// + /// Non-negative fractions of a second at nanosecond resolution. Negative + /// second values with fractions must still have non-negative nanos values + /// that count forward in time. Must be from 0 to 999,999,999 + /// inclusive. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Nanos { + get { return nanos_; } + set { + nanos_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Timestamp); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Timestamp other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Seconds != other.Seconds) return false; + if (Nanos != other.Nanos) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Seconds != 0L) hash ^= Seconds.GetHashCode(); + if (Nanos != 0) hash ^= Nanos.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Seconds != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Seconds); + } + if (Nanos != 0) { + output.WriteRawTag(16); + output.WriteInt32(Nanos); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Seconds != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Seconds); + } + if (Nanos != 0) { + output.WriteRawTag(16); + output.WriteInt32(Nanos); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Seconds != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Seconds); + } + if (Nanos != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Nanos); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Timestamp other) { + if (other == null) { + return; + } + if (other.Seconds != 0L) { + Seconds = other.Seconds; + } + if (other.Nanos != 0) { + Nanos = other.Nanos; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Seconds = input.ReadInt64(); + break; + } + case 16: { + Nanos = input.ReadInt32(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Seconds = input.ReadInt64(); + break; + } + case 16: { + Nanos = input.ReadInt32(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Libs/Google.Protobuf/WellKnownTypes/TimestampPartial.cs b/Libs/Google.Protobuf/WellKnownTypes/TimestampPartial.cs new file mode 100644 index 0000000..0bca44c --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/TimestampPartial.cs @@ -0,0 +1,344 @@ +#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.Globalization; +using System.Text; + +namespace LC.Google.Protobuf.WellKnownTypes +{ + public partial class Timestamp : ICustomDiagnosticMessage, IComparable + { + private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + // Constants determined programmatically, but then hard-coded so they can be constant expressions. + private const long BclSecondsAtUnixEpoch = 62135596800; + internal const long UnixSecondsAtBclMaxValue = 253402300799; + internal const long UnixSecondsAtBclMinValue = -BclSecondsAtUnixEpoch; + internal const int MaxNanos = Duration.NanosecondsPerSecond - 1; + + private static bool IsNormalized(long seconds, int nanoseconds) => + nanoseconds >= 0 && + nanoseconds <= MaxNanos && + seconds >= UnixSecondsAtBclMinValue && + seconds <= UnixSecondsAtBclMaxValue; + + /// + /// Returns the difference between one and another, as a . + /// + /// The timestamp to subtract from. Must not be null. + /// The timestamp to subtract. Must not be null. + /// The difference between the two specified timestamps. + public static Duration operator -(Timestamp lhs, Timestamp rhs) + { + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Duration.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); + } + } + + /// + /// Adds a to a , to obtain another Timestamp. + /// + /// The timestamp to add the duration to. Must not be null. + /// The duration to add. Must not be null. + /// The result of adding the duration to the timestamp. + public static Timestamp operator +(Timestamp lhs, Duration rhs) + { + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos); + } + } + + /// + /// Subtracts a from a , to obtain another Timestamp. + /// + /// The timestamp to subtract the duration from. Must not be null. + /// The duration to subtract. + /// The result of subtracting the duration from the timestamp. + public static Timestamp operator -(Timestamp lhs, Duration rhs) + { + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); + checked + { + return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); + } + } + + /// + /// Converts this timestamp into a . + /// + /// + /// The resulting DateTime will always have a Kind of Utc. + /// If the timestamp is not a precise number of ticks, it will be truncated towards the start + /// of time. For example, a timestamp with a value of 99 will result in a + /// value precisely on a second. + /// + /// This timestamp as a DateTime. + /// The timestamp contains invalid values; either it is + /// incorrectly normalized or is outside the valid range. + public DateTime ToDateTime() + { + if (!IsNormalized(Seconds, Nanos)) + { + throw new InvalidOperationException(@"Timestamp contains invalid values: Seconds={Seconds}; Nanos={Nanos}"); + } + return UnixEpoch.AddSeconds(Seconds).AddTicks(Nanos / Duration.NanosecondsPerTick); + } + + /// + /// Converts this timestamp into a . + /// + /// + /// The resulting DateTimeOffset will always have an Offset of zero. + /// If the timestamp is not a precise number of ticks, it will be truncated towards the start + /// of time. For example, a timestamp with a value of 99 will result in a + /// value precisely on a second. + /// + /// This timestamp as a DateTimeOffset. + /// The timestamp contains invalid values; either it is + /// incorrectly normalized or is outside the valid range. + public DateTimeOffset ToDateTimeOffset() + { + return new DateTimeOffset(ToDateTime(), TimeSpan.Zero); + } + + /// + /// Converts the specified to a . + /// + /// + /// The Kind of is not DateTimeKind.Utc. + /// The converted timestamp. + public static Timestamp FromDateTime(DateTime dateTime) + { + if (dateTime.Kind != DateTimeKind.Utc) + { + throw new ArgumentException("Conversion from DateTime to Timestamp requires the DateTime kind to be Utc", "dateTime"); + } + // Do the arithmetic using DateTime.Ticks, which is always non-negative, making things simpler. + long secondsSinceBclEpoch = dateTime.Ticks / TimeSpan.TicksPerSecond; + int nanoseconds = (int) (dateTime.Ticks % TimeSpan.TicksPerSecond) * Duration.NanosecondsPerTick; + return new Timestamp { Seconds = secondsSinceBclEpoch - BclSecondsAtUnixEpoch, Nanos = nanoseconds }; + } + + /// + /// Converts the given to a + /// + /// The offset is taken into consideration when converting the value (so the same instant in time + /// is represented) but is not a separate part of the resulting value. In other words, there is no + /// roundtrip operation to retrieve the original DateTimeOffset. + /// The date and time (with UTC offset) to convert to a timestamp. + /// The converted timestamp. + public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset) + { + // We don't need to worry about this having negative ticks: DateTimeOffset is constrained to handle + // values whose *UTC* value is in the range of DateTime. + return FromDateTime(dateTimeOffset.UtcDateTime); + } + + internal static Timestamp Normalize(long seconds, int nanoseconds) + { + int extraSeconds = nanoseconds / Duration.NanosecondsPerSecond; + seconds += extraSeconds; + nanoseconds -= extraSeconds * Duration.NanosecondsPerSecond; + + if (nanoseconds < 0) + { + nanoseconds += Duration.NanosecondsPerSecond; + seconds--; + } + return new Timestamp { Seconds = seconds, Nanos = nanoseconds }; + } + + /// + /// Converts a timestamp specified in seconds/nanoseconds to a string. + /// + /// + /// If the value is a normalized duration in the range described in timestamp.proto, + /// is ignored. Otherwise, if the parameter is true, + /// a JSON object with a warning is returned; if it is false, an is thrown. + /// + /// Seconds portion of the duration. + /// Nanoseconds portion of the duration. + /// Determines the handling of non-normalized values + /// The represented duration is invalid, and is false. + internal static string ToJson(long seconds, int nanoseconds, bool diagnosticOnly) + { + if (IsNormalized(seconds, nanoseconds)) + { + // Use .NET's formatting for the value down to the second, including an opening double quote (as it's a string value) + DateTime dateTime = UnixEpoch.AddSeconds(seconds); + var builder = new StringBuilder(); + builder.Append('"'); + builder.Append(dateTime.ToString("yyyy'-'MM'-'dd'T'HH:mm:ss", CultureInfo.InvariantCulture)); + Duration.AppendNanoseconds(builder, nanoseconds); + builder.Append("Z\""); + return builder.ToString(); + } + if (diagnosticOnly) + { + return string.Format(CultureInfo.InvariantCulture, + "{{ \"@warning\": \"Invalid Timestamp\", \"seconds\": \"{0}\", \"nanos\": {1} }}", + seconds, + nanoseconds); + } + else + { + throw new InvalidOperationException("Non-normalized timestamp value"); + } + } + + /// + /// Given another timestamp, returns 0 if the timestamps are equivalent, -1 if this timestamp precedes the other, and 1 otherwise + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// Timestamp to compare + /// an integer indicating whether this timestamp precedes or follows the other + public int CompareTo(Timestamp other) + { + return other == null ? 1 + : Seconds < other.Seconds ? -1 + : Seconds > other.Seconds ? 1 + : Nanos < other.Nanos ? -1 + : Nanos > other.Nanos ? 1 + : 0; + } + + /// + /// Compares two timestamps and returns whether the first is less than (chronologically precedes) the second + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// + /// + /// true if a precedes b + public static bool operator <(Timestamp a, Timestamp b) + { + return a.CompareTo(b) < 0; + } + + /// + /// Compares two timestamps and returns whether the first is greater than (chronologically follows) the second + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// + /// + /// true if a follows b + public static bool operator >(Timestamp a, Timestamp b) + { + return a.CompareTo(b) > 0; + } + + /// + /// Compares two timestamps and returns whether the first is less than (chronologically precedes) the second + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// + /// + /// true if a precedes b + public static bool operator <=(Timestamp a, Timestamp b) + { + return a.CompareTo(b) <= 0; + } + + /// + /// Compares two timestamps and returns whether the first is greater than (chronologically follows) the second + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// + /// + /// true if a follows b + public static bool operator >=(Timestamp a, Timestamp b) + { + return a.CompareTo(b) >= 0; + } + + + /// + /// Returns whether two timestamps are equivalent + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// + /// + /// true if the two timestamps refer to the same nanosecond + public static bool operator ==(Timestamp a, Timestamp b) + { + return ReferenceEquals(a, b) || (ReferenceEquals(a, null) ? (ReferenceEquals(b, null) ? true : false) : a.Equals(b)); + } + + /// + /// Returns whether two timestamps differ + /// + /// + /// Make sure the timestamps are normalized. Comparing non-normalized timestamps is not specified and may give unexpected results. + /// + /// + /// + /// true if the two timestamps differ + public static bool operator !=(Timestamp a, Timestamp b) + { + return !(a == b); + } + + /// + /// Returns a string representation of this for diagnostic purposes. + /// + /// + /// Normally the returned value will be a JSON string value (including leading and trailing quotes) but + /// when the value is non-normalized or out of range, a JSON object representation will be returned + /// instead, including a warning. This is to avoid exceptions being thrown when trying to + /// diagnose problems - the regular JSON formatter will still throw an exception for non-normalized + /// values. + /// + /// A string representation of this value. + public string ToDiagnosticString() + { + return ToJson(Seconds, Nanos, true); + } + } +} diff --git a/Libs/Google.Protobuf/WellKnownTypes/Type.cs b/Libs/Google.Protobuf/WellKnownTypes/Type.cs new file mode 100644 index 0000000..13f758c --- /dev/null +++ b/Libs/Google.Protobuf/WellKnownTypes/Type.cs @@ -0,0 +1,1877 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/type.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::LC.Google.Protobuf; +using pbc = global::LC.Google.Protobuf.Collections; +using pbr = global::LC.Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace LC.Google.Protobuf.WellKnownTypes { + + /// Holder for reflection information generated from google/protobuf/type.proto + public static partial class TypeReflection { + + #region Descriptor + /// File descriptor for google/protobuf/type.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static TypeReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Chpnb29nbGUvcHJvdG9idWYvdHlwZS5wcm90bxIPZ29vZ2xlLnByb3RvYnVm", + "Ghlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvGiRnb29nbGUvcHJvdG9idWYv", + "c291cmNlX2NvbnRleHQucHJvdG8i1wEKBFR5cGUSDAoEbmFtZRgBIAEoCRIm", + "CgZmaWVsZHMYAiADKAsyFi5nb29nbGUucHJvdG9idWYuRmllbGQSDgoGb25l", + "b2ZzGAMgAygJEigKB29wdGlvbnMYBCADKAsyFy5nb29nbGUucHJvdG9idWYu", + "T3B0aW9uEjYKDnNvdXJjZV9jb250ZXh0GAUgASgLMh4uZ29vZ2xlLnByb3Rv", + "YnVmLlNvdXJjZUNvbnRleHQSJwoGc3ludGF4GAYgASgOMhcuZ29vZ2xlLnBy", + "b3RvYnVmLlN5bnRheCLVBQoFRmllbGQSKQoEa2luZBgBIAEoDjIbLmdvb2ds", + "ZS5wcm90b2J1Zi5GaWVsZC5LaW5kEjcKC2NhcmRpbmFsaXR5GAIgASgOMiIu", + "Z29vZ2xlLnByb3RvYnVmLkZpZWxkLkNhcmRpbmFsaXR5Eg4KBm51bWJlchgD", + "IAEoBRIMCgRuYW1lGAQgASgJEhAKCHR5cGVfdXJsGAYgASgJEhMKC29uZW9m", + "X2luZGV4GAcgASgFEg4KBnBhY2tlZBgIIAEoCBIoCgdvcHRpb25zGAkgAygL", + "MhcuZ29vZ2xlLnByb3RvYnVmLk9wdGlvbhIRCglqc29uX25hbWUYCiABKAkS", + "FQoNZGVmYXVsdF92YWx1ZRgLIAEoCSLIAgoES2luZBIQCgxUWVBFX1VOS05P", + "V04QABIPCgtUWVBFX0RPVUJMRRABEg4KClRZUEVfRkxPQVQQAhIOCgpUWVBF", + "X0lOVDY0EAMSDwoLVFlQRV9VSU5UNjQQBBIOCgpUWVBFX0lOVDMyEAUSEAoM", + "VFlQRV9GSVhFRDY0EAYSEAoMVFlQRV9GSVhFRDMyEAcSDQoJVFlQRV9CT09M", + "EAgSDwoLVFlQRV9TVFJJTkcQCRIOCgpUWVBFX0dST1VQEAoSEAoMVFlQRV9N", + "RVNTQUdFEAsSDgoKVFlQRV9CWVRFUxAMEg8KC1RZUEVfVUlOVDMyEA0SDQoJ", + "VFlQRV9FTlVNEA4SEQoNVFlQRV9TRklYRUQzMhAPEhEKDVRZUEVfU0ZJWEVE", + "NjQQEBIPCgtUWVBFX1NJTlQzMhAREg8KC1RZUEVfU0lOVDY0EBIidAoLQ2Fy", + "ZGluYWxpdHkSFwoTQ0FSRElOQUxJVFlfVU5LTk9XThAAEhgKFENBUkRJTkFM", + "SVRZX09QVElPTkFMEAESGAoUQ0FSRElOQUxJVFlfUkVRVUlSRUQQAhIYChRD", + "QVJESU5BTElUWV9SRVBFQVRFRBADIs4BCgRFbnVtEgwKBG5hbWUYASABKAkS", + "LQoJZW51bXZhbHVlGAIgAygLMhouZ29vZ2xlLnByb3RvYnVmLkVudW1WYWx1", + "ZRIoCgdvcHRpb25zGAMgAygLMhcuZ29vZ2xlLnByb3RvYnVmLk9wdGlvbhI2", + "Cg5zb3VyY2VfY29udGV4dBgEIAEoCzIeLmdvb2dsZS5wcm90b2J1Zi5Tb3Vy", + "Y2VDb250ZXh0EicKBnN5bnRheBgFIAEoDjIXLmdvb2dsZS5wcm90b2J1Zi5T", + "eW50YXgiUwoJRW51bVZhbHVlEgwKBG5hbWUYASABKAkSDgoGbnVtYmVyGAIg", + "ASgFEigKB29wdGlvbnMYAyADKAsyFy5nb29nbGUucHJvdG9idWYuT3B0aW9u", + "IjsKBk9wdGlvbhIMCgRuYW1lGAEgASgJEiMKBXZhbHVlGAIgASgLMhQuZ29v", + "Z2xlLnByb3RvYnVmLkFueSouCgZTeW50YXgSEQoNU1lOVEFYX1BST1RPMhAA", + "EhEKDVNZTlRBWF9QUk9UTzMQAUJ7ChNjb20uZ29vZ2xlLnByb3RvYnVmQglU", + "eXBlUHJvdG9QAVotZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMv", + "a25vd24vdHlwZXBi+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxL", + "bm93blR5cGVzYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::LC.Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor, global::LC.Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::LC.Google.Protobuf.WellKnownTypes.Syntax), }, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Type), global::LC.Google.Protobuf.WellKnownTypes.Type.Parser, new[]{ "Name", "Fields", "Oneofs", "Options", "SourceContext", "Syntax" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Field), global::LC.Google.Protobuf.WellKnownTypes.Field.Parser, new[]{ "Kind", "Cardinality", "Number", "Name", "TypeUrl", "OneofIndex", "Packed", "Options", "JsonName", "DefaultValue" }, null, new[]{ typeof(global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind), typeof(global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Enum), global::LC.Google.Protobuf.WellKnownTypes.Enum.Parser, new[]{ "Name", "Enumvalue", "Options", "SourceContext", "Syntax" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.EnumValue), global::LC.Google.Protobuf.WellKnownTypes.EnumValue.Parser, new[]{ "Name", "Number", "Options" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::LC.Google.Protobuf.WellKnownTypes.Option), global::LC.Google.Protobuf.WellKnownTypes.Option.Parser, new[]{ "Name", "Value" }, null, null, null, null) + })); + } + #endregion + + } + #region Enums + /// + /// The syntax in which a protocol buffer element is defined. + /// + public enum Syntax { + /// + /// Syntax `proto2`. + /// + [pbr::OriginalName("SYNTAX_PROTO2")] Proto2 = 0, + /// + /// Syntax `proto3`. + /// + [pbr::OriginalName("SYNTAX_PROTO3")] Proto3 = 1, + } + + #endregion + + #region Messages + /// + /// A protocol buffer message type. + /// + public sealed partial class Type : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Type()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Type() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Type(Type other) : this() { + name_ = other.name_; + fields_ = other.fields_.Clone(); + oneofs_ = other.oneofs_.Clone(); + options_ = other.options_.Clone(); + sourceContext_ = other.sourceContext_ != null ? other.sourceContext_.Clone() : null; + syntax_ = other.syntax_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Type Clone() { + return new Type(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// The fully qualified message name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "fields" field. + public const int FieldsFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_fields_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.WellKnownTypes.Field.Parser); + private readonly pbc::RepeatedField fields_ = new pbc::RepeatedField(); + /// + /// The list of fields. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Fields { + get { return fields_; } + } + + /// Field number for the "oneofs" field. + public const int OneofsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_oneofs_codec + = pb::FieldCodec.ForString(26); + private readonly pbc::RepeatedField oneofs_ = new pbc::RepeatedField(); + /// + /// The list of types appearing in `oneof` definitions in this type. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Oneofs { + get { return oneofs_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_options_codec + = pb::FieldCodec.ForMessage(34, global::LC.Google.Protobuf.WellKnownTypes.Option.Parser); + private readonly pbc::RepeatedField options_ = new pbc::RepeatedField(); + /// + /// The protocol buffer options. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Options { + get { return options_; } + } + + /// Field number for the "source_context" field. + public const int SourceContextFieldNumber = 5; + private global::LC.Google.Protobuf.WellKnownTypes.SourceContext sourceContext_; + /// + /// The source context. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.SourceContext SourceContext { + get { return sourceContext_; } + set { + sourceContext_ = value; + } + } + + /// Field number for the "syntax" field. + public const int SyntaxFieldNumber = 6; + private global::LC.Google.Protobuf.WellKnownTypes.Syntax syntax_ = global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2; + /// + /// The source syntax. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Syntax Syntax { + get { return syntax_; } + set { + syntax_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Type); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Type other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!fields_.Equals(other.fields_)) return false; + if(!oneofs_.Equals(other.oneofs_)) return false; + if(!options_.Equals(other.options_)) return false; + if (!object.Equals(SourceContext, other.SourceContext)) return false; + if (Syntax != other.Syntax) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + hash ^= fields_.GetHashCode(); + hash ^= oneofs_.GetHashCode(); + hash ^= options_.GetHashCode(); + if (sourceContext_ != null) hash ^= SourceContext.GetHashCode(); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) hash ^= Syntax.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + fields_.WriteTo(output, _repeated_fields_codec); + oneofs_.WriteTo(output, _repeated_oneofs_codec); + options_.WriteTo(output, _repeated_options_codec); + if (sourceContext_ != null) { + output.WriteRawTag(42); + output.WriteMessage(SourceContext); + } + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(48); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + fields_.WriteTo(ref output, _repeated_fields_codec); + oneofs_.WriteTo(ref output, _repeated_oneofs_codec); + options_.WriteTo(ref output, _repeated_options_codec); + if (sourceContext_ != null) { + output.WriteRawTag(42); + output.WriteMessage(SourceContext); + } + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(48); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += fields_.CalculateSize(_repeated_fields_codec); + size += oneofs_.CalculateSize(_repeated_oneofs_codec); + size += options_.CalculateSize(_repeated_options_codec); + if (sourceContext_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContext); + } + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Type other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + fields_.Add(other.fields_); + oneofs_.Add(other.oneofs_); + options_.Add(other.options_); + if (other.sourceContext_ != null) { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + SourceContext.MergeFrom(other.SourceContext); + } + if (other.Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + Syntax = other.Syntax; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + fields_.AddEntriesFrom(input, _repeated_fields_codec); + break; + } + case 26: { + oneofs_.AddEntriesFrom(input, _repeated_oneofs_codec); + break; + } + case 34: { + options_.AddEntriesFrom(input, _repeated_options_codec); + break; + } + case 42: { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 48: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + fields_.AddEntriesFrom(ref input, _repeated_fields_codec); + break; + } + case 26: { + oneofs_.AddEntriesFrom(ref input, _repeated_oneofs_codec); + break; + } + case 34: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 42: { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 48: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + + } + + /// + /// A single field of a message type. + /// + public sealed partial class Field : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Field()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Field() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Field(Field other) : this() { + kind_ = other.kind_; + cardinality_ = other.cardinality_; + number_ = other.number_; + name_ = other.name_; + typeUrl_ = other.typeUrl_; + oneofIndex_ = other.oneofIndex_; + packed_ = other.packed_; + options_ = other.options_.Clone(); + jsonName_ = other.jsonName_; + defaultValue_ = other.defaultValue_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Field Clone() { + return new Field(this); + } + + /// Field number for the "kind" field. + public const int KindFieldNumber = 1; + private global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind kind_ = global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown; + /// + /// The field type. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind Kind { + get { return kind_; } + set { + kind_ = value; + } + } + + /// Field number for the "cardinality" field. + public const int CardinalityFieldNumber = 2; + private global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality cardinality_ = global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown; + /// + /// The field cardinality. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality Cardinality { + get { return cardinality_; } + set { + cardinality_ = value; + } + } + + /// Field number for the "number" field. + public const int NumberFieldNumber = 3; + private int number_; + /// + /// The field number. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Number { + get { return number_; } + set { + number_ = value; + } + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 4; + private string name_ = ""; + /// + /// The field name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "type_url" field. + public const int TypeUrlFieldNumber = 6; + private string typeUrl_ = ""; + /// + /// The field type URL, without the scheme, for message or enumeration + /// types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TypeUrl { + get { return typeUrl_; } + set { + typeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "oneof_index" field. + public const int OneofIndexFieldNumber = 7; + private int oneofIndex_; + /// + /// The index of the field type in `Type.oneofs`, for message or enumeration + /// types. The first type has index 1; zero means the type is not in the list. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int OneofIndex { + get { return oneofIndex_; } + set { + oneofIndex_ = value; + } + } + + /// Field number for the "packed" field. + public const int PackedFieldNumber = 8; + private bool packed_; + /// + /// Whether to use alternative packed wire representation. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Packed { + get { return packed_; } + set { + packed_ = value; + } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 9; + private static readonly pb::FieldCodec _repeated_options_codec + = pb::FieldCodec.ForMessage(74, global::LC.Google.Protobuf.WellKnownTypes.Option.Parser); + private readonly pbc::RepeatedField options_ = new pbc::RepeatedField(); + /// + /// The protocol buffer options. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Options { + get { return options_; } + } + + /// Field number for the "json_name" field. + public const int JsonNameFieldNumber = 10; + private string jsonName_ = ""; + /// + /// The field JSON name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string JsonName { + get { return jsonName_; } + set { + jsonName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "default_value" field. + public const int DefaultValueFieldNumber = 11; + private string defaultValue_ = ""; + /// + /// The string value of the default value of this field. Proto2 syntax only. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string DefaultValue { + get { return defaultValue_; } + set { + defaultValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Field); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Field other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Kind != other.Kind) return false; + if (Cardinality != other.Cardinality) return false; + if (Number != other.Number) return false; + if (Name != other.Name) return false; + if (TypeUrl != other.TypeUrl) return false; + if (OneofIndex != other.OneofIndex) return false; + if (Packed != other.Packed) return false; + if(!options_.Equals(other.options_)) return false; + if (JsonName != other.JsonName) return false; + if (DefaultValue != other.DefaultValue) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Kind != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) hash ^= Kind.GetHashCode(); + if (Cardinality != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown) hash ^= Cardinality.GetHashCode(); + if (Number != 0) hash ^= Number.GetHashCode(); + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (TypeUrl.Length != 0) hash ^= TypeUrl.GetHashCode(); + if (OneofIndex != 0) hash ^= OneofIndex.GetHashCode(); + if (Packed != false) hash ^= Packed.GetHashCode(); + hash ^= options_.GetHashCode(); + if (JsonName.Length != 0) hash ^= JsonName.GetHashCode(); + if (DefaultValue.Length != 0) hash ^= DefaultValue.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Kind != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) { + output.WriteRawTag(8); + output.WriteEnum((int) Kind); + } + if (Cardinality != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown) { + output.WriteRawTag(16); + output.WriteEnum((int) Cardinality); + } + if (Number != 0) { + output.WriteRawTag(24); + output.WriteInt32(Number); + } + if (Name.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Name); + } + if (TypeUrl.Length != 0) { + output.WriteRawTag(50); + output.WriteString(TypeUrl); + } + if (OneofIndex != 0) { + output.WriteRawTag(56); + output.WriteInt32(OneofIndex); + } + if (Packed != false) { + output.WriteRawTag(64); + output.WriteBool(Packed); + } + options_.WriteTo(output, _repeated_options_codec); + if (JsonName.Length != 0) { + output.WriteRawTag(82); + output.WriteString(JsonName); + } + if (DefaultValue.Length != 0) { + output.WriteRawTag(90); + output.WriteString(DefaultValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Kind != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) { + output.WriteRawTag(8); + output.WriteEnum((int) Kind); + } + if (Cardinality != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown) { + output.WriteRawTag(16); + output.WriteEnum((int) Cardinality); + } + if (Number != 0) { + output.WriteRawTag(24); + output.WriteInt32(Number); + } + if (Name.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Name); + } + if (TypeUrl.Length != 0) { + output.WriteRawTag(50); + output.WriteString(TypeUrl); + } + if (OneofIndex != 0) { + output.WriteRawTag(56); + output.WriteInt32(OneofIndex); + } + if (Packed != false) { + output.WriteRawTag(64); + output.WriteBool(Packed); + } + options_.WriteTo(ref output, _repeated_options_codec); + if (JsonName.Length != 0) { + output.WriteRawTag(82); + output.WriteString(JsonName); + } + if (DefaultValue.Length != 0) { + output.WriteRawTag(90); + output.WriteString(DefaultValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Kind != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Kind); + } + if (Cardinality != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Cardinality); + } + if (Number != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number); + } + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (TypeUrl.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeUrl); + } + if (OneofIndex != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofIndex); + } + if (Packed != false) { + size += 1 + 1; + } + size += options_.CalculateSize(_repeated_options_codec); + if (JsonName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName); + } + if (DefaultValue.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(DefaultValue); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Field other) { + if (other == null) { + return; + } + if (other.Kind != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) { + Kind = other.Kind; + } + if (other.Cardinality != global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown) { + Cardinality = other.Cardinality; + } + if (other.Number != 0) { + Number = other.Number; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.TypeUrl.Length != 0) { + TypeUrl = other.TypeUrl; + } + if (other.OneofIndex != 0) { + OneofIndex = other.OneofIndex; + } + if (other.Packed != false) { + Packed = other.Packed; + } + options_.Add(other.options_); + if (other.JsonName.Length != 0) { + JsonName = other.JsonName; + } + if (other.DefaultValue.Length != 0) { + DefaultValue = other.DefaultValue; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Kind = (global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum(); + break; + } + case 16: { + Cardinality = (global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) input.ReadEnum(); + break; + } + case 24: { + Number = input.ReadInt32(); + break; + } + case 34: { + Name = input.ReadString(); + break; + } + case 50: { + TypeUrl = input.ReadString(); + break; + } + case 56: { + OneofIndex = input.ReadInt32(); + break; + } + case 64: { + Packed = input.ReadBool(); + break; + } + case 74: { + options_.AddEntriesFrom(input, _repeated_options_codec); + break; + } + case 82: { + JsonName = input.ReadString(); + break; + } + case 90: { + DefaultValue = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Kind = (global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum(); + break; + } + case 16: { + Cardinality = (global::LC.Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) input.ReadEnum(); + break; + } + case 24: { + Number = input.ReadInt32(); + break; + } + case 34: { + Name = input.ReadString(); + break; + } + case 50: { + TypeUrl = input.ReadString(); + break; + } + case 56: { + OneofIndex = input.ReadInt32(); + break; + } + case 64: { + Packed = input.ReadBool(); + break; + } + case 74: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 82: { + JsonName = input.ReadString(); + break; + } + case 90: { + DefaultValue = input.ReadString(); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the Field message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + /// + /// Basic field types. + /// + public enum Kind { + /// + /// Field type unknown. + /// + [pbr::OriginalName("TYPE_UNKNOWN")] TypeUnknown = 0, + /// + /// Field type double. + /// + [pbr::OriginalName("TYPE_DOUBLE")] TypeDouble = 1, + /// + /// Field type float. + /// + [pbr::OriginalName("TYPE_FLOAT")] TypeFloat = 2, + /// + /// Field type int64. + /// + [pbr::OriginalName("TYPE_INT64")] TypeInt64 = 3, + /// + /// Field type uint64. + /// + [pbr::OriginalName("TYPE_UINT64")] TypeUint64 = 4, + /// + /// Field type int32. + /// + [pbr::OriginalName("TYPE_INT32")] TypeInt32 = 5, + /// + /// Field type fixed64. + /// + [pbr::OriginalName("TYPE_FIXED64")] TypeFixed64 = 6, + /// + /// Field type fixed32. + /// + [pbr::OriginalName("TYPE_FIXED32")] TypeFixed32 = 7, + /// + /// Field type bool. + /// + [pbr::OriginalName("TYPE_BOOL")] TypeBool = 8, + /// + /// Field type string. + /// + [pbr::OriginalName("TYPE_STRING")] TypeString = 9, + /// + /// Field type group. Proto2 syntax only, and deprecated. + /// + [pbr::OriginalName("TYPE_GROUP")] TypeGroup = 10, + /// + /// Field type message. + /// + [pbr::OriginalName("TYPE_MESSAGE")] TypeMessage = 11, + /// + /// Field type bytes. + /// + [pbr::OriginalName("TYPE_BYTES")] TypeBytes = 12, + /// + /// Field type uint32. + /// + [pbr::OriginalName("TYPE_UINT32")] TypeUint32 = 13, + /// + /// Field type enum. + /// + [pbr::OriginalName("TYPE_ENUM")] TypeEnum = 14, + /// + /// Field type sfixed32. + /// + [pbr::OriginalName("TYPE_SFIXED32")] TypeSfixed32 = 15, + /// + /// Field type sfixed64. + /// + [pbr::OriginalName("TYPE_SFIXED64")] TypeSfixed64 = 16, + /// + /// Field type sint32. + /// + [pbr::OriginalName("TYPE_SINT32")] TypeSint32 = 17, + /// + /// Field type sint64. + /// + [pbr::OriginalName("TYPE_SINT64")] TypeSint64 = 18, + } + + /// + /// Whether a field is optional, required, or repeated. + /// + public enum Cardinality { + /// + /// For fields with unknown cardinality. + /// + [pbr::OriginalName("CARDINALITY_UNKNOWN")] Unknown = 0, + /// + /// For optional fields. + /// + [pbr::OriginalName("CARDINALITY_OPTIONAL")] Optional = 1, + /// + /// For required fields. Proto2 syntax only. + /// + [pbr::OriginalName("CARDINALITY_REQUIRED")] Required = 2, + /// + /// For repeated fields. + /// + [pbr::OriginalName("CARDINALITY_REPEATED")] Repeated = 3, + } + + } + #endregion + + } + + /// + /// Enum type definition. + /// + public sealed partial class Enum : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Enum()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Enum() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Enum(Enum other) : this() { + name_ = other.name_; + enumvalue_ = other.enumvalue_.Clone(); + options_ = other.options_.Clone(); + sourceContext_ = other.sourceContext_ != null ? other.sourceContext_.Clone() : null; + syntax_ = other.syntax_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Enum Clone() { + return new Enum(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// Enum type name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "enumvalue" field. + public const int EnumvalueFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_enumvalue_codec + = pb::FieldCodec.ForMessage(18, global::LC.Google.Protobuf.WellKnownTypes.EnumValue.Parser); + private readonly pbc::RepeatedField enumvalue_ = new pbc::RepeatedField(); + /// + /// Enum value definitions. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Enumvalue { + get { return enumvalue_; } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_options_codec + = pb::FieldCodec.ForMessage(26, global::LC.Google.Protobuf.WellKnownTypes.Option.Parser); + private readonly pbc::RepeatedField options_ = new pbc::RepeatedField(); + /// + /// Protocol buffer options. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Options { + get { return options_; } + } + + /// Field number for the "source_context" field. + public const int SourceContextFieldNumber = 4; + private global::LC.Google.Protobuf.WellKnownTypes.SourceContext sourceContext_; + /// + /// The source context. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.SourceContext SourceContext { + get { return sourceContext_; } + set { + sourceContext_ = value; + } + } + + /// Field number for the "syntax" field. + public const int SyntaxFieldNumber = 5; + private global::LC.Google.Protobuf.WellKnownTypes.Syntax syntax_ = global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2; + /// + /// The source syntax. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::LC.Google.Protobuf.WellKnownTypes.Syntax Syntax { + get { return syntax_; } + set { + syntax_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Enum); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Enum other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!enumvalue_.Equals(other.enumvalue_)) return false; + if(!options_.Equals(other.options_)) return false; + if (!object.Equals(SourceContext, other.SourceContext)) return false; + if (Syntax != other.Syntax) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + hash ^= enumvalue_.GetHashCode(); + hash ^= options_.GetHashCode(); + if (sourceContext_ != null) hash ^= SourceContext.GetHashCode(); + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) hash ^= Syntax.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + enumvalue_.WriteTo(output, _repeated_enumvalue_codec); + options_.WriteTo(output, _repeated_options_codec); + if (sourceContext_ != null) { + output.WriteRawTag(34); + output.WriteMessage(SourceContext); + } + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(40); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + enumvalue_.WriteTo(ref output, _repeated_enumvalue_codec); + options_.WriteTo(ref output, _repeated_options_codec); + if (sourceContext_ != null) { + output.WriteRawTag(34); + output.WriteMessage(SourceContext); + } + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(40); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += enumvalue_.CalculateSize(_repeated_enumvalue_codec); + size += options_.CalculateSize(_repeated_options_codec); + if (sourceContext_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContext); + } + if (Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Enum other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + enumvalue_.Add(other.enumvalue_); + options_.Add(other.options_); + if (other.sourceContext_ != null) { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + SourceContext.MergeFrom(other.SourceContext); + } + if (other.Syntax != global::LC.Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + Syntax = other.Syntax; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + enumvalue_.AddEntriesFrom(input, _repeated_enumvalue_codec); + break; + } + case 26: { + options_.AddEntriesFrom(input, _repeated_options_codec); + break; + } + case 34: { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 40: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + enumvalue_.AddEntriesFrom(ref input, _repeated_enumvalue_codec); + break; + } + case 26: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 34: { + if (sourceContext_ == null) { + SourceContext = new global::LC.Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 40: { + Syntax = (global::LC.Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + + } + + /// + /// Enum value definition. + /// + public sealed partial class EnumValue : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValue()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::LC.Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[3]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValue() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValue(EnumValue other) : this() { + name_ = other.name_; + number_ = other.number_; + options_ = other.options_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EnumValue Clone() { + return new EnumValue(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// Enum value name. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "number" field. + public const int NumberFieldNumber = 2; + private int number_; + /// + /// Enum value number. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Number { + get { return number_; } + set { + number_ = value; + } + } + + /// Field number for the "options" field. + public const int OptionsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_options_codec + = pb::FieldCodec.ForMessage(26, global::LC.Google.Protobuf.WellKnownTypes.Option.Parser); + private readonly pbc::RepeatedField options_ = new pbc::RepeatedField(); + /// + /// Protocol buffer options. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Options { + get { return options_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EnumValue); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EnumValue other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Number != other.Number) return false; + if(!options_.Equals(other.options_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (Number != 0) hash ^= Number.GetHashCode(); + hash ^= options_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Number != 0) { + output.WriteRawTag(16); + output.WriteInt32(Number); + } + options_.WriteTo(output, _repeated_options_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Number != 0) { + output.WriteRawTag(16); + output.WriteInt32(Number); + } + options_.WriteTo(ref output, _repeated_options_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (Number != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number); + } + size += options_.CalculateSize(_repeated_options_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EnumValue other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.Number != 0) { + Number = other.Number; + } + options_.Add(other.options_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Number = input.ReadInt32(); + break; + } + case 26: { + options_.AddEntriesFrom(input, _repeated_options_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Number = input.ReadInt32(); + break; + } + case 26: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + } + } + } + #endif + + } + + /// + /// A protocol buffer option, which can be attached to a message, field, + /// enumeration, etc. + /// + public sealed partial class Option : pb::IMessage