-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodels.cs
More file actions
114 lines (96 loc) · 2.77 KB
/
models.cs
File metadata and controls
114 lines (96 loc) · 2.77 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System.Net;
namespace ETVRTrackingModule
{
public enum OSCType
{
Integer,
Float,
Bool,
IPAddress,
String,
}
public static class OSCValueUtils
{
public static readonly Dictionary<OSCType, (Type, Type)> OSCTypeMap = new()
{
{OSCType.Integer, (typeof(int), typeof(OSCInteger))},
{OSCType.Float, (typeof(float), typeof(OSCFloat))},
{OSCType.Bool, (typeof(bool), typeof(OSCBool))},
{OSCType.String, (typeof(string), typeof(OSCString))},
{OSCType.IPAddress, (typeof(string), typeof(OSCIPAddress))},
};
public static void ExtractStringData(byte[] buffer, int length, ref int step, out string result)
{
string value = "";
for (int i = step; i < length; i++)
{
// we've reached the end of the address section, let's update the steps counter
// to point at the value section
if (buffer[i] == 0)
{
// we need to ensure that we include the null terminator
step = i + 1;
// the size of a packet is a multiple of 4, we need to round it up
if (step % 4 != 0) { step += 4 - (step % 4); }
break;
}
value += (char)buffer[i];
}
result = value;
}
}
public abstract class OSCValue
{
public abstract OSCType Type { get; }
}
public class OSCInteger: OSCValue {
public override OSCType Type => OSCType.Integer;
public int value;
public OSCInteger(int value)
{
this.value = value;
}
}
public class OSCFloat: OSCValue
{
public override OSCType Type => OSCType.Float;
public float value;
public OSCFloat(float value)
{
this.value = value;
}
}
public class OSCBool: OSCValue
{
public override OSCType Type => OSCType.Bool;
public bool value;
public OSCBool(bool value)
{
this.value = value;
}
}
public class OSCString : OSCValue
{
public override OSCType Type => OSCType.String;
public string value;
public OSCString(string value)
{
this.value = value;
}
}
public class OSCIPAddress : OSCValue
{
public override OSCType Type => OSCType.IPAddress;
public IPAddress value;
public OSCIPAddress(IPAddress value)
{
this.value = value;
}
}
public struct OSCMessage
{
public string address;
public OSCValue value;
public bool success;
}
}