Java Code Examples for org.agrona.MutableDirectBuffer#capacity()

The following examples show how to use org.agrona.MutableDirectBuffer#capacity() . 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: SenderAndTargetSessionIdStrategy.java    From artio with Apache License 2.0 6 votes vote down vote up
public int save(final CompositeKey compositeKey, final MutableDirectBuffer buffer, final int offset)
{
    requireNonNull(compositeKey, "compositeKey");
    requireNonNull(buffer, "buffer");

    final String localCompId = compositeKey.localCompId();
    final String remoteCompId = compositeKey.remoteCompId();

    final int length = localCompId.length() + remoteCompId.length() + BLOCK_AND_LENGTH_FIELDS_LENGTH;
    if (buffer.capacity() < offset + length)
    {
        return INSUFFICIENT_SPACE;
    }

    keyEncoder.wrap(buffer, offset);
    keyEncoder.localCompId(localCompId);
    keyEncoder.remoteCompId(remoteCompId);

    return length;
}
 
Example 2
Source File: SenderTargetAndSubSessionIdStrategy.java    From artio with Apache License 2.0 6 votes vote down vote up
public int save(final CompositeKey compositeKey, final MutableDirectBuffer buffer, final int offset)
{
    final String localCompID = compositeKey.localCompId();
    final String localSubID = compositeKey.localSubId();
    final String remoteCompID = compositeKey.remoteCompId();

    final int length =
        localCompID.length() + localSubID.length() + remoteCompID.length() + BLOCK_AND_LENGTH_FIELDS_LENGTH;

    if (buffer.capacity() < offset + length)
    {
        return INSUFFICIENT_SPACE;
    }

    keyEncoder.wrap(buffer, offset);
    keyEncoder.localCompId(localCompID);
    keyEncoder.localSubId(localSubID);
    keyEncoder.remoteCompId(remoteCompID);

    return length;
}
 
Example 3
Source File: CodecUtil.java    From artio with Apache License 2.0 5 votes vote down vote up
public static void toBytes(final CharSequence value, final MutableDirectBuffer buffer)
{
    final int length = value.length();
    if (buffer.capacity() < length)
    {
        buffer.wrap(new byte[length]);
    }

    for (int i = 0; i < length; i++)
    {
        buffer.putByte(i, (byte)value.charAt(i));
    }
}
 
Example 4
Source File: CodecUtil.java    From artio with Apache License 2.0 5 votes vote down vote up
public static void toBytes(
    final char[] value, final MutableDirectBuffer buffer, final int offset, final int length)
{
    if (buffer.capacity() < length)
    {
        buffer.wrap(new byte[length]);
    }

    for (int i = 0; i < length; i++)
    {
        buffer.putByte(i, (byte)value[i + offset]);
    }
}