Java Code Examples for org.apache.mina.core.buffer.IoBuffer#putEnumSetShort()

The following examples show how to use org.apache.mina.core.buffer.IoBuffer#putEnumSetShort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtocolEncoderImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void encodeEntry ( final IoSession session, final IoBuffer data, final Entry entry ) throws ProtocolCodecException
{
    data.putUnsignedShort ( entry.getRegister () );
    data.put ( entry.getMissedUpdates () );
    data.putLong ( entry.getTimestamp () );
    data.putEnumSetShort ( entry.getStates () );

    // put payload
    encodeVariant ( session, data, entry.getValue () );
}
 
Example 2
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public <E extends Enum<E>> void encodeEnumSet ( final IoBuffer buffer, final byte fieldNumber, final Set<E> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_ENUM_SET );
        buffer.putEnumSetShort ( data );
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
Example 3
Source File: ProtocolEncoderImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
    IoBuffer data = null;
    if ( message instanceof Hello )
    {
        data = createMessage ( session, Messages.MC_HELLO, true );

        data.put ( (byte)0x01 ); // version

        data.putShort ( ( (Hello)message ).getNodeId () );
        data.putEnumSetShort ( ( (Hello)message ).getFeatures () );

        data.putUnsignedShort ( 3, data.position () - 3 ); // fill length
    }
    else if ( message instanceof Welcome )
    {
        data = createMessage ( session, Messages.MC_WELCOME, true );

        // put bit set
        data.putEnumSetShort ( ( (Welcome)message ).getFeatures () );
        encodeProperties ( data, ( (Welcome)message ).getProperties () );

        data.putUnsignedShort ( 3, data.position () - 3 ); // fill length
    }
    else if ( message instanceof ReadAll )
    {
        data = createMessage ( session, Messages.MC_READ_ALL, false );

    }
    else if ( message instanceof DataUpdate )
    {
        data = createMessage ( session, Messages.MC_DATA_UPDATE, true );

        data.putUnsignedShort ( ( (DataUpdate)message ).getEntries ().size () );
        // put values
        for ( final DataUpdate.Entry entry : ( (DataUpdate)message ).getEntries () )
        {
            encodeEntry ( session, data, entry );
        }

        data.putUnsignedShort ( 3, data.position () - 3 ); // fill length
    }
    else if ( message instanceof SubscribeBrowse )
    {
        data = createMessage ( session, Messages.MC_START_BROWSE, false );
    }
    else if ( message instanceof UnsubscribeBrowse )
    {
        data = createMessage ( session, Messages.MC_STOP_BROWSE, false );
    }
    else if ( message instanceof BrowseAdded )
    {
        data = createMessage ( session, Messages.MC_NS_ADDED, true );

        // put browse update
        encodeBrowseUpdate ( session, message, data );

        data.putUnsignedShort ( 3, data.position () - 3 ); // fill length
    }
    else if ( message instanceof WriteCommand )
    {
        data = createMessage ( session, Messages.MC_WRITE_COMMAND, true );

        data.putUnsignedShort ( ( (WriteCommand)message ).getRegisterNumber () );
        data.putInt ( ( (WriteCommand)message ).getOperationId () );
        encodeVariant ( session, data, ( (WriteCommand)message ).getValue () );

        data.putUnsignedShort ( 3, data.position () - 3 ); // fill length
    }
    else if ( message instanceof WriteResult )
    {
        data = createMessage ( session, Messages.MC_WRITE_RESULT, true );

        data.putInt ( ( (WriteResult)message ).getOperationId () );
        data.putUnsignedShort ( ( (WriteResult)message ).getErrorCode () );

        data.putPrefixedString ( ( (WriteResult)message ).getErrorMessage (), Sessions.getCharsetEncoder ( session ) );

        data.putUnsignedShort ( 3, data.position () - 3 ); // fill length
    }

    if ( data != null )
    {
        data.flip ();
        out.write ( data );
    }
    else
    {
        throw new ProtocolCodecException ( String.format ( "Message %s is not supported", message.getClass ().getName () ) );
    }
}