android - Protocol Buffer 支持 byte[] 字段吗?

标签 android arrays protocol-buffers

我正在尝试更新 Android BluetoothChat 示例的代码以使用 Protobuf 进行更结构化的数据交换。我还需要 byte[] 数组字段来发送任意数据,例如图像字节数组,但在尝试编译 .proto 文件时,出现以下错误。

protofiles/bluetoothmessage.proto:8:18:预期的字段名称。

下面是我的 .proto 文件。

package bluetoothmessage;

option java_package = "com.example.bluetoothexample";
option java_outer_classname = "ProtocolBuffers";

message BTMessage {
    required int32 cmd = 1;
    optional byte[] appData = 2;
}

stackoverflow 上的其他几篇文章提到 byte[] 可以用作字段,下面的页面也说了同样的事情。

https://developers.google.com/protocol-buffers/docs/proto#scalar

非常感谢任何帮助!谢谢!!

最佳答案

来自manual : bytes 可以包含任意任意字节序列。

行:

optional byte[] appData = 2;

必须更改为:

optional bytes appData = 2;

关于android - Protocol Buffer 支持 byte[] 字段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24898261/

相关文章:

java - 使用 Java 在普通 TCP 客户端和 Netty 服务器之间交换 Protobuf 消息

c++ - 对 google::protobuf::internal::empty_string_[abi:cxx11] 的 undefined reference

android - 游标与 CursorLoader

android - 如何在 Mac Eclipse-SDK 上从 Android AVD 切换到真实硬件?

android - AutoLayout对处理iOS屏幕大小的 fragment 有用吗?为什么Android中没有等效的工具?

c++ - SPOJ : GENERAL (Time limit exceeded)

arrays - 如何找到列表中1的最长间隔[matlab]

Android-Studio ActionBar sherlock 错误与 gradle

c - 指针对齐问题的原因是什么?

java - Google Protocol Buffer,在 Windows 上快,在 Ubuntu 上慢