Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, this solution is hard to maintain in a long term.</p> <p>I recommend that you prepend the full name of the serialized type to the serialized data in the serialization process and read the type name in the beginning of the deserialization process (no need to change the protobuf source-code)</p> <p>As a side note, you should try to avoid mixing object types in the deserialization process. I'm assuming you are updating an existing .net application and can't re-design it.</p> <p>Update: Sample code</p> <pre><code>public byte[] Serialize(object myObject) { using (var ms = new MemoryStream()) { Type type = myObject.GetType(); var id = System.Text.ASCIIEncoding.ASCII.GetBytes(type.FullName + '|'); ms.Write(id, 0, id.Length); Serializer.Serialize(ms, myObject); var bytes = ms.ToArray(); return bytes; } } public object Deserialize(byte[] serializedData) { StringBuilder sb = new StringBuilder(); using (var ms = new MemoryStream(serializedData)) { while (true) { var currentChar = (char)ms.ReadByte(); if (currentChar == '|') { break; } sb.Append(currentChar); } string typeName = sb.ToString(); // assuming that the calling assembly contains the desired type. // You can include aditional assembly information if necessary Type deserializationType = Assembly.GetCallingAssembly().GetType(typeName); MethodInfo mi = typeof(Serializer).GetMethod("Deserialize"); MethodInfo genericMethod = mi.MakeGenericMethod(new[] { deserializationType }); return genericMethod.Invoke(null, new[] { ms }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload