Last active
August 29, 2015 14:05
-
-
Save krestenkrab/bae542521c80f383c858 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
message Person { | |
required int32 id = 1; | |
required string name = 2; | |
optional string email = 3; | |
repeated Address addresses = 4; | |
extensions 10 to max; | |
} | |
message Address { | |
required string street = 1; | |
} | |
message Phone { | |
extend Person { repeated Phone phones = 10;} | |
enum PHONE_TYPE{ | |
MOBILE = 1; | |
HOME = 2; | |
} | |
optional string num = 1; | |
optional PHONE_TYPE type = 2; | |
} |
This file contains hidden or 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
package.path = package.path .. ';../protobuf/?.lua' | |
package.cpath = package.cpath .. ';../protobuf/?.so' | |
require 'person_pb' | |
local person= person_pb.Person() | |
person.id = 1000 | |
person.name = "Alice" | |
person.email = "[email protected]" | |
local home = person.Extensions[person_pb.Phone.phones]:add() | |
home.num = "2147483647" | |
home.type = person_pb.Phone.HOME | |
local addr = person.addresses:add() | |
addr.street = "Gade1" | |
local addr = person.addresses:add() | |
addr.street = "Gade2" | |
-- person.addresses = { addr1, addr2 } | |
local data = person:SerializeToString() | |
local msg = person_pb.Person() | |
msg:ParseFromString(data) | |
print(msg.addresses[1]) | |
print(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment