binary-serialization

Should I Still Use BinaryFormatter for Simple Serialization in .NET 4.0?

一笑奈何 提交于 2020-01-24 03:05:47
问题 I am developing a master-slave style application. The master application will send state data to the slave(s) to process and display at some constant rate. The state data is wrapped up into a single class that contains many fields. These field types consist of primitives, classes, interfaces, lists of interfaces, and so on. All the types are either BCL or custom types, so the the custom types can be modified if necessary. Both the master and and slave applications will be .NET 4.0. I am not

Should I Still Use BinaryFormatter for Simple Serialization in .NET 4.0?

筅森魡賤 提交于 2020-01-24 03:05:38
问题 I am developing a master-slave style application. The master application will send state data to the slave(s) to process and display at some constant rate. The state data is wrapped up into a single class that contains many fields. These field types consist of primitives, classes, interfaces, lists of interfaces, and so on. All the types are either BCL or custom types, so the the custom types can be modified if necessary. Both the master and and slave applications will be .NET 4.0. I am not

Wire Protocol Serialization

早过忘川 提交于 2020-01-06 07:27:40
问题 I'm looking for what I'll call a 'binary serializer/deserializer code generator' for lack of a better term that specifically allows you to specify the on-the-wire format with arbitrary bit lengths and then generates the necessary C/C++ code to pack/unpack packets in that format. I started down the path of using a struct with bit fields but after reading this post I'm wondering if there's already something out there that handles all the messy problems. An example data structure I would need to

.net serialization: how to selectively ignore data fields

冷暖自知 提交于 2020-01-02 10:15:30
问题 In. Net you can mark a field as non serializable, and it will be skipped during serialization. I'm looking for a simple method that will allow me to control in runtime whether a specific field should be serialized. 回答1: You are referring to "mark a field as non serializable", so I assume you are using BinaryFormatter and [NonSerialized] . If so, the only way to do conditional serialization is by implementing ISerializable and adding a similar constructor, and putting the logic in the

DeflateStream doesnt work on MemoryStream?

拜拜、爱过 提交于 2019-12-22 03:51:03
问题 I have the following piece of code: MemoryStream resultStream = new MemoryStream(); string users = ""//Really long string goes here BinaryFormatter bFormatter = new BinaryFormatter(); using (MemoryStream assignedUsersStream = new MemoryStream()) { bFormatter.Serialize(assignedUsersStream, users); assignedUsersStream.Position = 0; using (var compressionStream = new DeflateStream(resultStream, CompressionLevel.Optimal)) { assignedUsersStream.CopyTo(compressionStream); Console.WriteLine(

How to ignore Event class member for binary serialization?

五迷三道 提交于 2019-12-20 11:52:29
问题 I need to avoid serializing an Event class member because when the event is handled by an object that is not marked as Serializable the serialization will fail. I tried using the NonSerialized attribute on the Event class member but it fails to compile. This line of code: <NonSerialized()> Public Event PropertyValueChanged() produces the following error: Attribute 'NonSerializedAttribute' cannot be applied to 'PropertyValueChanged' because the attribute is not valid on this declaration type.

Does protobuf-net have built-in compression for serialization?

扶醉桌前 提交于 2019-12-20 11:07:49
问题 I was doing some comparison between BinaryFormatter and protobuf-net serializer and was quite pleased with what I found, but what was strange is that protobuf-net managed to serialize the objects into a smaller byte array than what I would get if I just wrote the value of every property into an array of bytes without any metadata. I know protobuf-net supports string interning if you set AsReference to true , but I'm not doing that in this case, so does protobuf-net provide some compression by

Java partial (de)serialization of objects

爱⌒轻易说出口 提交于 2019-12-20 02:35:35
问题 Let's say we have 3 Classes: class foo { // not a singleton String s; } class bar { foo f; int i; } class baz { foo sameF; } Now we create instances foo onlyFoo = new foo("the only one"); bar theBar = new bar(onlyFoo, 123); baz theBaz = new baz(onlyFoo); After that we want to store them serilazed in a file. If we deserialze theBaz, modify onlyFoo and deserialize theBaz to the file again, theBar still contains the original onlyFoo, so there are two different versions of onlyFoo. What I want

How to write to file when using Marshal::dump in Ruby for object serialization

自闭症网瘾萝莉.ら 提交于 2019-12-18 04:30:11
问题 Lets say I have the object line from class Line : class Line def initialize point1, point2 @p1 = point1 @p2 = point2 end end line = Line.new... How can I binary serialize the line object? I tried with: data = Marshal::dump(line, "path/to/still/unexisting/file") but it created file and didn't add anything. I read the Class: IO documentation but I couldn't really get it. 回答1: Like this: class Line attr_reader :p1, :p2 def initialize point1, point2 @p1 = point1 @p2 = point2 end end line = Line

How to create a SerializationBinder for the Binary Formatter that handles the moving of types from one assembly and namespace to another

﹥>﹥吖頭↗ 提交于 2019-12-17 09:56:46
问题 The context is as follows I want to refactor code by moving it around to different projects Some of this code comprises of serializable DTOs that are used to send and receive data across multiple endpoints If I move the code around, serialization breaks (therefore it is not backward compatible with older versions of my application) A solution to this problem is the SerializationBinder which allows me to "redirect" in a sense from one type to another. I therefore want to create a