0
我想在Windows平臺上序列化我的協議緩衝區消息,我的編碼語言是C++。序列化完成後,它返回「false」。請找到下面的代碼,並讓我知道我要去哪裏錯了。protobuf serializetocodedstream返回「false」
原型文件
message mobile_list{
required string name = 1;
required DeviceType type = 2;
required string imei = 3;
required bytes wifiAddress = 4;
optional bytes macAddress = 5;
}
#include <unistd.h>
#include "mobile.pb.h"
#include <iostream>
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
using namespace google::protobuf::io;
using namespace std;
int main(int argv, char** argc){
mobile payload;
payload.set_name("Testing");
payload.set_type(mobile::Android);
payload.set_imei("123456");
payload.set_wifiAddress("96-00-OM-1E-4R-99");
payload.set_macAddress("96-00-OM-1E-4R-99");
int siz = payload.ByteSize();
char *pkt = new char [siz];
google::protobuf::io::ArrayOutputStream as(pkt,siz);
CodedOutputStream *coded_output = new CodedOutputStream(&as);
coded_output->WriteVarint32(payload.ByteSize());
payload.SerializeToCodedStream(coded_output);
return a.exec();
}