コード例 #1
0
void ReceivedMessageArgumentIterator::Advance()
{
    if( !value_.typeTag_ )
        return;
        
    switch( *value_.typeTag_++ ){
        case '\0':
            // don't advance past end
            --value_.typeTag_;
            break;
            
        case TRUE_TYPE_TAG:
        case FALSE_TYPE_TAG:
        case NIL_TYPE_TAG:
        case INFINITUM_TYPE_TAG:
        case ARRAY_START_TYPE_TAG:
        case ARRAY_END_TYPE_TAG:

            // zero length
            break;

        case INT32_TYPE_TAG:
        case FLOAT_TYPE_TAG: 					
        case CHAR_TYPE_TAG:
        case RGBA_COLOR_TYPE_TAG:
        case MIDI_MESSAGE_TYPE_TAG:

            value_.argument_ += 4;
            break;

        case INT64_TYPE_TAG:
        case TIME_TAG_TYPE_TAG:
        case DOUBLE_TYPE_TAG:
				
            value_.argument_ += 8;
            break;

        case STRING_TYPE_TAG: 
        case SYMBOL_TYPE_TAG:

            // we use the unsafe function FindStr4End(char*) here because all of
            // the arguments have already been validated in
            // ReceivedMessage::Init() below.
            
            value_.argument_ = FindStr4End( value_.argument_ );
            break;

        case BLOB_TYPE_TAG:
            {
                uint32 blobSize = ToUInt32( value_.argument_ );
                value_.argument_ = value_.argument_ + 4 + RoundUp4( (unsigned long)blobSize );
            }
            break;

        default:    // unknown type tag
            // don't advance
            --value_.typeTag_;
            break;
    }
}
コード例 #2
0
void ReceivedMessage::Init( const char *message, unsigned long size )
{
    if( size == 0 )
        throw MalformedMessageException( "zero length messages not permitted" );

    if( (size & 0x03L) != 0 )
        throw MalformedMessageException( "message size must be multiple of four" );

    const char *end = message + size;

    typeTagsBegin_ = FindStr4End( addressPattern_, end );
    if( typeTagsBegin_ == 0 ){
        // address pattern was not terminated before end
        throw MalformedMessageException( "unterminated address pattern" );
    }

    if( typeTagsBegin_ == end ){
        // message consists of only the address pattern - no arguments or type tags.
        typeTagsBegin_ = 0;
        typeTagsEnd_ = 0;
        arguments_ = 0;
            
    }else{
        if( *typeTagsBegin_ != ',' )
            throw MalformedMessageException( "type tags not present" );

        if( *(typeTagsBegin_ + 1) == '\0' ){
            // zero length type tags
            typeTagsBegin_ = 0;
            typeTagsEnd_ = 0;
            arguments_ = 0;

        }else{
            // check that all arguments are present and well formed
                
            arguments_ = FindStr4End( typeTagsBegin_, end );
            if( arguments_ == 0 ){
                throw MalformedMessageException( "type tags were not terminated before end of message" );
            }

            ++typeTagsBegin_; // advance past initial ','
            
            const char *typeTag = typeTagsBegin_;
            const char *argument = arguments_;
                        
            do{
                switch( *typeTag ){
                    case TRUE_TYPE_TAG:
                    case FALSE_TYPE_TAG:
                    case NIL_TYPE_TAG:
                    case INFINITUM_TYPE_TAG:
                    case ARRAY_START_TYPE_TAG:
                    case ARRAY_END_TYPE_TAG:

                        // zero length
                        break;

                    case INT32_TYPE_TAG:
                    case FLOAT_TYPE_TAG:
                    case CHAR_TYPE_TAG:
                    case RGBA_COLOR_TYPE_TAG:
                    case MIDI_MESSAGE_TYPE_TAG:

                        if( argument == end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        argument += 4;
                        if( argument > end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        break;

                    case INT64_TYPE_TAG:
                    case TIME_TAG_TYPE_TAG:
                    case DOUBLE_TYPE_TAG:

                        if( argument == end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        argument += 8;
                        if( argument > end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        break;

                    case STRING_TYPE_TAG: 
                    case SYMBOL_TYPE_TAG:
                    
                        if( argument == end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        argument = FindStr4End( argument, end );
                        if( argument == 0 )
                            throw MalformedMessageException( "unterminated string argument" );
                        break;

                    case BLOB_TYPE_TAG:
                        {
                            if( argument + 4 > end )
                                MalformedMessageException( "arguments exceed message size" );
                                
                            uint32 blobSize = ToUInt32( argument );
                            argument = argument + 4 + RoundUp4( (unsigned long)blobSize );
                            if( argument > end )
                                MalformedMessageException( "arguments exceed message size" );
                        }
                        break;
                        
                    default:
                        throw MalformedMessageException( "unknown type tag" );

                    //    not handled:
                    //    [ Indicates the beginning of an array. The tags following are for
                    //        data in the Array until a close brace tag is reached.
                    //    ] Indicates the end of an array.
                }

            }while( *++typeTag != '\0' );
            typeTagsEnd_ = typeTag;
        }
    }
}
コード例 #3
0
void ReceivedMessageArgumentIterator::Advance()
{
    if( !value_.typeTagPtr_ )
        return;
        
    switch( *value_.typeTagPtr_++ ){
        case '\0':
            // don't advance past end
            --value_.typeTagPtr_;
            break;
            
        case TRUE_TYPE_TAG:
        case FALSE_TYPE_TAG:
        case NIL_TYPE_TAG:
        case INFINITUM_TYPE_TAG:
        
            // zero length
            break;

        case INT32_TYPE_TAG:
        case FLOAT_TYPE_TAG: 					
        case CHAR_TYPE_TAG:
        case RGBA_COLOR_TYPE_TAG:
        case MIDI_MESSAGE_TYPE_TAG:

            value_.argumentPtr_ += 4;
            break;

        case INT64_TYPE_TAG:
        case TIME_TAG_TYPE_TAG:
        case DOUBLE_TYPE_TAG:
				
            value_.argumentPtr_ += 8;
            break;

        case STRING_TYPE_TAG: 
        case SYMBOL_TYPE_TAG:

            // we use the unsafe function FindStr4End(char*) here because all of
            // the arguments have already been validated in
            // ReceivedMessage::Init() below.
            
            value_.argumentPtr_ = FindStr4End( value_.argumentPtr_ );
            break;

        case BLOB_TYPE_TAG:
            {
                // treat blob size as an unsigned int for the purposes of this calculation
                uint32 blobSize = ToUInt32( value_.argumentPtr_ );
                value_.argumentPtr_ = value_.argumentPtr_ + osc::OSC_SIZEOF_INT32 + RoundUp4( blobSize );
            }
            break;

        case ARRAY_BEGIN_TYPE_TAG:
        case ARRAY_END_TYPE_TAG: 

            //    [ Indicates the beginning of an array. The tags following are for
            //        data in the Array until a close brace tag is reached.
            //    ] Indicates the end of an array.

            // zero length, don't advance argument ptr
            break;

        default:    // unknown type tag
            // don't advance
            --value_.typeTagPtr_;
            break;
    }
}
コード例 #4
0
void ReceivedMessage::Init( const char *message, osc_bundle_element_size_t size )
{
    if( !IsValidElementSizeValue(size) )
        throw MalformedMessageException( "invalid message size" );

    if( size == 0 )
        throw MalformedMessageException( "zero length messages not permitted" );

    if( !IsMultipleOf4(size) )
        throw MalformedMessageException( "message size must be multiple of four" );

    const char *end = message + size;

    typeTagsBegin_ = FindStr4End( addressPattern_, end );
    if( typeTagsBegin_ == 0 ){
        // address pattern was not terminated before end
        throw MalformedMessageException( "unterminated address pattern" );
    }

    if( typeTagsBegin_ == end ){
        // message consists of only the address pattern - no arguments or type tags.
        typeTagsBegin_ = 0;
        typeTagsEnd_ = 0;
        arguments_ = 0;
            
    }else{
        if( *typeTagsBegin_ != ',' )
            throw MalformedMessageException( "type tags not present" );

        if( *(typeTagsBegin_ + 1) == '\0' ){
            // zero length type tags
            typeTagsBegin_ = 0;
            typeTagsEnd_ = 0;
            arguments_ = 0;

        }else{
            // check that all arguments are present and well formed
                
            arguments_ = FindStr4End( typeTagsBegin_, end );
            if( arguments_ == 0 ){
                throw MalformedMessageException( "type tags were not terminated before end of message" );
            }

            ++typeTagsBegin_; // advance past initial ','
            
            const char *typeTag = typeTagsBegin_;
            const char *argument = arguments_;
            unsigned int arrayLevel = 0;
                        
            do{
                switch( *typeTag ){
                    case TRUE_TYPE_TAG:
                    case FALSE_TYPE_TAG:
                    case NIL_TYPE_TAG:
                    case INFINITUM_TYPE_TAG:
                        // zero length
                        break;

                    //    [ Indicates the beginning of an array. The tags following are for
                    //        data in the Array until a close brace tag is reached.
                    //    ] Indicates the end of an array.
                    case ARRAY_BEGIN_TYPE_TAG:
                        ++arrayLevel;
                        // (zero length argument data)
                        break;

                    case ARRAY_END_TYPE_TAG:
                        --arrayLevel;
                        // (zero length argument data)
                        break;

                    case INT32_TYPE_TAG:
                    case FLOAT_TYPE_TAG:
                    case CHAR_TYPE_TAG:
                    case RGBA_COLOR_TYPE_TAG:
                    case MIDI_MESSAGE_TYPE_TAG:

                        if( argument == end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        argument += 4;
                        if( argument > end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        break;

                    case INT64_TYPE_TAG:
                    case TIME_TAG_TYPE_TAG:
                    case DOUBLE_TYPE_TAG:

                        if( argument == end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        argument += 8;
                        if( argument > end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        break;

                    case STRING_TYPE_TAG: 
                    case SYMBOL_TYPE_TAG:
                    
                        if( argument == end )
                            throw MalformedMessageException( "arguments exceed message size" );
                        argument = FindStr4End( argument, end );
                        if( argument == 0 )
                            throw MalformedMessageException( "unterminated string argument" );
                        break;

                    case BLOB_TYPE_TAG:
                        {
                            if( argument + osc::OSC_SIZEOF_INT32 > end )
                                MalformedMessageException( "arguments exceed message size" );
                                
                            // treat blob size as an unsigned int for the purposes of this calculation
                            uint32 blobSize = ToUInt32( argument );
                            argument = argument + osc::OSC_SIZEOF_INT32 + RoundUp4( blobSize );
                            if( argument > end )
                                MalformedMessageException( "arguments exceed message size" );
                        }
                        break;
                        
                    default:
                        throw MalformedMessageException( "unknown type tag" );
                }

            }while( *++typeTag != '\0' );
            typeTagsEnd_ = typeTag;

            if( arrayLevel !=  0 )
                throw MalformedMessageException( "array was not terminated before end of message (expected ']' end of array tag)" );
        }

        // These invariants should be guaranteed by the above code.
        // we depend on them in the implementation of ArgumentCount()
#ifndef NDEBUG
        std::ptrdiff_t argumentCount = typeTagsEnd_ - typeTagsBegin_;
        assert( argumentCount >= 0 );
        assert( argumentCount <= OSC_INT32_MAX );
#endif
    }
}
コード例 #5
0
void ReceivedMessageArgumentIterator::Advance()
{
    if( !value_.typeTag_ )
        return;
        
    switch( *value_.typeTag_++ ){
        case '\0':
            // don't advance past end
            --value_.typeTag_;
            break;
            
        case TRUE_TYPE_TAG:
        case FALSE_TYPE_TAG:
        case NIL_TYPE_TAG:
        case INFINITUM_TYPE_TAG:

            // zero length
            break;

        case INT32_TYPE_TAG:
        case FLOAT_TYPE_TAG: 					
        case CHAR_TYPE_TAG:
        case RGBA_COLOR_TYPE_TAG:
        case MIDI_MESSAGE_TYPE_TAG:

            value_.argument_ += 4;
            break;

        case INT64_TYPE_TAG:
        case TIME_TAG_TYPE_TAG:
        case DOUBLE_TYPE_TAG:
				
            value_.argument_ += 8;
            break;

        case STRING_TYPE_TAG: 
        case SYMBOL_TYPE_TAG:

            // we use the unsafe function FindStr4End(char*) here because all of
            // the arguments have already been validated in
            // ReceivedMessage::Init() below.
            
            value_.argument_ = FindStr4End( value_.argument_ );
            break;

        case BLOB_TYPE_TAG:
            {
                uint32 blobSize = ToUInt32( value_.argument_ );
                value_.argument_ = value_.argument_ + 4 + RoundUp4( (unsigned long)blobSize );
            }
            break;

        default:    // unknown type tag
            // don't advance
            --value_.typeTag_;
            break;
            

        //    not handled:
        //    [ Indicates the beginning of an array. The tags following are for
        //        data in the Array until a close brace tag is reached.
        //    ] Indicates the end of an array.
    }
}