blob: b72093243ab97476d3045e4cbc1c5607153d0e2f [file] [log] [blame]
Thomas Van Lenten30650d82015-05-01 08:57:16 -04001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15// * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#import <Foundation/Foundation.h>
32
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040033#import "GPBArray.h"
Thomas Van Lenten30650d82015-05-01 08:57:16 -040034#import "GPBMessage.h"
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040035#import "GPBRuntimeTypes.h"
Thomas Van Lenten30650d82015-05-01 08:57:16 -040036
37CF_EXTERN_C_BEGIN
38
Thomas Van Lenten8c889572015-06-16 16:45:14 -040039NS_ASSUME_NONNULL_BEGIN
40
Thomas Van Lenten36650a02016-03-07 12:07:03 -050041/// Generates a string that should be a valid "Text Format" for the C++ version
42/// of Protocol Buffers.
43///
44/// @param message The message to generate from.
45/// @param lineIndent A string to use as the prefix for all lines generated. Can
46/// be nil if no extra indent is needed.
47///
48/// @return A @c NSString with the Text Format of the message.
Thomas Van Lenten8c889572015-06-16 16:45:14 -040049NSString *GPBTextFormatForMessage(GPBMessage *message,
50 NSString * __nullable lineIndent);
Thomas Van Lenten36650a02016-03-07 12:07:03 -050051
52/// Generates a string that should be a valid "Text Format" for the C++ version
53/// of Protocol Buffers.
54///
55/// @param unknownSet The unknown field set to generate from.
56/// @param lineIndent A string to use as the prefix for all lines generated. Can
57/// be nil if no extra indent is needed.
58///
59/// @return A @c NSString with the Text Format of the unknown field set.
Thomas Van Lentenc27833b2015-12-07 10:49:30 -050060NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
Thomas Van Lenten8c889572015-06-16 16:45:14 -040061 NSString * __nullable lineIndent);
Thomas Van Lenten30650d82015-05-01 08:57:16 -040062
Thomas Van Lenten36650a02016-03-07 12:07:03 -050063/// Test if the given field is set on a message.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040064BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
Thomas Van Lenten36650a02016-03-07 12:07:03 -050065/// Test if the given field is set on a message.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040066BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
67
Thomas Van Lenten36650a02016-03-07 12:07:03 -050068/// Clear the given field of a message.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040069void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
70
71//%PDDM-EXPAND GPB_ACCESSORS()
72// This block of code is generated, do not edit it directly.
73
74
75//
76// Get/Set the given field of a message.
77//
78
79// Single Fields
80
Thomas Van Lenten36650a02016-03-07 12:07:03 -050081/// Gets the value of a bytes field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040082NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -050083/// Sets the value of a bytes field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040084void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
85
Thomas Van Lenten36650a02016-03-07 12:07:03 -050086/// Gets the value of a string field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040087NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -050088/// Sets the value of a string field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040089void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
90
Thomas Van Lenten36650a02016-03-07 12:07:03 -050091/// Gets the value of a message field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040092GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -050093/// Sets the value of a message field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040094void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
95
Thomas Van Lenten36650a02016-03-07 12:07:03 -050096/// Gets the value of a group field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040097GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -050098/// Sets the value of a group field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040099void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
100
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500101/// Gets the value of a bool field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400102BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500103/// Sets the value of a bool field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400104void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
105
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500106/// Gets the value of an int32 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400107int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500108/// Sets the value of an int32 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400109void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
110
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500111/// Gets the value of an uint32 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400112uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500113/// Sets the value of an uint32 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400114void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
115
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500116/// Gets the value of an int64 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400117int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500118/// Sets the value of an int64 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400119void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
120
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500121/// Gets the value of an uint64 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400122uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500123/// Sets the value of an uint64 field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400124void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
125
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500126/// Gets the value of a float field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400127float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500128/// Sets the value of a float field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400129void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
130
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500131/// Gets the value of a double field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400132double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500133/// Sets the value of a double field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400134void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
135
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500136/// Get the given enum field of a message. For proto3, if the value isn't a
137/// member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
138/// GPBGetMessageRawEnumField will bypass the check and return whatever value
139/// was set.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400140int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500141/// Set the given enum field of a message. You can only set values that are
142/// members of the enum.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400143void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500144/// Get the given enum field of a message. No check is done to ensure the value
145/// was defined in the enum.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400146int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500147/// Set the given enum field of a message. You can set the value to anything,
148/// even a value that is not a member of the enum.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400149void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
150
151// Repeated Fields
152
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500153/// Gets the value of a repeated field.
154///
155/// The result will be @c GPB*Array or @c NSMutableArray based on the
156/// field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400157id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500158/// Sets the value of a repeated field.
159///
160/// The value should be @c GPB*Array or @c NSMutableArray based on the
161/// field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400162void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array);
163
164// Map Fields
165
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500166/// Gets the value of a map<> field.
167///
168/// The result will be @c GPB*Dictionary or @c NSMutableDictionary based on
169/// the field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400170id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500171/// Sets the value of a map<> field.
172///
173/// The object should be @c GPB*Dictionary or @c NSMutableDictionary based
174/// on the field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400175void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary);
176
177//%PDDM-EXPAND-END GPB_ACCESSORS()
178
179// Returns an empty NSData to assign to byte fields when you wish
180// to assign them to empty. Prevents allocating a lot of little [NSData data]
181// objects.
182NSData *GPBEmptyNSData(void) __attribute__((pure));
183
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400184NS_ASSUME_NONNULL_END
185
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400186CF_EXTERN_C_END
187
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400188
189//%PDDM-DEFINE GPB_ACCESSORS()
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400190//%
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400191//%//
192//%// Get/Set the given field of a message.
193//%//
194//%
195//%// Single Fields
196//%
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500197//%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
198//%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
199//%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
200//%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
201//%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
202//%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
203//%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
204//%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
205//%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
206//%GPB_ACCESSOR_SINGLE(Float, float, )
207//%GPB_ACCESSOR_SINGLE(Double, double, )
208//%/// Get the given enum field of a message. For proto3, if the value isn't a
209//%/// member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
210//%/// GPBGetMessageRawEnumField will bypass the check and return whatever value
211//%/// was set.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400212//%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500213//%/// Set the given enum field of a message. You can only set values that are
214//%/// members of the enum.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400215//%void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500216//%/// Get the given enum field of a message. No check is done to ensure the value
217//%/// was defined in the enum.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400218//%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500219//%/// Set the given enum field of a message. You can set the value to anything,
220//%/// even a value that is not a member of the enum.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400221//%void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
222//%
223//%// Repeated Fields
224//%
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500225//%/// Gets the value of a repeated field.
226//%///
227//%/// The result will be @c GPB*Array or @c NSMutableArray based on the
228//%/// field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400229//%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500230//%/// Sets the value of a repeated field.
231//%///
232//%/// The value should be @c GPB*Array or @c NSMutableArray based on the
233//%/// field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400234//%void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array);
235//%
236//%// Map Fields
237//%
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500238//%/// Gets the value of a map<> field.
239//%///
240//%/// The result will be @c GPB*Dictionary or @c NSMutableDictionary based on
241//%/// the field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400242//%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500243//%/// Sets the value of a map<> field.
244//%///
245//%/// The object should be @c GPB*Dictionary or @c NSMutableDictionary based
246//%/// on the field's type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400247//%void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary);
248//%
249
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500250//%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
251//%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
252//%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
253//%/// Gets the value of a##AN NAME$L field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400254//%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500255//%/// Sets the value of a##AN NAME$L field.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400256//%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
257//%