Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ProtobufCS/2.4.1/ProtobufCS/src/ProtocolBuffers/IBuilder.cs @ 8295

Last change on this file since 8295 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: 13.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;
38using System.Collections.Generic;
39using System.IO;
40using Google.ProtocolBuffers.Descriptors;
41
42namespace Google.ProtocolBuffers
43{
44    /// <summary>
45    /// Non-generic interface for all members whose signatures don't require knowledge of
46    /// the type being built. The generic interface extends this one. Some methods return
47    /// either an IBuilder or an IMessage; in these cases the generic interface redeclares
48    /// the same method with a type-specific signature. Implementations are encouraged to
49    /// use explicit interface implemenation for the non-generic form. This mirrors
50    /// how IEnumerable and IEnumerable&lt;T&gt; work.
51    /// </summary>
52    public interface IBuilder : IBuilderLite
53    {
54        /// <summary>
55        /// Returns true iff all required fields in the message and all
56        /// embedded messages are set.
57        /// </summary>
58        new bool IsInitialized { get; }
59
60        /// <summary>
61        /// Only present in the nongeneric interface - useful for tests, but
62        /// not as much in real life.
63        /// </summary>
64        IBuilder SetField(FieldDescriptor field, object value);
65
66        /// <summary>
67        /// Only present in the nongeneric interface - useful for tests, but
68        /// not as much in real life.
69        /// </summary>
70        IBuilder SetRepeatedField(FieldDescriptor field, int index, object value);
71
72        /// <summary>
73        /// Behaves like the equivalent property in IMessage&lt;T&gt;.
74        /// The returned map may or may not reflect future changes to the builder.
75        /// Either way, the returned map is unmodifiable.
76        /// </summary>
77        IDictionary<FieldDescriptor, object> AllFields { get; }
78
79        /// <summary>
80        /// Allows getting and setting of a field.
81        /// <see cref="IMessage{TMessage, TBuilder}.Item(FieldDescriptor)"/>
82        /// </summary>
83        /// <param name="field"></param>
84        /// <returns></returns>
85        object this[FieldDescriptor field] { get; set; }
86
87        /// <summary>
88        /// Get the message's type descriptor.
89        /// <see cref="IMessage{TMessage, TBuilder}.DescriptorForType"/>
90        /// </summary>
91        MessageDescriptor DescriptorForType { get; }
92
93        /// <summary>
94        /// <see cref="IMessage{TMessage, TBuilder}.GetRepeatedFieldCount"/>
95        /// </summary>
96        /// <param name="field"></param>
97        /// <returns></returns>
98        int GetRepeatedFieldCount(FieldDescriptor field);
99
100        /// <summary>
101        /// Allows getting and setting of a repeated field value.
102        /// <see cref="IMessage{TMessage, TBuilder}.Item(FieldDescriptor, int)"/>
103        /// </summary>
104        object this[FieldDescriptor field, int index] { get; set; }
105
106        /// <summary>
107        /// <see cref="IMessage{TMessage, TBuilder}.HasField"/>
108        /// </summary>
109        bool HasField(FieldDescriptor field);
110
111        /// <summary>
112        /// <see cref="IMessage{TMessage, TBuilder}.UnknownFields"/>
113        /// </summary>
114        UnknownFieldSet UnknownFields { get; set; }
115
116        /// <summary>
117        /// Create a builder for messages of the appropriate type for the given field.
118        /// Messages built with this can then be passed to the various mutation properties
119        /// and methods.
120        /// </summary>
121        IBuilder CreateBuilderForField(FieldDescriptor field);
122
123        #region Methods which are like those of the generic form, but without any knowledge of the type parameters
124
125        IBuilder WeakAddRepeatedField(FieldDescriptor field, object value);
126        new IBuilder WeakClear();
127        IBuilder WeakClearField(FieldDescriptor field);
128        IBuilder WeakMergeFrom(IMessage message);
129        new IBuilder WeakMergeFrom(ByteString data);
130        new IBuilder WeakMergeFrom(ByteString data, ExtensionRegistry registry);
131        new IBuilder WeakMergeFrom(ICodedInputStream input);
132        new IBuilder WeakMergeFrom(ICodedInputStream input, ExtensionRegistry registry);
133        new IMessage WeakBuild();
134        new IMessage WeakBuildPartial();
135        new IBuilder WeakClone();
136        new IMessage WeakDefaultInstanceForType { get; }
137
138        #endregion
139    }
140
141    /// <summary>
142    /// Interface implemented by Protocol Message builders.
143    /// TODO(jonskeet): Consider "SetXXX" methods returning the builder, as well as the properties.
144    /// </summary>
145    /// <typeparam name="TMessage">Type of message</typeparam>
146    /// <typeparam name="TBuilder">Type of builder</typeparam>
147    public interface IBuilder<TMessage, TBuilder> : IBuilder, IBuilderLite<TMessage, TBuilder>
148        where TMessage : IMessage<TMessage, TBuilder>
149        where TBuilder : IBuilder<TMessage, TBuilder>
150    {
151        TBuilder SetUnknownFields(UnknownFieldSet unknownFields);
152
153        /// <summary>
154        /// Resets all fields to their default values.
155        /// </summary>
156        new TBuilder Clear();
157
158        /// <summary>
159        /// Merge the specified other message which may be a different implementation of
160        /// the same message descriptor.
161        /// </summary>
162        TBuilder MergeFrom(IMessage other);
163
164        /// <summary>
165        /// Constructs the final message. Once this is called, this Builder instance
166        /// is no longer valid, and calling any other method may throw a
167        /// NullReferenceException. If you need to continue working with the builder
168        /// after calling Build, call Clone first.
169        /// </summary>
170        /// <exception cref="UninitializedMessageException">the message
171        /// is missing one or more required fields; use BuildPartial to bypass
172        /// this check</exception>
173        new TMessage Build();
174
175        /// <summary>
176        /// Like Build(), but does not throw an exception if the message is missing
177        /// required fields. Instead, a partial message is returned.
178        /// </summary>
179        new TMessage BuildPartial();
180
181        /// <summary>
182        /// Clones this builder.
183        /// TODO(jonskeet): Explain depth of clone.
184        /// </summary>
185        new TBuilder Clone();
186
187        /// <summary>
188        /// Parses a message of this type from the input and merges it with this
189        /// message, as if using MergeFrom(IMessage&lt;T&gt;).
190        /// </summary>
191        /// <remarks>
192        /// Warning: This does not verify that all required fields are present
193        /// in the input message. If you call Build() without setting all
194        /// required fields, it will throw an UninitializedMessageException.
195        /// There are a few good ways to deal with this:
196        /// <list>
197        /// <item>Call IsInitialized to verify to verify that all required fields are
198        /// set before building.</item>
199        /// <item>Parse  the message separately using one of the static ParseFrom
200        /// methods, then use MergeFrom(IMessage&lt;T&gt;) to merge it with
201        /// this one. ParseFrom will throw an InvalidProtocolBufferException
202        /// (an IOException) if some required fields are missing.
203        /// Use BuildPartial to build, which ignores missing required fields.
204        /// </list>
205        /// </remarks>
206        new TBuilder MergeFrom(ICodedInputStream input);
207
208        /// <summary>
209        /// Like MergeFrom(ICodedInputStream), but also parses extensions.
210        /// The extensions that you want to be able to parse must be registered
211        /// in <paramref name="extensionRegistry"/>. Extensions not in the registry
212        /// will be treated as unknown fields.
213        /// </summary>
214        new TBuilder MergeFrom(ICodedInputStream input, ExtensionRegistry extensionRegistry);
215
216        /// <summary>
217        /// Get's the message's type's default instance.
218        /// <see cref="IMessage{TMessage}.DefaultInstanceForType" />
219        /// </summary>
220        new TMessage DefaultInstanceForType { get; }
221
222        /// <summary>
223        /// Clears the field. This is exactly equivalent to calling the generated
224        /// Clear method corresponding to the field.
225        /// </summary>
226        /// <param name="field"></param>
227        /// <returns></returns>
228        TBuilder ClearField(FieldDescriptor field);
229
230        /// <summary>
231        /// Appends the given value as a new element for the specified repeated field.
232        /// </summary>
233        /// <exception cref="ArgumentException">the field is not a repeated field,
234        /// the field does not belong to this builder's type, or the value is
235        /// of the incorrect type
236        /// </exception>
237        TBuilder AddRepeatedField(FieldDescriptor field, object value);
238
239        /// <summary>
240        /// Merge some unknown fields into the set for this message.
241        /// </summary>
242        TBuilder MergeUnknownFields(UnknownFieldSet unknownFields);
243
244        /// <summary>
245        /// Like MergeFrom(Stream), but does not read until the end of the file.
246        /// Instead, the size of the message (encoded as a varint) is read first,
247        /// then the message data. Use Message.WriteDelimitedTo(Stream) to
248        /// write messages in this format.
249        /// </summary>
250        /// <param name="input"></param>
251        new TBuilder MergeDelimitedFrom(Stream input);
252
253        /// <summary>
254        /// Like MergeDelimitedFrom(Stream) but supporting extensions.
255        /// </summary>
256        new TBuilder MergeDelimitedFrom(Stream input, ExtensionRegistry extensionRegistry);
257
258        #region Convenience methods
259
260        /// <summary>
261        /// Parse <paramref name="data"/> as a message of this type and merge
262        /// it with the message being built. This is just a small wrapper around
263        /// MergeFrom(ICodedInputStream).
264        /// </summary>
265        new TBuilder MergeFrom(ByteString data);
266
267        /// <summary>
268        /// Parse <paramref name="data"/> as a message of this type and merge
269        /// it with the message being built. This is just a small wrapper around
270        /// MergeFrom(ICodedInputStream, extensionRegistry).
271        /// </summary>
272        new TBuilder MergeFrom(ByteString data, ExtensionRegistry extensionRegistry);
273
274        /// <summary>
275        /// Parse <paramref name="data"/> as a message of this type and merge
276        /// it with the message being built. This is just a small wrapper around
277        /// MergeFrom(ICodedInputStream).
278        /// </summary>
279        new TBuilder MergeFrom(byte[] data);
280
281        /// <summary>
282        /// Parse <paramref name="data"/> as a message of this type and merge
283        /// it with the message being built. This is just a small wrapper around
284        /// MergeFrom(ICodedInputStream, extensionRegistry).
285        /// </summary>
286        new TBuilder MergeFrom(byte[] data, ExtensionRegistry extensionRegistry);
287
288        /// <summary>
289        /// Parse <paramref name="input"/> as a message of this type and merge
290        /// it with the message being built. This is just a small wrapper around
291        /// MergeFrom(ICodedInputStream). Note that this method always reads
292        /// the entire input (unless it throws an exception). If you want it to
293        /// stop earlier, you will need to wrap the input in a wrapper
294        /// stream which limits reading. Or, use IMessage.WriteDelimitedTo(Stream)
295        /// to write your message and MmergeDelimitedFrom(Stream) to read it.
296        /// Despite usually reading the entire stream, this method never closes the stream.
297        /// </summary>
298        new TBuilder MergeFrom(Stream input);
299
300        /// <summary>
301        /// Parse <paramref name="input"/> as a message of this type and merge
302        /// it with the message being built. This is just a small wrapper around
303        /// MergeFrom(ICodedInputStream, extensionRegistry).
304        /// </summary>
305        new TBuilder MergeFrom(Stream input, ExtensionRegistry extensionRegistry);
306
307        #endregion
308    }
309}
Note: See TracBrowser for help on using the repository browser.