A list,

Protobuffer is a data transfer protocol similar to JSON. It is not a protocol, but a data transfer format similar to JSON and XML. But it’s much lighter than JSON. Consumes less bandwidth. Cross-language, that’s one of its advantages. It comes with a compiler, protoc, just need to use it to compile, can be compiled into JAVA, python, C++ code, only these three, the other temporarily forget, and then you can directly use, do not need to write any other code. Even the ones that parse are already there. JSON is also cross-language of course, but this cross-language is built on the basis of writing code, iOS developers can use Protobuf to add third-party libraries to integrate with the development environment for use.

Second, integration of the environment

1. Protobuf buffers installation download

Environment address github.com/google/prot…

2. Decompress the downloaded package. After decompressing the package, use the terminal to access the root directory and run the following command

$./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
Copy the code

3. Open the TERMINAL and run the following command

$ cd /usr/local/bin/
$ ls
Copy the code

If protoc is present, the Protoc plug-in is already installed

Create xxx.proto file

LLDB: Create a person. proto file

syntax = "proto3";

message Person {
	string name = 1;
	int32 age = 2;
	string gender = 3;
}
Copy the code

Enter:

protoc --proto_path=. --objc_out=. Person.proto
Copy the code

H and.m files will be generated in the same path as person. proto. Note that the generated files are MRC files

Four, how to use

Rely on the Protobuf third-party frameworks: Cocoapods https://github.com/google/protobuf.git can be used for import

Five, common error solutions

Serialization and deserialization

7,

The use of protobuf data format, improve programmer development efficiency, due to the lightweight data, occupied less bandwidth, improve the efficiency of the program. Proto files need to be defined in the early stage and the background, and the data obtained can be directly deserialized into data Model, which improves the development efficiency to a certain extent.