xcode 在 Objective-C 中使用 Protocol Buffers

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1601656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:54:50  来源:igfitidea点击:

Using Protocol Buffers with Objective-C

objective-cxcodeprotocol-buffers

提问by Richard Stelling

Has anyone used Google's Protocol Bufferswhen developing applications in Objective-C?

有没有人在 Objective-C 中开发应用程序时使用过Google 的 Protocol Buffers

Are there any current projects for compiling .protofiles into Objective-C, all the Google docs simply refer to Java, C++ or Python.

当前是否有任何将.proto文件编译为 Objective-C 的项目,所有的 Google 文档都只是指 Java、C++ 或 Python。

回答by Jon Parise

I've been working on an fork of Cyrus' project. It's based on protobuf 2.3 and works as a protocplugin (protoc-gen-objc) instead of requiring a modified protobuf distribution.

我一直在研究 Cyrus 项目的一个分支。它基于 protobuf 2.3 并作为protoc插件 ( protoc-gen-objc) 工作,而不需要修改 protobuf 发行版。

You can find it as the protobuf-objproject on GitHub.

你可以在 GitHub 上找到它作为protobuf-obj项目。

回答by Jon Skeet

The Third Partypage lists this Objective-C port. Unfortunately the project appears to be empty at the moment, but it's encouraging to see it anyway. I had heard internal rumours of the project, but hadn't seen it as an open source project before today.

第三方网页列出了这个Objective-C的端口。不幸的是,该项目目前似乎是空的,但无论如何看到它还是令人鼓舞的。我听说过这个项目的内部传闻,但在今天之前并没有将它视为一个开源项目。

You could get in touch with the project owner (Cyrus Najmabadi) to ask about it though...

您可以与项目所有者 (Cyrus Najmabadi) 取得联系,询问有关它的问题...

(Small piece of trivia - Cyrus used to work on the C# team in Microsoft before he joined Google.)

(小知识 - Cyrus 在加入 Google 之前曾在 Microsoft 的 C# 团队工作。)

回答by JasonSmith

This may or may not be helpful, but Apache Thrift(originally developed at Facebook) supports Cocoa, and seems to have people attempting to use it in the iPhone.

这可能有帮助,也可能没有帮助,但Apache Thrift(最初由 Facebook 开发)支持 Cocoa,并且似乎有人试图在 iPhone 中使用它。

Thrift officially supports more languages. But Protocol Buffers have 5x the Stack Overflow interest, so who knows if it's a good replacement in terms of maintenance—not to mention compatibility with your own project! Still, maybe it's worth consideration.

Thrift 正式支持更多语言。但是 Protocol Buffers 对 Stack Overflow 的兴趣是 Stack Overflow 的 5 倍,所以谁知道它在维护方面是否是一个很好的替代品——更不用说与您自己的项目的兼容性了!不过,也许值得考虑。

I just asked a related question you may find helpful if it gets good answers: Any success using Apache Thrift on iPhone?

我刚刚问了一个相关问题,如果得到好的答案,您可能会觉得有帮助:在 iPhone 上使用 Apache Thrift 是否成功?

回答by Graham Miln

Protocol Buffers v3 supports Objective-C

Protocol Buffers v3 支持 Objective-C

Protocol Buffers v3 supports Objective-Cas a first class language.

Protocol Buffers v3支持 Objective-C作为第一类语言。

To generate Objective-C code from a .protofile call the compiler with the objc_outoption:

要从文件中生成 Objective-C 代码,.proto请使用以下objc_out选项调用编译器:

 protoc --proto_path=src --objc_out=build/gen src/foo.proto src/bar/baz.proto 

回答by JARC

I prefer to use c++ generated classes within my objc projects, works just fine.

我更喜欢在我的 objc 项目中使用 C++ 生成的类,效果很好。

I did try the objc PB version but without success.

我确实尝试过 objc PB 版本但没有成功。