Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.ProtobufCS/2.4.1/ProtobufCS/src/ProtocolBuffers/IMessageLite.cs @ 10743

Last change on this file since 10743 was 8295, checked in by abeham, 12 years ago

#1897:

  • Removed protocol buffers 0.9.1
  • Added protocol buffers 2.4.1
  • Updated proto processing command
File size: 7.6 KB
Line 
1#region Copyright notice and license
2
3// Protocol Buffers - Google's data interchange format
4// Copyright 2008 Google Inc.  All rights reserved.
5// http://github.com/jskeet/dotnet-protobufs/
6// Original C++/Java/Python code:
7// http://code.google.com/p/protobuf/
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13//     * Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//     * Redistributions in binary form must reproduce the above
16// copyright notice, this list of conditions and the following disclaimer
17// in the documentation and/or other materials provided with the
18// distribution.
19//     * Neither the name of Google Inc. nor the names of its
20// contributors may be used to endorse or promote products derived from
21// this software without specific prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35#endregion
36
37using System.IO;
38
39namespace Google.ProtocolBuffers
40{
41    /// <summary>
42    /// Non-generic interface used for all parts of the API which don't require
43    /// any type knowledge.
44    /// </summary>
45    public partial interface IMessageLite
46    {
47        /// <summary>
48        /// Returns true iff all required fields in the message and all embedded
49        /// messages are set.
50        /// </summary>
51        bool IsInitialized { get; }
52
53        /// <summary>
54        /// Serializes the message and writes it to the given output stream.
55        /// This does not flush or close the stream.
56        /// </summary>
57        /// <remarks>
58        /// Protocol Buffers are not self-delimiting. Therefore, if you write
59        /// any more data to the stream after the message, you must somehow ensure
60        /// that the parser on the receiving end does not interpret this as being
61        /// part of the protocol message. One way of doing this is by writing the size
62        /// of the message before the data, then making sure you limit the input to
63        /// that size when receiving the data. Alternatively, use WriteDelimitedTo(Stream).
64        /// </remarks>
65        void WriteTo(ICodedOutputStream output);
66
67        /// <summary>
68        /// Like WriteTo(Stream) but writes the size of the message as a varint before
69        /// writing the data. This allows more data to be written to the stream after the
70        /// message without the need to delimit the message data yourself. Use
71        /// IBuilder.MergeDelimitedFrom(Stream) or the static method
72        /// YourMessageType.ParseDelimitedFrom(Stream) to parse messages written by this method.
73        /// </summary>
74        /// <param name="output"></param>
75        void WriteDelimitedTo(Stream output);
76
77        /// <summary>
78        /// Returns the number of bytes required to encode this message.
79        /// The result is only computed on the first call and memoized after that.
80        /// </summary>
81        int SerializedSize { get; }
82
83        #region Comparison and hashing
84
85        /// <summary>
86        /// Compares the specified object with this message for equality.
87        /// Returns true iff the given object is a message of the same type
88        /// (as defined by DescriptorForType) and has identical values
89        /// for all its fields.
90        /// </summary>
91        bool Equals(object other);
92
93        /// <summary>
94        /// Returns the hash code value for this message.
95        /// TODO(jonskeet): Specify the hash algorithm, but better than the Java one!
96        /// </summary>
97        int GetHashCode();
98
99        #endregion
100
101        #region Convenience methods
102
103        /// <summary>
104        /// Converts the message to a string in protocol buffer text format.
105        /// This is just a trivial wrapper around TextFormat.PrintToString.
106        /// </summary>
107        string ToString();
108
109        /// <summary>
110        /// Converts the message to a string.
111        /// </summary>
112        void PrintTo(TextWriter writer);
113
114        /// <summary>
115        /// Serializes the message to a ByteString. This is a trivial wrapper
116        /// around WriteTo(ICodedOutputStream).
117        /// </summary>
118        ByteString ToByteString();
119
120        /// <summary>
121        /// Serializes the message to a byte array. This is a trivial wrapper
122        /// around WriteTo(ICodedOutputStream).
123        /// </summary>
124        byte[] ToByteArray();
125
126        /// <summary>
127        /// Serializes the message and writes it to the given stream.
128        /// This is just a wrapper around WriteTo(ICodedOutputStream). This
129        /// does not flush or close the stream.
130        /// </summary>
131        /// <param name="output"></param>
132        void WriteTo(Stream output);
133
134        #endregion
135
136        /// <summary>
137        /// Creates a builder for the type, but in a weakly typed manner. This
138        /// is typically implemented by strongly typed messages by just returning
139        /// the result of CreateBuilderForType.
140        /// </summary>
141        IBuilderLite WeakCreateBuilderForType();
142
143        /// <summary>
144        /// Creates a builder with the same contents as this message. This
145        /// is typically implemented by strongly typed messages by just returning
146        /// the result of ToBuilder.
147        /// </summary>
148        IBuilderLite WeakToBuilder();
149
150        IMessageLite WeakDefaultInstanceForType { get; }
151    }
152
153    public interface IMessageLite<TMessage> : IMessageLite
154    {
155        /// <summary>
156        /// Returns an instance of this message type with all fields set to
157        /// their default values. This may or may not be a singleton. This differs
158        /// from the DefaultInstance property of each generated message class in that this
159        /// method is an abstract method of IMessage whereas DefaultInstance is
160        /// a static property of a specific class. They return the same thing.
161        /// </summary>
162        TMessage DefaultInstanceForType { get; }
163    }
164
165    /// <summary>
166    /// Type-safe interface for all generated messages to implement.
167    /// </summary>
168    public interface IMessageLite<TMessage, TBuilder> : IMessageLite<TMessage>
169        where TMessage : IMessageLite<TMessage, TBuilder>
170        where TBuilder : IBuilderLite<TMessage, TBuilder>
171    {
172        #region Builders
173
174        /// <summary>
175        /// Constructs a new builder for a message of the same type as this message.
176        /// </summary>
177        TBuilder CreateBuilderForType();
178
179        /// <summary>
180        /// Creates a builder with the same contents as this current instance.
181        /// This is typically implemented by strongly typed messages by just
182        /// returning the result of ToBuilder().
183        /// </summary>
184        TBuilder ToBuilder();
185
186        #endregion
187    }
188}
Note: See TracBrowser for help on using the repository browser.