static object[] ReadArgs(OSCTypeTag[] argTypes, OSCReader oscr) { if (argTypes.Length > 0) { List <object> args = new List <object>(); foreach (OSCTypeTag argType in argTypes) { switch (argType) { case OSCTypeTag.Int32: args.Add(oscr.ReadInt32()); break; case OSCTypeTag.Float: args.Add(oscr.ReadSingle()); break; case OSCTypeTag.String: args.Add(oscr.ReadString()); break; case OSCTypeTag.Blob: { int size = oscr.ReadInt32(); byte[] array = oscr.ReadBytes(size); int remainder = size % 4; if (remainder != 0) { oscr.ReadBytes(remainder); } args.Add(array); } break; case OSCTypeTag.Int64: args.Add(oscr.ReadInt64()); break; case OSCTypeTag.Time: throw new NotImplementedException(); case OSCTypeTag.Double: args.Add(oscr.ReadDouble()); break; case OSCTypeTag.StringAlt: args.Add(oscr.ReadString()); break; case OSCTypeTag.Character: args.Add((char)oscr.ReadInt32()); break; case OSCTypeTag.Color: args.Add(oscr.ReadUInt32()); break; case OSCTypeTag.Midi: throw new NotImplementedException(); case OSCTypeTag.True: args.Add(true); break; case OSCTypeTag.False: args.Add(false); break; case OSCTypeTag.Nil: args.Add(null); break; case OSCTypeTag.Infinitum: args.Add(double.PositiveInfinity); break; case OSCTypeTag.ArrayBegin: case OSCTypeTag.ArrayEnd: throw new NotImplementedException(); } } return(args.ToArray()); } return(null); }
public static OSCMessage FromData(byte[] data, int dataLength, string from) { if (data[0] == '#') { // Bundle throw new NotImplementedException(); } else { // Message OSCReader oscr = new OSCReader(new MemoryStream(data)); string address = oscr.ReadString(); OSCTypeTag[] argTypes = oscr.ReadTags(); object[] args = ReadArgs(argTypes, oscr); OSCMessage msg = new OSCMessage(address, args); msg.From = from; return(msg); } }