1 #region Copyright notice and license 2 // Protocol Buffers - Google's data interchange format 3 // Copyright 2008 Google Inc. All rights reserved. 4 // 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file or at 7 // https://developers.google.com/open-source/licenses/bsd 8 #endregion 9 10 using System; 11 using Google.Protobuf.Reflection; 12 13 namespace Google.Protobuf 14 { 15 /// <summary> 16 /// Interface for a Protocol Buffers message, supporting 17 /// basic operations required for serialization. 18 /// </summary> 19 public interface IMessage 20 { 21 /// <summary> 22 /// Merges the data from the specified coded input stream with the current message. 23 /// </summary> 24 /// <remarks>See the user guide for precise merge semantics.</remarks> 25 /// <param name="input"></param> MergeFrom(CodedInputStream input)26 void MergeFrom(CodedInputStream input); 27 28 /// <summary> 29 /// Writes the data to the given coded output stream. 30 /// </summary> 31 /// <param name="output">Coded output stream to write the data to. Must not be null.</param> WriteTo(CodedOutputStream output)32 void WriteTo(CodedOutputStream output); 33 34 /// <summary> 35 /// Calculates the size of this message in Protocol Buffer wire format, in bytes. 36 /// </summary> 37 /// <returns>The number of bytes required to write this message 38 /// to a coded output stream.</returns> CalculateSize()39 int CalculateSize(); 40 41 /// <summary> 42 /// Descriptor for this message. All instances are expected to return the same descriptor, 43 /// and for generated types this will be an explicitly-implemented member, returning the 44 /// same value as the static property declared on the type. 45 /// </summary> 46 MessageDescriptor Descriptor { get; } 47 } 48 49 /// <summary> 50 /// Generic interface for a Protocol Buffers message, 51 /// where the type parameter is expected to be the same type as 52 /// the implementation class. 53 /// </summary> 54 /// <typeparam name="T">The message type.</typeparam> 55 public interface IMessage<T> : IMessage, IEquatable<T>, IDeepCloneable<T> where T : IMessage<T> 56 { 57 /// <summary> 58 /// Merges the given message into this one. 59 /// </summary> 60 /// <remarks>See the user guide for precise merge semantics.</remarks> 61 /// <param name="message">The message to merge with this one. Must not be null.</param> MergeFrom(T message)62 void MergeFrom(T message); 63 } 64 } 65