protobuf中c++生成的string可以在java中来parse吗?

Mr_print 2016-07-19 08:12:06
如题

我是在android中用jni回调,jni中收到的string是用c++的SerializeAsString()输出的,
在jni中我将string转为byte[]数组,回调到java中,通过java的parseFrom来解析。

现在在java端报的错误是
com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length.

但是同样的string,我在jni中用c++的ParseFromString是可以解析成功的。

proto是同一个文件,分别生成了c++和java两个版本。

用过protobuf的各路大神,请问这是什么问题??谢谢了
...全文
703 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mr_print 2016-10-10
  • 打赏
  • 举报
回复
给大家一个参与分,哈哈
Mr_print 2016-10-10
  • 打赏
  • 举报
回复
引用 4 楼 longzhenwen 的回复:
怎么解决的???
我怀疑是我的数据格式出了问题,但是没找到为什么 所以,我在jni层用c++的proto解析了一遍,然后再序列化一遍就可以了 entity.ParseFromString(msg); const std::string jss = entity.SerializeAsString();
赵4老师 2016-09-22
  • 打赏
  • 举报
回复
帮结帖+蹭分
龙战风云 2016-09-22
  • 打赏
  • 举报
回复
怎么解决的???
ztenv 版主 2016-07-21
  • 打赏
  • 举报
回复
解决了就行,
Mr_print 2016-07-19
  • 打赏
  • 举报
回复
解决了,可以的。之前看错了。
Mr_print 2016-07-19
  • 打赏
  • 举报
回复
补充,我使用的是protobuf-lite 3.0

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧