-
Notifications
You must be signed in to change notification settings - Fork 0
/
OscArgumentParser.cs
26 lines (22 loc) · 985 Bytes
/
OscArgumentParser.cs
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
using System;
using Suhock.Osc.Arguments;
namespace Suhock.Osc;
/// <summary>
/// An <see cref="IOscArgumentParser"/> implementation for working with the four basic OSC argument types specified in
/// the OSC protocol.
/// </summary>
public class OscArgumentParser : IOscArgumentParser
{
public virtual IOscArgument FromBytes(byte typeTag, ReadOnlySpan<byte> bytes, out int length)
{
length = 0;
return typeTag switch
{
OscStringArgument.TypeTagByte => new OscStringArgument(OscUtil.ReadString(bytes, out length)),
OscIntArgument.TypeTagByte => new OscIntArgument(OscUtil.ReadInt(bytes, out length)),
OscFloatArgument.TypeTagByte => new OscFloatArgument(OscUtil.ReadFloat(bytes, out length)),
OscBlobArgument.TypeTagByte => new OscBlobArgument(OscUtil.ReadBlob(bytes, out length)),
_ => throw new ArgumentException($"Unsupported type tag: {typeTag}", nameof(typeTag))
};
}
}