• Home
Name Date Size #Lines LOC

..--

DevTools/12-May-2024-1,8401,421

ProtocolBuffers_OSX.xcodeproj/12-May-2024-1,6251,604

ProtocolBuffers_iOS.xcodeproj/12-May-2024-1,6501,629

ProtocolBuffers_tvOS.xcodeproj/12-May-2024-1,6661,645

Tests/12-May-2024-45,47540,308

google/protobuf/12-May-2024-3010

.clang-formatD12-May-2024129 85

.gitignoreD12-May-2024284 2420

GPBAny.pbobjc.hD12-May-20245.6 KiB18437

GPBAny.pbobjc.mD12-May-20243.7 KiB11595

GPBApi.pbobjc.hD12-May-202410.5 KiB31289

GPBApi.pbobjc.mD12-May-202413.2 KiB373336

GPBArray.hD12-May-202459 KiB1,970227

GPBArray.mD12-May-202476.4 KiB2,5762,284

GPBArray_PackagePrivate.hD12-May-20243.5 KiB13356

GPBBootstrap.hD12-May-20245.8 KiB14741

GPBCodedInputStream.hD12-May-20247.5 KiB25449

GPBCodedInputStream.mD12-May-202415.9 KiB514438

GPBCodedInputStream_PackagePrivate.hD12-May-20245.1 KiB11357

GPBCodedOutputStream.hD12-May-202423.3 KiB758131

GPBCodedOutputStream.mD12-May-202441.1 KiB1,2491,083

GPBCodedOutputStream_PackagePrivate.hD12-May-20246.1 KiB12776

GPBDescriptor.hD12-May-202410.8 KiB31983

GPBDescriptor.mD12-May-202436.1 KiB1,1551,025

GPBDescriptor_PackagePrivate.hD12-May-202414.8 KiB375211

GPBDictionary.hD12-May-2024187.2 KiB5,773900

GPBDictionary.mD12-May-2024375.6 KiB12,15110,741

GPBDictionary_PackagePrivate.hD12-May-202414.9 KiB501332

GPBDuration.pbobjc.hD12-May-20244.6 KiB14637

GPBDuration.pbobjc.mD12-May-20243.5 KiB11090

GPBEmpty.pbobjc.hD12-May-20242 KiB7531

GPBEmpty.pbobjc.mD12-May-20242.6 KiB8666

GPBExtensionInternals.hD12-May-20242.4 KiB5115

GPBExtensionInternals.mD12-May-202415.8 KiB392371

GPBExtensionRegistry.hD12-May-20243.6 KiB8811

GPBExtensionRegistry.mD12-May-20245 KiB131114

GPBFieldMask.pbobjc.hD12-May-20247.9 KiB27436

GPBFieldMask.pbobjc.mD12-May-20243.1 KiB9979

GPBMessage.hD12-May-202417.9 KiB47167

GPBMessage.mD12-May-2024125.8 KiB3,3673,115

GPBMessage_PackagePrivate.hD12-May-20245.3 KiB12531

GPBProtocolBuffers.hD12-May-20243 KiB7740

GPBProtocolBuffers.mD12-May-20242.8 KiB6761

GPBProtocolBuffers_RuntimeSupport.hD12-May-20242 KiB416

GPBRootObject.hD12-May-20242.1 KiB537

GPBRootObject.mD12-May-20249.6 KiB246219

GPBRootObject_PackagePrivate.hD12-May-20242 KiB477

GPBRuntimeTypes.hD12-May-20245.1 KiB15251

GPBSourceContext.pbobjc.hD12-May-20242.1 KiB7835

GPBSourceContext.pbobjc.mD12-May-20243.2 KiB9979

GPBStruct.pbobjc.hD12-May-20246.1 KiB20584

GPBStruct.pbobjc.mD12-May-202410.5 KiB312273

GPBTimestamp.pbobjc.hD12-May-20245.9 KiB16837

GPBTimestamp.pbobjc.mD12-May-20243.5 KiB11090

GPBType.pbobjc.hD12-May-202413.5 KiB445171

GPBType.pbobjc.mD12-May-202425.7 KiB728665

GPBUnknownField.hD12-May-20243.3 KiB10021

GPBUnknownField.mD12-May-202411.2 KiB338300

GPBUnknownFieldSet.hD12-May-20242.9 KiB8311

GPBUnknownFieldSet.mD12-May-202412.7 KiB396352

GPBUnknownFieldSet_PackagePrivate.hD12-May-20242.4 KiB6219

GPBUnknownField_PackagePrivate.hD12-May-20242 KiB4810

GPBUtilities.hD12-May-202417.3 KiB55257

GPBUtilities.mD12-May-202487.3 KiB2,2902,089

GPBUtilities_PackagePrivate.hD12-May-202414.1 KiB363196

GPBWellKnownTypes.hD12-May-20248.9 KiB24657

GPBWellKnownTypes.mD12-May-20248.8 KiB273229

GPBWireFormat.hD12-May-20243 KiB7434

GPBWireFormat.mD12-May-20243.6 KiB8676

GPBWrappers.pbobjc.hD12-May-20244.7 KiB22091

GPBWrappers.pbobjc.mD12-May-202416 KiB458390

README.mdD12-May-20248.9 KiB198149

generate_well_known_types.shD12-May-20242.5 KiB9063

README.md

1Protocol Buffers - Google's data interchange format
2===================================================
3
4[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_cocoapods_integration.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_cocoapods_integration%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_ios_debug.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_ios_debug%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_ios_release.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_ios_release%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-objectivec_osx.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fobjectivec_osx%2Fcontinuous)
5
6Copyright 2008 Google Inc.
7
8This directory contains the Objective C Protocol Buffers runtime library.
9
10Requirements
11------------
12
13The Objective C implementation requires:
14
15- Objective C 2.0 Runtime (32bit & 64bit iOS, 64bit OS X).
16- Xcode 10.3 (or later).
17- The library code does *not* use ARC (for performance reasons), but it all can
18  be called from ARC code.
19
20Installation
21------------
22
23The distribution pulled from github includes the sources for both the
24compiler (protoc) and the runtime (this directory). After cloning the distribution
25and needed submodules ([see the src directory's README](../src/README.md)),
26to build the compiler and run the runtime tests, you can use:
27
28     $ objectivec/DevTools/full_mac_build.sh
29
30This will generate the `src/protoc` binary.
31
32Building
33--------
34
35There are two ways to include the Runtime sources in your project:
36
37Add `objectivec/*.h`, `objectivec/google/protobuf/*.pbobjc.h`, and
38`objectivec/GPBProtocolBuffers.m` to your project.
39
40*or*
41
42Add `objectivec/*.h`, `objectivec/google/protobuf/*.pbobjc.h`,
43`objectivec/google/protobuf/*.pbobjc.m`, and `objectivec/*.m` except for
44`objectivec/GPBProtocolBuffers.m` to your project.
45
46
47If the target is using ARC, remember to turn off ARC (`-fno-objc-arc`) for the
48`.m` files.
49
50The files generated by `protoc` for the `*.proto` files (`*.pbobjc.h` and
51`*.pbobjc.m`) are then also added to the target.
52
53Usage
54-----
55
56The objects generated for messages should work like any other Objective C
57object. They are mutable objects, but if you don't change them, they are safe
58to share between threads (similar to passing an NSMutableDictionary between
59threads/queues; as long as no one mutates it, things are fine).
60
61There are a few behaviors worth calling out:
62
63A property that is type NSString\* will never return nil. If the value is
64unset, it will return an empty string (@""). This is inpart to align things
65with the Protocol Buffers spec which says the default for strings is an empty
66string, but also so you can always safely pass them to isEqual:/compare:, etc.
67and have deterministic results.
68
69A property that is type NSData\* also won't return nil, it will return an empty
70data ([NSData data]). The reasoning is the same as for NSString not returning
71nil.
72
73A property that is another GPBMessage class also will not return nil. If the
74field wasn't already set, you will get a instance of the correct class. This
75instance will be a temporary instance unless you mutate it, at which point it
76will be attached to its parent object. We call this pattern *autocreators*.
77Similar to NSString and NSData properties it makes things a little safer when
78using them with isEqual:/etc.; but more importantly, this allows you to write
79code that uses Objective C's property dot notation to walk into nested objects
80and access and/or assign things without having to check that they are not nil
81and create them each step along the way. You can write this:
82
83```
84- (void)updateRecord:(MyMessage *)msg {
85  ...
86  // Note: You don't have to check subMessage and otherMessage for nil and
87  // alloc/init/assign them back along the way.
88  msg.subMessage.otherMessage.lastName = @"Smith";
89  ...
90}
91```
92
93If you want to check if a GPBMessage property is present, there is always as
94`has\[NAME\]` property to go with the main property to check if it is set.
95
96A property that is of an Array or Dictionary type also provides *autocreator*
97behavior and will never return nil. This provides all the same benefits you
98see for the message properties. Again, you can write:
99
100```
101- (void)updateRecord:(MyMessage *)msg {
102  ...
103  // Note: Just like above, you don't have to check subMessage and otherMessage
104  // for nil and alloc/init/assign them back along the way. You also don't have
105  // to create the siblingsArray, you can safely just append to it.
106  [msg.subMessage.otherMessage.siblingsArray addObject:@"Pat"];
107  ...
108}
109```
110
111If you are inspecting a message you got from some other place (server, disk,
112etc), you may want to check if the Array or Dictionary has entries without
113causing it to be created for you. For this, there is always a `\[NAME\]_Count`
114property also provided that can return zero or the real count, but won't trigger
115the creation.
116
117For primitive type fields (ints, floats, bools, enum) in messages defined in a
118`.proto` file that use *proto2* syntax there are conceptual differences between
119having an *explicit* and *default* value. You can always get the value of the
120property. In the case that it hasn't been set you will get the default. In
121cases where you need to know whether it was set explicitly or you are just
122getting the default, you can use the `has\[NAME\]` property. If the value has
123been set, and you want to clear it, you can set the `has\[NAME\]` to `NO`.
124*proto3* syntax messages do away with this concept, thus the default values are
125never included when the message is encoded.
126
127The Objective C classes/enums can be used from Swift code.
128
129Objective C Generator Proto File Options
130----------------------------------------
131
132**objc_class_prefix=\<prefix\>** (no default)
133
134Since Objective C uses a global namespace for all of its classes, there can
135be collisions. This option provides a prefix that will be added to the Enums
136and Objects (for messages) generated from the proto. Convention is to base
137the prefix on the package the proto is in.
138
139Objective C Generator `protoc` Options
140--------------------------------------
141
142When generating Objective C code, `protoc` supports a `--objc_opt` argument; the
143argument is comma-delimited name/value pairs (_key=value,key2=value2_). The
144_keys_ are used to change the behavior during generation. The currently
145supported keys are:
146
147  * `generate_for_named_framework`: The `value` used for this key will be used
148    when generating the `#import` statements in the generated code.  Instead
149    of being plain `#import "some/path/file.pbobjc.h"` lines, they will be
150    framework based, i.e. - `#import <VALUE/file.pbobjc.h>`.
151
152    _NOTE:_ If this is used with `named_framework_to_proto_path_mappings_path`,
153    then this is effectively the _default_ to use for everything that wasn't
154    mapped by the other.
155
156  * `named_framework_to_proto_path_mappings_path`: The `value` used for this key
157    is a path to a file containing the listing of framework names and proto
158    files. The generator uses this to decide if another proto file referenced
159    should use a framework style import vs. a user level import
160    (`#import <FRAMEWORK/file.pbobjc.h>` vs `#import "dir/file.pbobjc.h"`).
161
162    The format of the file is:
163      * An entry is a line of `frameworkName: file.proto, dir/file2.proto`.
164      * Comments start with `#`.
165      * A comment can go on a line after an entry.
166        (i.e. - `frameworkName: file.proto # comment`)
167
168    Any number of files can be listed for a framework, just separate them with
169    commas.
170
171    There can be multiple lines listing the same frameworkName incase it has a
172    lot of proto files included in it; and having multiple lines makes things
173    easier to read.
174
175  * `runtime_import_prefix`: The `value` used for this key to be used as a
176    prefix on `#import`s of runtime provided headers in the generated files.
177    When integrating ObjC protos into a build system, this can be used to avoid
178    having to add the runtime directory to the header search path since the
179    generate `#import` will be more complete.
180
181Contributing
182------------
183
184Please make updates to the tests along with changes. If just changing the
185runtime, the Xcode projects can be used to build and run tests. If your change
186also requires changes to the generated code,
187`objectivec/DevTools/full_mac_build.sh` can be used to easily rebuild and test
188changes. Passing `-h` to the script will show the addition options that could
189be useful.
190
191Documentation
192-------------
193
194The complete documentation for Protocol Buffers is available via the
195web at:
196
197    https://developers.google.com/protocol-buffers/
198