Esempio n. 1
0
        public static T FromProtoBuf <T>(this byte[] bytes)
        {
            using var ms = MemoryStreamFactory.GetStream(bytes);
            var obj = (T)ProtoBufFormat.Deserialize(typeof(T), ms);

            return(obj);
        }
Esempio n. 2
0
        public static byte[] ToProtoBuf <T>(this T obj)
        {
            using var ms = MemoryStreamFactory.GetStream();
            ProtoBufFormat.Serialize(obj, ms);
            var bytes = ms.ToArray();

            return(bytes);
        }
 public static T FromProtoBuf <T>(this byte[] bytes)
 {
     using (var ms = new MemoryStream(bytes))
     {
         var obj = (T)ProtoBufFormat.Deserialize(typeof(T), ms);
         return(obj);
     }
 }
 public static byte[] ToProtoBuf <T>(this T obj)
 {
     using (var ms = new MemoryStream())
     {
         ProtoBufFormat.Serialize(obj, ms);
         var bytes = ms.ToArray();
         return(bytes);
     }
 }
 private static object Deserialize(Type type, Stream source)
 {
     try
     {
         return(ProtoBufFormat.Deserialize(type, source));
     }
     catch (Exception ex)
     {
         throw new SerializationException("ProtoBufServiceClient: Error deserializing: " + ex.Message, ex);
     }
 }
 public override T DeserializeFromStream <T>(Stream stream)
 {
     try
     {
         return(ProtoBufFormat.Deserialize <T>(stream));
     }
     catch (Exception ex)
     {
         throw new SerializationException("ProtoBufServiceClient: Error deserializing: " + ex.Message, ex);
     }
 }
 public override void SerializeToStream(IRequest req, object request, Stream stream)
 {
     try
     {
         ProtoBufFormat.Serialize(req, request, stream);
     }
     catch (Exception ex)
     {
         throw new SerializationException("ProtoBufServiceClient: Error serializing: " + ex.Message, ex);
     }
 }