google/protobuf hello world
2016-08-06 07:56
375 查看
/(ㄒoㄒ)/~~官网被墙
1.github>Search>protobuforprotocolbuffers
2.https://github.com/google/protobuf
3.releases
4.protoc-3.0.0-alpha-2-win32.zip
readme.txt
1.github>Search>protobuforprotocolbuffers
2.https://github.com/google/protobuf
3.releases
4.
readme.txt
ProtocolBuffers-Google'sdatainterchangeformat Copyright2008GoogleInc.https://developers.google.com/protocol-buffers/ ThispackagecontainsaprecompiledWin32binaryversionoftheprotocolbuffer compiler(protoc).ThisbinaryisintendedforWindowsuserswhowantto useProtocolBuffersinJavaorPythonbutdonotwanttocompileprotoc themselves.Toinstall,simplyplacethisbinarysomewhereinyourPATH. ThisbinarywasbuiltusingMinGW,buttheoutputisthesameregardlessof theC++compilerused. Youwillstillneedtodownloadthesourcecodepackageinordertoobtainthe JavaorPythonruntimelibraries.Getitfrom: 'target='_blank'>https://github.com/google/protobuf/releases/[/code]
将protoc.exe放至C:\WINDOWS\system32
cmd
protoc--versionlibprotoc3.0.0
protoc-hUsage:protoc[OPTION]PROTO_FILES ParsePROTO_FILESandgenerateoutputbasedontheoptionsgiven: -IPATH,--proto_path=PATHSpecifythedirectoryinwhichtosearchfor imports.Maybespecifiedmultipletimes; directorieswillbesearchedinorder.Ifnot given,thecurrentworkingdirectoryisused. --versionShowversioninfoandexit. -h,--helpShowthistextandexit. --encode=MESSAGE_TYPEReadatext-formatmessageofthegiventype fromstandardinputandwriteitinbinary tostandardoutput.Themessagetypemust bedefinedinPROTO_FILESortheirimports. --decode=MESSAGE_TYPEReadabinarymessageofthegiventypefrom standardinputandwriteitintextformat tostandardoutput.Themessagetypemust bedefinedinPROTO_FILESortheirimports. --decode_rawReadanarbitraryprotocolmessagefrom standardinputandwritetherawtag/value pairsintextformattostandardoutput.No PROTO_FILESshouldbegivenwhenusingthis flag. -oFILE,WritesaFileDescriptorSet(aprotocolbuffer, --descriptor_set_out=FILEdefinedindescriptor.proto)containingallof theinputfilestoFILE. --include_importsWhenusing--descriptor_set_out,alsoinclude alldependenciesoftheinputfilesinthe set,sothatthesetisself-contained. --include_source_infoWhenusing--descriptor_set_out,donotstrip SourceCodeInfofromtheFileDescriptorProto. Thisresultsinvastlylargerdescriptorsthat includeinformationabouttheoriginal locationofeachdeclinthesourcefileas wellassurroundingcomments. --error_format=FORMATSettheformatinwhichtoprinterrors. FORMATmaybe'gcc'(thedefault)or'msvs' (MicrosoftVisualStudioformat). --print_free_field_numbersPrintthefreefieldnumbersofthemessages definedinthegivenprotofiles.Groupsshare thesamefieldnumberspacewiththeparent message.Extensionrangesarecountedas occupiedfieldsnumbers. --plugin=EXECUTABLESpecifiesapluginexecutabletouse. Normally,protocsearchesthePATHfor plugins,butyoumayspecifyadditional executablesnotinthepathusingthisflag. Additionally,EXECUTABLEmaybeoftheform NAME=PATH,inwhichcasethegivenpluginname ismappedtothegivenexecutableevenif theexecutable'sownnamediffers. --cpp_out=OUT_DIRGenerateC++headerandsource. --java_out=OUT_DIRGenerateJavasourcefile. --javanano_out=OUT_DIRGenerateJavaNanosourcefile. --python_out=OUT_DIRGeneratePythonsourcefile. --ruby_out=OUT_DIRGenerateRubysourcefile.
protoc--java_out=.addressbook.proto[libprotobufWARNINGgoogle/protobuf/compiler/parser.cc:471]Nosyntaxspecifiedfortheprotofile.Pleaseuse'syntax ="proto2";'or'syntax="proto3";'tospecifyasyntaxversion.(Defaultedtoproto2syntax.)
遭遇以上问题时,请确保protofile中已指定syntax,然后重试。
具体查看https://github.com/google/protobuf/blob/master/CHANGES.txt Anewnotion"syntax"isintroducedtospecifywhethera.protofile usesproto2orproto3: //foo.proto syntax="proto3"; messageBar{...}
5.消息模板文件位置
clonehttps://github.com/google/protobuf.git
文件位于\protobuf\examples
6.maven依赖<repositories> <repository> <id>oschina</id> <url>http://maven.oschina.net/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.0.0-alpha-2</version> </dependency> </dependencies>
7.完整示例
helptree
tree/FE:. └─hello-protocol │ADDRESS_BOOK_FILE │pom.xml │ └─src └─main └─java └─cn └─zxg AddPerson.java AddressBookProtos.java ListPeople.java
执行AddPerson参数为ADDRESS_BOOK_FILE结果:ADDRESS_BOOK_FILE:Filenotfound.Creatinganewfile. EnterpersonID:7 Entername:James Enteremailaddress(blankfornone):7@7.com Enteraphonenumber(orleaveblanktofinish):911 Isthisamobile,home,orworkphone?work Enteraphonenumber(orleaveblanktofinish):
执行ListPerson参数为ADDRESS_BOOK_FILE结果:PersonID:7 Name:James E-mailaddress:7@7.com Workphone#:911
相关文章推荐
- google ProtoBuf 开发者指南
- google protobuf源码分析1
- RabbitMQ消息队列的小伙伴: ProtoBuf(Google Protocol Buffer) [转]
- Quick-Cocos2d-x 集成 Google protobuf 方法
- RabbitMQ消息队列的小伙伴: ProtoBuf(Google Protocol Buffer)
- ImportError: No module named google.protobuf
- Google 新实现的Protobuf RPC: grpc
- ubuntu16.04下编译caffe出现.build_release/lib/libcaffe.so: undefined reference to google ::protobuf...的问题
- google ProtoBuf开发者指南
- Protobuf(Google Protocol Buffer)编码学习笔记
- RabbitMQ消息队列的小伙伴: ProtoBuf(Google Protocol Buffer)(转)
- google protobuf的编译成jar包
- [转]Google 的开源技术protobuf 简介与例子
- ImportError: No module named google.protobuf.internal
- C#下使用protobuf(Google Protocol Buffers)
- Google 的开源技术protobuf 简介与例子[转]
- google_protobuf数据类型
- google protobuf 使用过程笔记
- java google Protobuf