libprotobuf ERROR google/protobuf/wire_format.cc:1059
来源:互联网 发布:如何用阿里云搭建网站 编辑:程序博客网 时间:2024/05/24 03:27
http://blog.csdn.net/jisuanji2121/article/details/9833463
使用google::protobuf进行序列化,在运行时有如下警告!
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
原因:要求所有的string类型都必须为UTF-8类型的,可以使用<iconv.h> 进行格式转化。
介绍一下字符集相关知识:
在技术编码方面上,演化顺序为:ASCII ⇒ GB2312 ⇒ GBK ⇒ GB18030
先面贴一段转化的代码:
- include <string>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- #include <iconv.h>
- bool convertGbk2Utf(string& instr, string& outstr)
- {
- iconv_t gbk2UtfDescriptor;
- gbk2UtfDescriptor = iconv_open("UTF-8", "GBK");
- size_t inlen = instr.length();
- char* in = const_cast<char*>(instr.c_str());
- size_t outlen = inlen * 2 + 1; // inlen * 1.5 + 1 >= outlen >= inlen + 1
- char* outbuf = (char*)::malloc(outlen);
- char* out = outbuf;
- memset(outbuf, 0x0, outlen);
- if((size_t)-1 == iconv(gbk2UtfDescriptor, &in, &inlen, &out, &outlen))
- {
- ::free(outbuf);
- return false;
- }
- outstr.clear();
- outstr.append(outbuf);
- ::free(outbuf);
- return true;
- }
- int main()
- {
- string str = "黄";
- convertGbk2Utf(str,str);
- cout << str << endl;
- }
0 0
- libprotobuf ERROR google/protobuf/wire_format.cc:1059
- libprotobuf ERROR google/protobuf/wire_format.cc:1059
- 编译时protobuf报错的问题(error with libprotobuf.so.8)
- error :No module named google.protobuf.internal
- protobuf-cpp-3.2.0编译Windows的libprotobuf.lib
- 使用-fPIC选项编译出protobuf静态库libprotobuf.a
- iOS中ProtocolBuffer2.2的安装及google/protobuf/message.cc:130:60错误解决办法
- google protobuf
- Google ProtoBuf
- protobuf (GOOGLE)
- google protobuf
- google protobuf
- 【google protobuf】
- google protobuf
- Google protobuf
- Google protoBuf
- Google Protobuf
- Google protobuf
- 新建单据,放大镜过滤的添加。
- (013):LINQ查询语法与方法语法
- C/C++中取消宏定义
- 控制台启动WCF服务的配置
- Windows系统下搭建MPI环境
- libprotobuf ERROR google/protobuf/wire_format.cc:1059
- php-5.4.22 编译
- 经典开源项目介绍(游戏、游戏引擎、通用组件)
- Android设置多个定时器时只有最后一个定时器有效的问题
- java-乱七八糟
- OpenLDAP Master/Slave部署
- phpQuery乱码解决经验分享
- 何时释放Image
- (014):LINQ to SQL简介