Google protocol buffers on iOS

后端 未结 4 1932
情书的邮戳
情书的邮戳 2020-12-07 17:23

Is the metasyntactic static library for iOS . . .

http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers

. . . compatible with regular old C++ compiled

4条回答
  •  甜味超标
    2020-12-07 17:29

    I guess based on the actual question my comment is worth posting as an answer:

    I'm using a slightly modified version of the native Obj code generation provided by Booyah

    It supports repeated fields out of the box but in order to use ObjC fast enumeration you need to convert the PBArray type (basically a typed c buffer) to an array of NSObjects that it represents - either the NSNumber or protobuf message of the objects. You can see an example of the updated fast enumeration code in this change: . You could also add a category for that on PBArray called toObjects.

    I just mark the generated code with -fno-objc-arc, but you can get arc and 2.5 support from the booyah pull requests.

    The directions are pretty good for setup, but if people want more explicit instructions on the category I use, how I built the protobuf-objc plugin, how to get support for Class prefixes (e.g. IXMyProtoMessage instead of MyProtoMessage) or how I generate the code let me know and I'll try to set aside time to write up a post. I'm using it with > 50 proto files with a lot of cross project dependencies.

    A weakness of the library is that it doesn't include the typical Protobuf reflection api on the generated code so doing something like converting a message to a NSDictionary would have to do some hacky stuff with the objC runtime (the code doesn't follow typical KV compliance) or write a custom code generator from protos that do have the reflection api (I did this with python + jinja2). Or - better yet and of similar difficulty, add reflection apis to the code generator ;).

提交回复
热议问题