I’m about serialize a paket with information, which act as an answer on a incoming udp paket. The incoming UDP paket is very compact and contains exactly the information I want to see.
When I send my reply, the packet is nearly 200 times bigger (1036 byte against 57 byte..) and contains a lot of white spaces, name of the class instance and it’s structure (like nullable and so on).
The question may sounds wide but what are the problem here? I understand that my solution is serialize the whole object, including it’s class name, namespace and so on. The recipient don’t need, won’t and Can’t take this info. They need to go directly into the data structure.
You should probably try out Protobuf. It supports the attributed serialization model (in fact, it supports several attributed models, including the
DataContractWCF model), and is significantly faster than built-in .Net binary serialization (faster than evenDataContractserialization). Protobuf is also designed to be as compact as possible – so you should have fewer problems with packet size.Edit: You could also implement your own serialization paradigm, by using an interface. For example: