c# - BinaryFormatter does not exist in CF. Solutions? -
i need serialize/deserialize obj in/from byte[] on compact framework there no binaryformatter, should do? thanks. class using on server side , want on client(a device windows mobile 6)
public class serializer { public byte[] serializeobject(object obj) { if (obj == null) return null; using (memorystream stream = new memorystream()) { binaryformatter formatter = new binaryformatter(); formatter.serialize(stream, obj); return stream.toarray(); } } public object deserializeobject(byte[] bytes) { if (bytes == null) return null; binaryformatter formatter = new binaryformatter(); memorystream stream = new memorystream(bytes); return formatter.deserialize(stream); } }
for scenario, might consider switching protobuf-net; not same format binaryformatter
, both client , server need tweaks, binary serialization api works on both platforms, , typically smaller added extra. format google's "protocol buffers" encoding; fast, platform-independent, , designed flexible add properties etc. , free. fool gives away.
Comments
Post a Comment