private void ScanMessage(byte[] buffer, int offset, int length)
        {
            // Where the next element begins if any
            var next = offset + length;

            // OSC address
            var address = OscDataTypes.ReadString(buffer, offset);

            offset += OscDataTypes.Align4(address.Length + 1);

            if (address == "#bundle")
            {
                // We don't use the timestamp data; Just skip it.
                offset += 8;

                // Keep reading until the next element begins.
                while (offset < next)
                {
                    // Get the length of the element.
                    var elementLength = OscDataTypes.ReadInt(buffer, offset);
                    offset += 4;

                    // Scan the bundle element in a recursive fashion.
                    ScanMessage(buffer, offset, elementLength);
                    offset += elementLength;
                }
            }
            else
            {
                // Retrieve the arguments and dispatch the message.
                _dataHandle.Scan(buffer, offset);
                _dispatcher.Dispatch(address, _dataHandle);
            }
        }
예제 #2
0
        internal void Scan(Byte[] buffer, int offset)
        {
            // Reset the internal state.
            _sharedBuffer = buffer;
            _typeTags.Clear();
            _offsets.Clear();

            // Read type tags.
            offset++; // ","

            while (true)
            {
                var tag = (char)buffer[offset];
                if (!OscDataTypes.IsSupportedTag(tag))
                {
                    break;
                }
                _typeTags.Add(tag);
                offset++;
            }

            offset += OscDataTypes.GetStringSize(buffer, offset);

            // Determine the offsets of the each element.
            foreach (var tag in _typeTags)
            {
                _offsets.Add(offset);

                if (tag == 'i' || tag == 'f')
                {
                    offset += 4;
                }
                if (tag == 'd')
                {
                    offset += 8;
                }
                else if (tag == 's')
                {
                    offset += OscDataTypes.GetStringSize(buffer, offset);
                }
                else // tag == 'b'
                {
                    offset += 4 + OscDataTypes.ReadInt(buffer, offset);
                }
            }
        }
예제 #3
0
        internal void Scan(byte[] buffer, int offset)
        {
            // Reset the internal state.
            _sharedBuffer = buffer;
            _typeTags.Clear();
            _offsets.Clear();

            // Read type tags.
            offset++; // ","

            while (true)
            {
                var tag = (char)buffer[offset];
                if (!OscDataTypes.IsSupportedTag(tag))
                {
                    break;
                }
                _typeTags.Add(tag);
                offset++;
            }

            offset += OscDataTypes.GetStringSize(buffer, offset);

            // Determine the offsets of the each element.
            foreach (var tag in _typeTags)
            {
                _offsets.Add(offset);

                switch (tag)
                {
                case 'i':
                case 'f':
                    offset += 4;
                    break;

                case 's':
                    offset += OscDataTypes.GetStringSize(buffer, offset);
                    break;

                // tag == 'b'
                default:
                    offset += 4 + OscDataTypes.ReadInt(buffer, offset);
                    break;
                }
            }
        }
예제 #4
0
        public float GetElementAsFloat(int index)
        {
            if (index >= _typeTags.Count)
            {
                return(0);
            }
            var tag  = _typeTags[index];
            var offs = _offsets[index];

            if (tag == 'f')
            {
                return(OscDataTypes.ReadFloat(_sharedBuffer, offs));
            }
            if (tag == 'i')
            {
                return(OscDataTypes.ReadInt(_sharedBuffer, offs));
            }
            return(0);
        }
예제 #5
0
        public float GetElementAsFloat(int index)
        {
            if (index >= _typeTags.Count)
            {
                return(0);
            }
            var tag  = _typeTags[index];
            var offs = _offsets[index];

            switch (tag)
            {
            case 'f':
                return(OscDataTypes.ReadFloat(_sharedBuffer, offs));

            case 'i':
                return(OscDataTypes.ReadInt(_sharedBuffer, offs));

            default:
                return(0);
            }
        }
예제 #6
0
        public string GetElementAsString(int index)
        {
            if (index >= _typeTags.Count)
            {
                return("");
            }
            var tag  = _typeTags[index];
            var offs = _offsets[index];

            if (tag == 's')
            {
                return(OscDataTypes.ReadString(_sharedBuffer, offs));
            }
            if (tag == 'i')
            {
                return(OscDataTypes.ReadInt(_sharedBuffer, offs).ToString());
            }
            if (tag == 'f')
            {
                return(OscDataTypes.ReadFloat(_sharedBuffer, offs).ToString());
            }
            return("");
        }
예제 #7
0
        public string GetElementAsString(int index)
        {
            if (index >= _typeTags.Count)
            {
                return("");
            }
            var tag  = _typeTags[index];
            var offs = _offsets[index];

            switch (tag)
            {
            case 's':
                return(OscDataTypes.ReadString(_sharedBuffer, offs));

            case 'i':
                return(OscDataTypes.ReadInt(_sharedBuffer, offs).ToString());

            case 'f':
                return(OscDataTypes.ReadFloat(_sharedBuffer, offs).ToString());

            default:
                return("");
            }
        }