binary-serialization

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:14
问题 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

SerializationException when deserializing

▼魔方 西西 提交于 2019-12-13 02:48:17
问题 This code deserialize object from SQLite. I'm get serialized object from DBinaryData (BLOB) field. But get System.Runtime.Serialization.SerializationException: end of stream encountered before parsing was completed. How to fix this? public void Dump() { try { const string databaseName = @"C:\Code\C#\WcfService\WcfService\mainDB.db3"; SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};", databaseName)); connection.Open(); try { SQLiteCommand command = new

Check whether binary serialized data matches the class which serialized it

邮差的信 提交于 2019-12-11 22:22:07
问题 The title says pretty much what I would like to know. I have data which was binary serialized and now I'm reading it again (class name remains the same) and I would like to know if the serializer misses something because, for example, a private backing field might have been renamed. I did the following refactoring: private string descriptionField; public string Description { get { return this.descriptionField; } } to public string Description { get; private set; } As stated in in this article

Malformed binary serialization of HashMap<String,Double>

老子叫甜甜 提交于 2019-12-11 17:52:53
问题 I wrote some code to serialize a HashMap<String,Double> by iterating entries and serializing each of them instead of using ObjectOutputStream.readObject() . The reason is just efficiency: the resulting file is much smaller and it is much faster to write and read (eg. 23 MB in 0.6 seconds vs. 29 MB in 9.9 seconds). This is what I did to serialize: ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("test.bin")); oos.writeInt(map.size()); // write size of the map for (Map.Entry

Dropwizard and Protocol Buffers by example

こ雲淡風輕ζ 提交于 2019-12-10 10:27:47
问题 Please note: Although this question specifically mentions Dropwizard, I believe anyone with Jersey/JAX-RS experience should be able to answer this question, as I would imagine Dropwizard is just following Jersey/JAX-RS conventions under the hood. I have a Dropwizard service that reds/writes in JSON and works beautifully. I would like to now switch it to read/write binary data (to minimize network bandidth). I see there is the Dropwizard-Protobuf lib but I have a few concerns about

How can I serialize a 3rd party type using protobuf-net or other serializers?

南笙酒味 提交于 2019-12-06 07:33:23
问题 I have List<HtmlAgilityPack.HtmlNode> but protobuf-net gives me error that it doesn't have a contract. How can I specify a contract for it when I don't have the source? It actually said it couldn't infer the type but I assume it's because I didn't use its attibute, right? The default binary serializer also complains because the type is not marked as serializable. EDIT: The error message is: Type is not expected, and no contract can be inferred: HtmlAgilityPack.HtmlNode 回答1: Frankly, in the

deserializing a generic list returns null

送分小仙女□ 提交于 2019-12-06 03:42:51
问题 I'm de/serializing an object like so: public class myClass : ISerializable { public List<OType> value; public myClass(SerializationInfo info, StreamingContext context) { this.value = (List<OType>)info.GetValue("value", typeof(List<OType>)); } void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("value", value, typeof(List<OType>)); } } The object that is in the list does have the Serializable attribute. When serializing, no errors are thrown and

Dropwizard and Protocol Buffers by example

霸气de小男生 提交于 2019-12-05 22:51:18
Please note: Although this question specifically mentions Dropwizard, I believe anyone with Jersey/JAX-RS experience should be able to answer this question, as I would imagine Dropwizard is just following Jersey/JAX-RS conventions under the hood. I have a Dropwizard service that reds/writes in JSON and works beautifully. I would like to now switch it to read/write binary data (to minimize network bandidth). I see there is the Dropwizard-Protobuf lib but I have a few concerns about implementing binary serialization in Dropwizard. First off, here's the important stuff from my current (JSON

DeflateStream doesnt work on MemoryStream?

你离开我真会死。 提交于 2019-12-05 01:19:02
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("Compressed from {0} to {1} bytes.", assignedUsersStream.Length.ToString(), resultStream.Length.ToString()); }

How can I serialize a 3rd party type using protobuf-net or other serializers?

扶醉桌前 提交于 2019-12-04 13:31:57
I have List<HtmlAgilityPack.HtmlNode> but protobuf-net gives me error that it doesn't have a contract. How can I specify a contract for it when I don't have the source? It actually said it couldn't infer the type but I assume it's because I didn't use its attibute, right? The default binary serializer also complains because the type is not marked as serializable. EDIT: The error message is: Type is not expected, and no contract can be inferred: HtmlAgilityPack.HtmlNode Frankly, in the case of HTML I'd just store... the html - it is kinda pre-serialised! However, to answer the question: In