protobuf序列化、反序列化

引用dllprotobuf-net.rar

 

/// <summary>

/// buf序列化

/// </summary>

public static String SerializerBuf<T>(T obj)

{

MemoryStream ms = new MemoryStream();

ProtoBuf.Serializer.Serialize<T>(ms, obj);

return Convert.ToBase64String(ms.ToArray());

}

 

/// <summary>

/// buf反序列化

/// </summary>

/// <typeparam name="T"></typeparam>

/// <param name="base64String"></param>

/// <returns></returns>

public static T DeSerializerBuf<T>(string base64String)

{

MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64String));

return ProtoBuf.Serializer.Deserialize<T>(ms);

}

posted on 2015-06-19 10:26  Anthony.Zhao  阅读(776)  评论(0编辑  收藏  举报