# Project **Repository Path**: playwowo/Project ## Basic Information - **Project Name**: Project - **Description**: 项目简介 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2014-06-18 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #Project cocos2d-x-3.1rc0 java-jdk1.6 protobuf 2.4.1 #准备 1.http://code.google.com/p/protobuf/downloads/list ,选择其中的win版本下载 2.下载一个protobuf-java-2.4.1.jar文件(注意,要与你刚才下的proto.exe版本相同,否则可能出现编译通不过现象) http://grepcode.com/snapshot/repo1.maven.org/maven2/com.google.protobuf/protobuf-java/2.4.1 #JAVA 生成 3.在proto.exe同级目录,编写一个msg.proto文件: 书写protobuf文件 Java代码 package tutorial; message ShopBuyMsg { optional int32 good_id = 1; optional int32 count = 2; optional int32 receive_id = 3; optional int32 result = 4; } 在proto.exe同级目录中用cmd java 命令行,生成java文件 protoc --java_out =F:\protoc-2.4.1-win32 ShopBuy.proto 4.在java 工程中导入protobuf-java-2.4.1.jar #C++ 生成 1.打开源码,并且编译lib库 目录 protobuf-2.4.1 vsprojects protobuf.sln vs 运行 生成 libprotobuf.lib 2.把生成的动态库拷贝到 c++项目的工程目录(cocos2d-x Debug.win32下),并且配置好链接库 3.在proto.exe同级目录 cmd命令行,生成c++ protobuf文件 protoc --cpp_out =F:\protoc-2.4.1-win32 ShopBuy.proto 生成了 ShopBuy.pb.h 和 ShopBuy.pb.cc 文件 4. c++项目中引入 protobuf头文件,并配置c++ 配置目录 目录 protobuf-2.4.1 src 5.在引用的文件中引入头文件 #include "ShopBuy.pb.h" 6.应用 tutorial::ShopBuyMsg shopMsg ; shopMsg.set_good_id(123); shopMsg.set_count(2); shopMsg.set_receive_id(1); shopMsg.set_result(1); std::string str = shopMsg.SerializeAsString(); const char* protoMsg = str.c_str() ; //下面为tcp 发送数据 stream.writeUTF(protoMsg); write(stream);