aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Transport/Encoders/ProtoEncoder.cs
blob: bdc47da706505f4f94445d3578a1ce0f80bf1d50 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR;
using Tango.PMR.Common;

namespace Tango.Transport.Encoders
{
    /// <summary>
    /// Represents a protobuf <see cref="ITransportEncoder">Transport Encoder</see>.
    /// </summary>
    /// <seealso cref="Tango.Transport.ITransportEncoder" />
    public class ProtoEncoder : ITransportEncoder
    {
        /// <summary>
        /// Decodes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public ITangoMessage Decode(byte[] data)
        {
            return MessageFactory.ParseTangoMessageAgnostic(data);
        }

        /// <summary>
        /// Decodes only the container part of the message.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public MessageContainer DecodeContainer(byte[] data)
        {
            return MessageFactory.ParseContainer(data);
        }

        /// <summary>
        /// Encodes the specified tango message.
        /// </summary>
        /// <param name="tangoMessage">The tango message.</param>
        /// <returns></returns>
        public byte[] Encode(ITangoMessage tangoMessage)
        {
            return tangoMessage.ToBytes();
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return "Protobuf Encoder";
        }
    }
}
s="p">{ _connection = value; RaisePropertyChangedAuto(); } } public SafetyLevelOperationsConfirmationViewVM(ExternalBridgeClientConnectedEventArgs connection) { Connection = connection; MaxSeconds = 30; SecondsRemaining = 30; _timer = new DispatcherTimer(DispatcherPriority.Background, Application.Current.Dispatcher); _timer.Interval = TimeSpan.FromMilliseconds(800); _timer.Tick += _timer_Tick; } public override void OnShow() { base.OnShow(); _timer.Start(); } protected override void Accept() { _timer.Stop(); base.Accept(); } protected override void Cancel() { _timer.Stop(); base.Cancel(); } private void _timer_Tick(object sender, EventArgs e) { SecondsRemaining--; if (SecondsRemaining == 0) { Cancel(); } } } }