I\'d like to serialize/de-serialize an object using a string. Just to note, when I serialize/de-serialize to a file everything works fine. What I\'m trying to do is get a
Based on the answer and the comment, I use these:
internal static string SerializeToString_PB(this T obj)
{
using (MemoryStream ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, obj);
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
}
}
internal static T DeserializeFromString_PB(this string txt)
{
byte[] arr = Convert.FromBase64String(txt);
using (MemoryStream ms = new MemoryStream(arr))
return ProtoBuf.Serializer.Deserialize(ms);
}