Inheritance: OscPacket
Esempio n. 1
0
        /// <summary>
        /// Takes in an OSC bundle package in byte form and parses it into a more usable OscBundle object
        /// </summary>
        /// <param name="bundle"></param>
        /// <returns>Bundle containing elements and a timetag</returns>
        private static OscBundle parseBundle(byte[] bundle)
        {
            UInt64            timetag;
            List <OscMessage> messages = new List <OscMessage>();

            int index = 0;

            var bundleTag = Encoding.UTF8.GetString(bundle.SubArray(0, 8));

            index += 8;

            timetag = getULong(bundle, index);
            index  += 8;

            if (bundleTag != "#bundle\0")
            {
                throw new Exception("Not a bundle");
            }

            while (index < bundle.Length)
            {
                int size = getInt(bundle, index);
                index += 4;

                byte[] messageBytes = bundle.SubArray(index, size);
                var    message      = parseMessage(messageBytes);

                messages.Add(message);

                index += size;
                while (index % 4 != 0)
                {
                    index++;
                }
            }

            OscBundle output = new OscBundle(timetag, messages.ToArray());

            return(output);
        }
Esempio n. 2
0
        /// <summary>
        /// Takes in an OSC bundle package in byte form and parses it into a more usable OscBundle object
        /// </summary>
        /// <param name="bundle"></param>
        /// <returns>Bundle containing elements and a timetag</returns>
        private static OscBundle parseBundle(byte[] bundle)
        {
            UInt64 timetag;
            List<OscMessage> messages = new List<OscMessage>();

            int index = 0;

            var bundleTag = Encoding.ASCII.GetString(bundle.SubArray(0, 8));
            index += 8;

            timetag = getULong(bundle, index);
            index += 8;

            if (bundleTag != "#bundle\0")
                throw new Exception("Not a bundle");

            while (index < bundle.Length)
            {
                int size = getInt(bundle, index);
                index += 4;

                byte[] messageBytes = bundle.SubArray(index, size);
                var message = parseMessage(messageBytes);

                messages.Add(message);

                index += size;
                while (index % 4 != 0)
                    index++;
            }

            OscBundle output = new OscBundle(timetag, messages.ToArray());
            return output;
        }