Initial version
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using ProtoBuf;
|
||||
|
||||
namespace EonaCat.gRPC.Proto.Helpers;
|
||||
|
||||
public static class Utility
|
||||
{
|
||||
public static byte[] ProtoSerialize<T>(T record) where T : class
|
||||
{
|
||||
if (null == record) return null;
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
Serializer.Serialize(stream, record);
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Log error
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static T ProtoDeserialize<T>(byte[] data) where T : class
|
||||
{
|
||||
if (null == data) return null;
|
||||
|
||||
try
|
||||
{
|
||||
using (var stream = new MemoryStream(data))
|
||||
{
|
||||
return Serializer.Deserialize<T>(stream);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Log error
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user