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
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLY.Thick.Base.Common
{
public class TimeGridEventArgs : EventArgs
{
/// <summary>
/// 数据, 厚度数据!!!!!
/// </summary>
public int[] data;
/// <summary>
/// 单数据时间间隔
/// </summary>
public TimeSpan ts;
/// <summary>
/// 开始时间点
/// </summary>
public DateTime time;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(time.Ticks));
buf.AddRange(BitConverter.GetBytes(ts.Ticks));
buf.AddRange(BitConverter.GetBytes(data.Length));
for (int i = 0; i < data.Length; i++)
buf.AddRange(BitConverter.GetBytes(data[i]));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
int cnt = 8 * 2 + 4;
if (value.Length < cnt)
return false;
int idx = 0;
time = new DateTime(BitConverter.ToInt64(value, idx));
idx += 8;
ts = TimeSpan.FromTicks(BitConverter.ToInt64(value, idx));
idx += 8;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
cnt += (len * 4);
if (value.Length < cnt)
return false;
data = new int[len];
for (int i = 0; i < len; i++)
{
data[i] = BitConverter.ToInt32(value, idx);
idx += 4;
}
return true;
}
#endregion
}
}