i'm trying use protobuf-net create object of class on tcp connection. i'm relatively new i'm following tutorial @ https://code.google.com/p/protobuf-net/wiki/gettingstarted
on host have code defining class "person"
[protocontract] class person { [protomember(1)] public int id {get; set;} [protomember(2)] public string name {get; set:} [protomember(3)] public address address {get; set;} } and block serializes class .bin file :
var person = new person { id = 12345, name = "fred", address = new address { line1 = "flat 1", line2 = "the meadows" } }; using (var file = file.create("person.bin")) { serializer.serialize(file, person); } i copied , pasted person.bin file project folder on client , used following block read .bin file , output segment of file.
person newperson; using (var file = file.openread("person.bin")) { newperson = serializer.deserialize<person>(file); } console.writeline("the name is: " + newperson.name); unfortunately, works when have code defining class "person" on client. how can send definition of class host client on tcp connection using protocol buffers can create object on client?
in general, parts of system communicating using protobufs need know definitions of protobufs in order work them (your receiving class must know priori structure of person, , how deserialize it).
it's inconvenient , inefficient, it's not usual case, can use self-describing message simultaneously send structure , data: https://developers.google.com/protocol-buffers/docs/techniques#self-description
Comments
Post a Comment