简体   繁体   English

Google protobuf 可以用于android 中C 和Java 服务之间的通信吗?

[英]Can Google protobuf be used for communication between C and Java services in android?

We have a legacy protocol stack written in C with c-protobuf interface and C++ wrapper API that need to be ported to Android and develop java service with AIDL interfaces.我们有一个用 C 编写的遗留协议栈,带有 c-protobuf 接口和 C++ 包装器 API,需要移植到 Android 并开发带有 AIDL 接口的 java 服务。 So here are the questions,那么问题来了

  1. Can we remove C++ interface and have Java service talking to C- native process over protobuf?我们可以删除 C++ 接口并让 Java 服务通过 protobuf 与 C-native 进程通信吗?

  2. Another approach is to strip c-protobuf interface and develop JNI interface.另一种做法是剥离c-protobuf接口,开发JNI接口。 What is the trade off between protobuf vs JNI approach? protobuf 与 JNI 方法之间的权衡是什么?

  3. As far I know performance will be an issue due to IPC, serialization etc compared to JNI approach.据我所知,与 JNI 方法相比,由于 IPC、序列化等,性能将成为一个问题。 Is there any other major drawback with this approach considering Java and Android context?考虑到 Java 和 Android 上下文,这种方法还有其他主要缺点吗? Also, this service is going to be used by multiple user applications.此外,该服务将由多个用户应用程序使用。

  1. Sure that should work.当然这应该有效。

  2. As @pskink already pointed out, JNI will cause smaller overhead.正如@pskink 已经指出的那样,JNI 将导致较小的开销。 Especially in case of large number of calls with small arguments.特别是在大量调用小参数的情况下。 As a bonus you can actually choose to pass serialized protocol buffer in form of byte array.作为奖励,您实际上可以选择以字节数组的形式传递序列化的协议缓冲区。 I would expect the overhead of that to be quite small and it can make further modifications of the interface easier.我希望它的开销非常小,并且可以更轻松地进一步修改界面。

  3. Depending on how you plan to pack everything together the JNI interface might be easier to maintain compatible as everything is build into a single APK.根据您计划如何将所有内容打包在一起,JNI 接口可能更容易保持兼容,因为所有内容都构建到单个 APK 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM