Dusan Klinec | ccaa0d9 | 2014-11-09 03:21:31 +0100 | [diff] [blame] | 1 | import plyproto.parser as plyproto |
| 2 | |
| 3 | test1 = """package tutorial;""" |
| 4 | |
| 5 | test2 = """package tutorial; |
| 6 | |
| 7 | message Person { |
| 8 | required string name = 1; |
| 9 | required int32 id = 2; |
| 10 | optional string email = 3; |
| 11 | } |
| 12 | |
| 13 | """ |
| 14 | |
| 15 | test3 = """package tutorial; |
| 16 | option java_outer_classname = "PushNotifications"; |
Dusan Klinec | aa9ff47 | 2014-11-10 18:02:03 +0100 | [diff] [blame] | 17 | option optimize_for = SPEED; |
Dusan Klinec | ccaa0d9 | 2014-11-09 03:21:31 +0100 | [diff] [blame] | 18 | |
| 19 | message Person { |
| 20 | required string name = 1; |
| 21 | required int32 id = 2; |
| 22 | optional string email = 3; |
| 23 | |
| 24 | enum PhoneType { |
| 25 | MOBILE = 0; |
| 26 | HOME = 1; |
| 27 | WORK = 2; |
| 28 | } |
| 29 | |
| 30 | message PhoneNumber { |
| 31 | required string number = 1; |
| 32 | optional PhoneType type = 2 [default = HOME]; |
| 33 | } |
| 34 | |
| 35 | repeated PhoneNumber phone = 4; |
| 36 | extensions 500 to 990; |
| 37 | } |
| 38 | |
| 39 | message AddressBook { |
| 40 | repeated Person person = 1; |
| 41 | |
| 42 | // Possible extension numbers. |
| 43 | extensions 500 to max; |
| 44 | }""" |
| 45 | |
| 46 | parser = plyproto.ProtobufAnalyzer() |
| 47 | print(parser.parse_string(test3)) |