1 #region Copyright notice and license 2 // Protocol Buffers - Google's data interchange format 3 // Copyright 2008 Google Inc. All rights reserved. 4 // https://developers.google.com/protocol-buffers/ 5 // 6 // Redistribution and use in source and binary forms, with or without 7 // modification, are permitted provided that the following conditions are 8 // met: 9 // 10 // * Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // * Redistributions in binary form must reproduce the above 13 // copyright notice, this list of conditions and the following disclaimer 14 // in the documentation and/or other materials provided with the 15 // distribution. 16 // * Neither the name of Google Inc. nor the names of its 17 // contributors may be used to endorse or promote products derived from 18 // this software without specific prior written permission. 19 // 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 #endregion 32 33 using System; 34 using Google.Protobuf.Reflection; 35 36 namespace Google.Protobuf 37 { 38 /// <summary> 39 /// Interface for a Protocol Buffers message, supporting 40 /// basic operations required for serialization. 41 /// </summary> 42 public interface IMessage 43 { 44 /// <summary> 45 /// Merges the data from the specified coded input stream with the current message. 46 /// </summary> 47 /// <remarks>See the user guide for precise merge semantics.</remarks> 48 /// <param name="input"></param> MergeFrom(CodedInputStream input)49 void MergeFrom(CodedInputStream input); 50 51 /// <summary> 52 /// Writes the data to the given coded output stream. 53 /// </summary> 54 /// <param name="output">Coded output stream to write the data to. Must not be null.</param> WriteTo(CodedOutputStream output)55 void WriteTo(CodedOutputStream output); 56 57 /// <summary> 58 /// Calculates the size of this message in Protocol Buffer wire format, in bytes. 59 /// </summary> 60 /// <returns>The number of bytes required to write this message 61 /// to a coded output stream.</returns> CalculateSize()62 int CalculateSize(); 63 64 /// <summary> 65 /// Descriptor for this message. All instances are expected to return the same descriptor, 66 /// and for generated types this will be an explicitly-implemented member, returning the 67 /// same value as the static property declared on the type. 68 /// </summary> 69 MessageDescriptor Descriptor { get; } 70 } 71 72 /// <summary> 73 /// Generic interface for a Protocol Buffers message, 74 /// where the type parameter is expected to be the same type as 75 /// the implementation class. 76 /// </summary> 77 /// <typeparam name="T">The message type.</typeparam> 78 public interface IMessage<T> : IMessage, IEquatable<T>, IDeepCloneable<T> where T : IMessage<T> 79 { 80 /// <summary> 81 /// Merges the given message into this one. 82 /// </summary> 83 /// <remarks>See the user guide for precise merge semantics.</remarks> 84 /// <param name="message">The message to merge with this one. Must not be null.</param> MergeFrom(T message)85 void MergeFrom(T message); 86 } 87 } 88