Skip to content

Instantly share code, notes, and snippets.

@GuoJing
Last active December 29, 2015 07:13
Show Gist options
  • Save GuoJing/f21105ec4c930e6f17c7 to your computer and use it in GitHub Desktop.
Save GuoJing/f21105ec4c930e6f17c7 to your computer and use it in GitHub Desktop.
syntax = "proto3";
package tutorial;
message Person {
string name = 1;
int32 id = 2;
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phone = 4;
}
import sample_pb2
person = sample.Person()
person.id = 1234
person.name = "GuoJing"
person.email = "[email protected]"
# 序列化
data = person.SerializeToString()
person1 = sample.Person()
# 反序列化
person1.ParseFromString(data)
print person1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment