Last active
December 29, 2015 07:13
-
-
Save GuoJing/f21105ec4c930e6f17c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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