This is a creation in Article, where the information may have evolved or changed.
Why is there a lot of almost identical and incorrect tutorials on the Internet???
Fucking Open a tutorial about Golang and protobuf, nothing more than to pull the fuck protobuf how awesome, how stupid xml, and then how to install Protobuf, and then the same shit as an example.
Installation process not a right, I searched so many blogs, all is a virtue, I first write the Ubuntu installation steps, and for Mac and other Linux, and the guarantee is right.
Really powerless to spit groove, first said the matter, and then spit.
First, go to https://github.com/google/protobuf download protobuf, follow the readme steps to compile the installation. If the autoreconf not found error occurs during the execution of the autogen.sh, the description does not install Automake, and the sudo apt-get install Automake libtool on Ubuntu can be done, Other platforms are installed according to the actual situation.
Second, implement Go Get-u Github.com/golang/protobuf/{proto, proto-gen-go}, automatic installation proto-gen-go
Third, copy the proto-gen-go to/usr/local/bin or other path, as long as it is contained in the PATH environment variable, in order to facilitate PROTOC call it.
Four, write a Xx.proto file, execute Protoc--go_out=. Xx.proto generates the code for the Go language, and if the hint libprotoc.so not found, you need to add/usr/local/lib to the LD_LIBRARY_PATH environment variable.
Follow this step down, should all be able to compile successfully, use is also very simple, online a lot of excrement example, mainly call marshal and unmarshal to encode and decode.
So here's the question:
1, I use binary transmission message meaning where?
Of course, there are fewer bytes and less transfer cost.
2, the mother of the binary unreadable Ah, how to decode it?
Calling the Unmarshal function, passing in the object of the corresponding type, automatically decodes the binary into the incoming object.
3, get a big tuo binary data, how to know which class to decode to?
Well, that's a good question, mom. There was no mention of it, forced neglect and pretended to be? When it comes to fucking protobuf, I mention the self-reflection mechanism, can type derivation, how can you tell me what the fuck you don't say???
4, can only know each other to transfer the type, and then can happily use Protobuf?
You know, the type is also coded dry hair ah? recklessly straight in the order of the fields, right? Still use protobuf dry hair???
In short, the online mention of Protobuf, I do not know whether they really used protobuf, hold Google Daddy's thigh trend is not wrong, but forced to pretend a deep work and the name of the appearance is a good atmosphere?
Finally, I still suggest, do the online game protocol, or self-realization serialization and deserialization it, is nothing more than a type ID just, this even the original to heinous??
The next step is to start doing it.