Adam Cozzette 72fddb7272 Fixed the Codespell check hace 4 años
..
DevTools 676ea98902 Update the build/testing script for Xcode 12. hace 5 años
ProtocolBuffers_OSX.xcodeproj 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años
ProtocolBuffers_iOS.xcodeproj a645d7176b Update the iOS project for Xcode 12. hace 5 años
ProtocolBuffers_tvOS.xcodeproj 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años
Tests 2f6a7546e4 Update the pod tests to match the new min iOS version. hace 4 años
google 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años
.clang-format ab48ecf140 Update pddm to work with clang-format hace 5 años
.gitignore daec44fa52 Expand the OS X/Xcode gitignores hace 9 años
BUILD 8b93b8eae5 [bazel] Move Objective-C runtime into //objectivec hace 5 años
GPBAny.pbobjc.h 25755efc4f Sync from Piper @319848517 hace 5 años
GPBAny.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBApi.pbobjc.h e2cc2de304 Fix lots of spelling errors (#7751) hace 5 años
GPBApi.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBArray.h ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBArray.m ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBArray_PackagePrivate.h ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBBootstrap.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBCodedInputStream.h d58b92ae51 Adds pushLimit: and popLimit: into GPBCodedInputStream (#2297) hace 9 años
GPBCodedInputStream.m 668eb3b4e6 Fix decoding of overencoded booleans. hace 5 años
GPBCodedInputStream_PackagePrivate.h a721bf6d29 Migrate away from deprecated OSAtomic APIs. (#4184) hace 7 años
GPBCodedOutputStream.h ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBCodedOutputStream.m ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBCodedOutputStream_PackagePrivate.h 36650a07cf HeaderDoc support in the library and generated sources hace 9 años
GPBDescriptor.h 1c95097dd3 ObjC: avoid assign for object properties (part 2) hace 6 años
GPBDescriptor.m dddeed298b [ObjC] Typos and comment improvements. hace 5 años
GPBDescriptor_PackagePrivate.h 2360bacd12 Tweak the union used for Extensions to support old generated code. hace 5 años
GPBDictionary.h ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBDictionary.m ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBDictionary_PackagePrivate.h ab48ecf140 Update pddm to work with clang-format hace 5 años
GPBDuration.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBDuration.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBEmpty.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBEmpty.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBExtensionInternals.h d846b0b059 Beta quality drop of Objective C Support. hace 10 años
GPBExtensionInternals.m e2cc2de304 Fix lots of spelling errors (#7751) hace 5 años
GPBExtensionRegistry.h a2484208c3 Fixes extra whitespace on generated comments. (#1950) hace 9 años
GPBExtensionRegistry.m 49e4ba6098 Fix ExtensionRegistry copying and add tests. hace 8 años
GPBFieldMask.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBFieldMask.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBMessage.h 5939bc3619 Fix "the the". hace 6 años
GPBMessage.m 72fddb7272 Fixed the Codespell check hace 4 años
GPBMessage_PackagePrivate.h cf016a42e6 Work around strange error with atomic and swift under Xcode 8.3.3. hace 7 años
GPBProtocolBuffers.h 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años
GPBProtocolBuffers.m 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años
GPBProtocolBuffers_RuntimeSupport.h bca797dac9 Trim imports for bundled generated protos. hace 7 años
GPBRootObject.h 32fadc0d49 Migrating documentation of the ObjectiveC runtime code to appledoc. (#1867) hace 9 años
GPBRootObject.m 37a6672c31 Remove unreferenced 'GPBMessageSignatureProtocol' class. hace 7 años
GPBRootObject_PackagePrivate.h d846b0b059 Beta quality drop of Objective C Support. hace 10 años
GPBRuntimeTypes.h aa1d7e7c48 Change Objective C class references to using macros. hace 5 años
GPBSourceContext.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBSourceContext.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBStruct.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBStruct.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBTimestamp.pbobjc.h 95e6c5b474 Sync from Piper @327110949 hace 5 años
GPBTimestamp.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBType.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBType.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBUnknownField.h b30dee3ea6 Expose the initializer for unknown fields. hace 8 años
GPBUnknownField.m 3389bd965b Add header need for module maps. hace 7 años
GPBUnknownFieldSet.h 32fadc0d49 Migrating documentation of the ObjectiveC runtime code to appledoc. (#1867) hace 9 años
GPBUnknownFieldSet.m 5904279ebd Remove the custom key functions and just use the system provided defaults. hace 9 años
GPBUnknownFieldSet_PackagePrivate.h 30650d81d9 Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. hace 10 años
GPBUnknownField_PackagePrivate.h b30dee3ea6 Expose the initializer for unknown fields. hace 8 años
GPBUtilities.h dddeed298b [ObjC] Typos and comment improvements. hace 5 años
GPBUtilities.m 2123ed5df7 Switch to atomic for setting autocreated objects. hace 4 años
GPBUtilities_PackagePrivate.h 2123ed5df7 Switch to atomic for setting autocreated objects. hace 4 años
GPBWellKnownTypes.h 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años
GPBWellKnownTypes.m d0bc096b4a Timestamp helper fix, Duration helper cleanup. hace 8 años
GPBWireFormat.h c18aa7795a Validate the tag numbers when parsing. (#1725) hace 9 años
GPBWireFormat.m c18aa7795a Validate the tag numbers when parsing. (#1725) hace 9 años
GPBWrappers.pbobjc.h b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
GPBWrappers.pbobjc.m b0e2792842 [ObjC] Generation changes around proto3 optional. hace 5 años
README.md e2cc2de304 Fix lots of spelling errors (#7751) hace 5 años
generate_well_known_types.sh 56c48ae592 Revisit how the WKTs are bundled with ObjC. hace 5 años

README.md

Protocol Buffers - Google's data interchange format

Build status Build status Build status Build status

Copyright 2008 Google Inc.

This directory contains the Objective C Protocol Buffers runtime library.

Requirements

The Objective C implementation requires:

  • Objective C 2.0 Runtime (32bit & 64bit iOS, 64bit OS X).
  • Xcode 10.3 (or later).
  • The library code does not use ARC (for performance reasons), but it all can be called from ARC code.

Installation

The distribution pulled from github includes the sources for both the compiler (protoc) and the runtime (this directory). After cloning the distribution and needed submodules (see the src directory's README), to build the compiler and run the runtime tests, you can use:

 $ objectivec/DevTools/full_mac_build.sh

This will generate the src/protoc binary.

Building

There are two ways to include the Runtime sources in your project:

Add objectivec/*.h, objectivec/google/protobuf/*.pbobjc.h, and objectivec/GPBProtocolBuffers.m to your project.

or

Add objectivec/*.h, objectivec/google/protobuf/*.pbobjc.h, objectivec/google/protobuf/*.pbobjc.m, and objectivec/*.m except for objectivec/GPBProtocolBuffers.m to your project.

If the target is using ARC, remember to turn off ARC (-fno-objc-arc) for the .m files.

The files generated by protoc for the *.proto files (*.pbobjc.h and *.pbobjc.m) are then also added to the target.

Usage

The objects generated for messages should work like any other Objective C object. They are mutable objects, but if you don't change them, they are safe to share between threads (similar to passing an NSMutableDictionary between threads/queues; as long as no one mutates it, things are fine).

There are a few behaviors worth calling out:

A property that is type NSString* will never return nil. If the value is unset, it will return an empty string (@""). This is inpart to align things with the Protocol Buffers spec which says the default for strings is an empty string, but also so you can always safely pass them to isEqual:/compare:, etc. and have deterministic results.

A property that is type NSData* also won't return nil, it will return an empty data ([NSData data]). The reasoning is the same as for NSString not returning nil.

A property that is another GPBMessage class also will not return nil. If the field wasn't already set, you will get a instance of the correct class. This instance will be a temporary instance unless you mutate it, at which point it will be attached to its parent object. We call this pattern autocreators. Similar to NSString and NSData properties it makes things a little safer when using them with isEqual:/etc.; but more importantly, this allows you to write code that uses Objective C's property dot notation to walk into nested objects and access and/or assign things without having to check that they are not nil and create them each step along the way. You can write this:

- (void)updateRecord:(MyMessage *)msg {
  ...
  // Note: You don't have to check subMessage and otherMessage for nil and
  // alloc/init/assign them back along the way.
  msg.subMessage.otherMessage.lastName = @"Smith";
  ...
}

If you want to check if a GPBMessage property is present, there is always as has\[NAME\] property to go with the main property to check if it is set.

A property that is of an Array or Dictionary type also provides autocreator behavior and will never return nil. This provides all the same benefits you see for the message properties. Again, you can write:

- (void)updateRecord:(MyMessage *)msg {
  ...
  // Note: Just like above, you don't have to check subMessage and otherMessage
  // for nil and alloc/init/assign them back along the way. You also don't have
  // to create the siblingsArray, you can safely just append to it.
  [msg.subMessage.otherMessage.siblingsArray addObject:@"Pat"];
  ...
}

If you are inspecting a message you got from some other place (server, disk, etc), you may want to check if the Array or Dictionary has entries without causing it to be created for you. For this, there is always a \[NAME\]_Count property also provided that can return zero or the real count, but won't trigger the creation.

For primitive type fields (ints, floats, bools, enum) in messages defined in a .proto file that use proto2 syntax there are conceptual differences between having an explicit and default value. You can always get the value of the property. In the case that it hasn't been set you will get the default. In cases where you need to know whether it was set explicitly or you are just getting the default, you can use the has\[NAME\] property. If the value has been set, and you want to clear it, you can set the has\[NAME\] to NO. proto3 syntax messages do away with this concept, thus the default values are never included when the message is encoded.

The Objective C classes/enums can be used from Swift code.

Objective C Generator Proto File Options

objc_class_prefix=<prefix> (no default)

Since Objective C uses a global namespace for all of its classes, there can be collisions. This option provides a prefix that will be added to the Enums and Objects (for messages) generated from the proto. Convention is to base the prefix on the package the proto is in.

Objective C Generator protoc Options

When generating Objective C code, protoc supports a --objc_opt argument; the argument is comma-delimited name/value pairs (key=value,key2=value2). The keys are used to change the behavior during generation. The currently supported keys are:

  • generate_for_named_framework: The value used for this key will be used when generating the #import statements in the generated code. Instead of being plain #import "some/path/file.pbobjc.h" lines, they will be framework based, i.e. - #import <VALUE/file.pbobjc.h>.

    NOTE: If this is used with named_framework_to_proto_path_mappings_path, then this is effectively the default to use for everything that wasn't mapped by the other.

  • named_framework_to_proto_path_mappings_path: The value used for this key is a path to a file containing the listing of framework names and proto files. The generator uses this to decide if another proto file referenced should use a framework style import vs. a user level import (#import <FRAMEWORK/file.pbobjc.h> vs #import "dir/file.pbobjc.h").

    The format of the file is:

    • An entry is a line of frameworkName: file.proto, dir/file2.proto.
    • Comments start with #.
    • A comment can go on a line after an entry. (i.e. - frameworkName: file.proto # comment)

    Any number of files can be listed for a framework, just separate them with commas.

    There can be multiple lines listing the same frameworkName in case it has a lot of proto files included in it; and having multiple lines makes things easier to read.

  • runtime_import_prefix: The value used for this key to be used as a prefix on #imports of runtime provided headers in the generated files. When integrating ObjC protos into a build system, this can be used to avoid having to add the runtime directory to the header search path since the generate #import will be more complete.

Contributing

Please make updates to the tests along with changes. If just changing the runtime, the Xcode projects can be used to build and run tests. If your change also requires changes to the generated code, objectivec/DevTools/full_mac_build.sh can be used to easily rebuild and test changes. Passing -h to the script will show the addition options that could be useful.

Documentation

The complete documentation for Protocol Buffers is available via the web at:

https://developers.google.com/protocol-buffers/