aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.PMR/ExtensionMethods/IMessageExtensions.cs
blob: 84acb51d21297267b7073162ad2d98c80997024a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


public static class IMessageExtensions
{
    /// <summary>
    /// Serializes this PMR message to byte array.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="message">The message.</param>
    /// <returns></returns>
    public static byte[] ToBytes<T>(this T message) where T : IMessage<T>
    {
        using (MemoryStream ms = new MemoryStream())
        {
            message.WriteTo(ms);
            return ms.ToArray();
        }
    }
}