Java Code Examples for org.apache.qpid.proton.codec.WritableBuffer#putInt()

The following examples show how to use org.apache.qpid.proton.codec.WritableBuffer#putInt() . 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: FastPathTransferType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Transfer value) {
    WritableBuffer buffer = getEncoder().getBuffer();
    int count = getElementCount(value);
    byte encodingCode = deduceEncodingCode(value, count);

    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    buffer.put(encodingCode);

    final int fieldWidth;

    if (encodingCode == EncodingCodes.LIST8) {
        fieldWidth = 1;
    } else {
        fieldWidth = 4;
    }

    int startIndex = buffer.position();

    // Reserve space for the size and write the count of list elements.
    if (fieldWidth == 1) {
        buffer.put((byte) 0);
        buffer.put((byte) count);
    } else {
        buffer.putInt(0);
        buffer.putInt(count);
    }

    // Write the list elements and then compute total size written.
    for (int i = 0; i < count; ++i) {
        writeElement(value, i);
    }

    // Move back and write the size
    int endIndex = buffer.position();
    int writeSize = endIndex - startIndex - fieldWidth;

    buffer.position(startIndex);
    if (fieldWidth == 1) {
        buffer.put((byte) writeSize);
    } else {
        buffer.putInt(writeSize);
    }
    buffer.position(endIndex);
}
 
Example 2
Source File: FastPathFlowType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Flow flow) {
    WritableBuffer buffer = getEncoder().getBuffer();
    int count = getElementCount(flow);
    byte encodingCode = deduceEncodingCode(flow, count);

    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    buffer.put(encodingCode);

    final int fieldWidth;

    if (encodingCode == EncodingCodes.LIST8) {
        fieldWidth = 1;
    } else {
        fieldWidth = 4;
    }

    int startIndex = buffer.position();

    // Reserve space for the size and write the count of list elements.
    if (fieldWidth == 1) {
        buffer.put((byte) 0);
        buffer.put((byte) count);
    } else {
        buffer.putInt(0);
        buffer.putInt(count);
    }

    // Write the list elements and then compute total size written.
    for (int i = 0; i < count; ++i) {
        writeElement(flow, i);
    }

    // Move back and write the size
    int endIndex = buffer.position();
    int writeSize = endIndex - startIndex - fieldWidth;

    buffer.position(startIndex);
    if (fieldWidth == 1) {
        buffer.put((byte) writeSize);
    } else {
        buffer.putInt(writeSize);
    }
    buffer.position(endIndex);
}
 
Example 3
Source File: FastPathDispositionType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Disposition disposition) {
    WritableBuffer buffer = getEncoder().getBuffer();
    int count = getElementCount(disposition);
    byte encodingCode = deduceEncodingCode(disposition, count);

    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    buffer.put(encodingCode);

    final int fieldWidth;

    if (encodingCode == EncodingCodes.LIST8) {
        fieldWidth = 1;
    } else {
        fieldWidth = 4;
    }

    int startIndex = buffer.position();

    // Reserve space for the size and write the count of list elements.
    if (fieldWidth == 1) {
        buffer.put((byte) 0);
        buffer.put((byte) count);
    } else {
        buffer.putInt(0);
        buffer.putInt(count);
    }

    // Write the list elements and then compute total size written.
    for (int i = 0; i < count; ++i) {
        writeElement(disposition, i);
    }

    // Move back and write the size
    int endIndex = buffer.position();
    int writeSize = endIndex - startIndex - fieldWidth;

    buffer.position(startIndex);
    if (fieldWidth == 1) {
        buffer.put((byte) writeSize);
    } else {
        buffer.putInt(writeSize);
    }
    buffer.position(endIndex);
}
 
Example 4
Source File: FastPathPropertiesType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Properties value) {
    WritableBuffer buffer = getEncoder().getBuffer();
    int count = getElementCount(value);
    byte encodingCode = deduceEncodingCode(value, count);

    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    buffer.put(encodingCode);

    // Optimized step, no other data to be written.
    if (encodingCode == EncodingCodes.LIST0) {
        return;
    }

    final int fieldWidth;

    if (encodingCode == EncodingCodes.LIST8) {
        fieldWidth = 1;
    } else {
        fieldWidth = 4;
    }

    int startIndex = buffer.position();

    // Reserve space for the size and write the count of list elements.
    if (fieldWidth == 1) {
        buffer.put((byte) 0);
        buffer.put((byte) count);
    } else {
        buffer.putInt(0);
        buffer.putInt(count);
    }

    // Write the list elements and then compute total size written.
    for (int i = 0; i < count; ++i) {
        writeElement(value, i);
    }

    // Move back and write the size
    int endIndex = buffer.position();
    int writeSize = endIndex - startIndex - fieldWidth;

    buffer.position(startIndex);
    if (fieldWidth == 1) {
        buffer.put((byte) writeSize);
    } else {
        buffer.putInt(writeSize);
    }
    buffer.position(endIndex);
}
 
Example 5
Source File: FastPathHeaderType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Header value) {
    WritableBuffer buffer = getEncoder().getBuffer();
    int count = getElementCount(value);
    byte encodingCode = deduceEncodingCode(value, count);

    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    buffer.put(encodingCode);

    // Optimized step, no other data to be written.
    if (encodingCode == EncodingCodes.LIST0) {
        return;
    }

    final int fieldWidth;

    if (encodingCode == EncodingCodes.LIST8) {
        fieldWidth = 1;
    } else {
        fieldWidth = 4;
    }

    int startIndex = buffer.position();

    // Reserve space for the size and write the count of list elements.
    if (fieldWidth == 1) {
        buffer.put((byte) 0);
        buffer.put((byte) count);
    } else {
        buffer.putInt(0);
        buffer.putInt(count);
    }

    // Write the list elements and then compute total size written.
    for (int i = 0; i < count; ++i) {
        writeElement(value, i);
    }

    // Move back and write the size
    int endIndex = buffer.position();
    int writeSize = endIndex - startIndex - fieldWidth;

    buffer.position(startIndex);
    if (fieldWidth == 1) {
        buffer.put((byte) writeSize);
    } else {
        buffer.putInt(writeSize);
    }
    buffer.position(endIndex);
}