pizheng / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

[Question] Using protobuf on closed source classes? #181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This isn't an issue but a question, I'm not sure if there's a forum dedicated 
to protobuf-net, but I cannot find it.

My question is, is it possible to use protobuf on classes that I don't have the 
source code to?  (Such as XNA's vector and matrix classes)

I'm using the latest v2 beta from the downloads section.

Thanks for any help, and also thank you for creating a great library!

Original issue reported on code.google.com by ylos...@gmail.com on 5 Jun 2011 at 11:19

GoogleCodeExporter commented 9 years ago
You can use a RuntimeTypeModel to tell it how to serialize types you don't 
control, or in more complicated cases - add a surrogate. Are you using a 
TypeModel currently?

Original comment by marc.gravell on 6 Jun 2011 at 9:57

GoogleCodeExporter commented 9 years ago
No I am not using either.
Are there any samples on how to implement either a surrogate or a TypeModel in 
protobuf-net?

Original comment by ylos...@gmail.com on 6 Jun 2011 at 6:12

GoogleCodeExporter commented 9 years ago
k; as a first stab:

    RuntimeTypeModel.Default.Add(typeof(Vector3), false).Add("X", "Y", "Z");

somewhere at startup registers Vector3, using fields 1,2,3 to serialize X,Y,Z 

does that work?

Original comment by marc.gravell on 6 Jun 2011 at 7:31

GoogleCodeExporter commented 9 years ago
    RuntimeTypeModel.Default.Add(typeof(Vector3), false).Add("X", "Y", "Z");

This works great!
Thanks for your help, and again thanks for porting this to .net!

Original comment by ylos...@gmail.com on 6 Jun 2011 at 11:40

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 13 Jun 2011 at 8:26