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

The following examples show how to use org.apache.mina.core.buffer.IoBuffer#putDouble() . 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: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void encodeDoubleCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Double> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_DOUBLE_LIST );
        buffer.putInt ( data.size () );
        for ( final Double entry : data )
        {
            buffer.putDouble ( entry );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
Example 2
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void encodeDouble ( final IoBuffer buffer, final byte fieldNumber, final Double data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_DOUBLE );
        buffer.putDouble ( data );
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
Example 3
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void encodePrimitiveDouble ( final IoBuffer buffer, final byte fieldNumber, final double data ) throws Exception
{
    buffer.put ( fieldNumber );
    buffer.put ( TYPE_DOUBLE );
    buffer.putDouble ( data );
}
 
Example 4
Source File: DefaultBinaryContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void inlineEncodeVariant ( final IoBuffer buffer, final Variant variant ) throws Exception
{
    final VariantType type = variant.getType ();
    buffer.putEnum ( type );

    switch ( type )
    {
        case BOOLEAN:
            buffer.put ( variant.asBoolean () ? (byte)0xFF : (byte)0x00 );
            break;
        case DOUBLE:
            buffer.putDouble ( variant.asDouble () );
            break;
        case INT32:
            buffer.putInt ( variant.asInteger () );
            break;
        case INT64:
            buffer.putLong ( variant.asLong () );
            break;
        case STRING:
            buffer.putPrefixedString ( variant.asString (), STRING_PREFIX_LEN, this.encoder );
            break;
        case NULL:
            break;
        case UNKNOWN:
            break;
    }
}
 
Example 5
Source File: DoubleFieldTypeHandler.java    From CXTouch with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void encode(Double value, IoBuffer outBuffer) {
    double val = value;
    outBuffer.put(getType());
    outBuffer.putDouble(val);
}
 
Example 6
Source File: DoubleType.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void putValue ( final IoBuffer slice, final Variant value )
{
    slice.putDouble ( makeValue ( value ) );
}
 
Example 7
Source File: ProtocolEncoderImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
private void encodeVariant ( final IoSession session, final IoBuffer data, final Variant value ) throws ProtocolCodecException
{
    if ( value == null )
    {
        data.put ( DataType.DEAD.getDataType () ); // dead
    }
    else if ( value.isNull () )
    {
        data.put ( DataType.NULL.getDataType () );
    }
    else if ( value.isBoolean () )
    {
        data.put ( DataType.BOOLEAN.getDataType () );
        data.put ( (byte) ( value.asBoolean () ? 0xFF : 0x00 ) );
    }
    else if ( value.isInteger () )
    {
        data.put ( DataType.INT32.getDataType () );
        data.putInt ( value.asInteger ( null ) );
    }
    else if ( value.isLong () )
    {
        data.put ( DataType.INT64.getDataType () );
        data.putLong ( value.asLong ( null ) );
    }
    else if ( value.isDouble () )
    {
        data.put ( DataType.DOUBLE.getDataType () );
        data.putDouble ( value.asDouble ( null ) );
    }
    else if ( value.isString () )
    {
        data.put ( DataType.STRING.getDataType () );
        try
        {
            data.putPrefixedString ( value.asString ( null ), Sessions.getCharsetEncoder ( session ) );
        }
        catch ( final CharacterCodingException e )
        {
            throw new ProtocolCodecException ( e );
        }
    }
}