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

The following examples show how to use org.apache.qpid.proton.codec.WritableBuffer#put() . 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: FastPathMessageAnnotationsType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void write(MessageAnnotations val) {
    WritableBuffer buffer = getEncoder().getBuffer();

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

    MapType mapType = (MapType) getEncoder().getType(val.getValue());

    mapType.setKeyEncoding(symbolType);
    try {
        mapType.write(val.getValue());
    } finally {
        mapType.setKeyEncoding(null);
    }
}
 
Example 2
Source File: AmqpReadableBuffer.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
    int start = target.position();

    if (buffer.hasArray()) {
        target.put(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes());
    } else {
        target.put(buffer.nioBuffer());
    }

    int written = target.position() - start;

    buffer.readerIndex(buffer.readerIndex() + written);

    return this;
}
 
Example 3
Source File: ProtonReadableBufferImpl.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
  int start = target.position();

  if (buffer.hasArray()) {
    target.put(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes());
  } else {
    target.put(buffer.nioBuffer());
  }

  int written = target.position() - start;

  buffer.readerIndex(buffer.readerIndex() + written);

  return this;
}
 
Example 4
Source File: NettyReadable.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
   int start = target.position();

   if (buffer.hasArray()) {
      target.put(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes());
   } else {
      target.put(buffer.nioBuffer());
   }

   int written = target.position() - start;

   buffer.readerIndex(buffer.readerIndex() + written);

   return this;
}
 
Example 5
Source File: FastPathApplicationPropertiesType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void write(ApplicationProperties val) {
    WritableBuffer buffer = getEncoder().getBuffer();

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

    MapType mapType = (MapType) getEncoder().getType(val.getValue());

    mapType.setKeyEncoding(stringType);
    try {
        mapType.write(val.getValue());
    } finally {
        mapType.setKeyEncoding(null);
    }
}
 
Example 6
Source File: DeliveryImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
int recv(final WritableBuffer buffer)
{
    final int consumed;
    if (_dataBuffer != null && _dataBuffer.hasRemaining())
    {
        consumed = Math.min(buffer.remaining(), _dataBuffer.remaining());
        buffer.put(_dataBuffer);
        _dataBuffer.reclaimRead();
    }
    else
    {
        consumed = 0;
    }

    return (_complete && consumed == 0) ? Transport.END_OF_STREAM : consumed;
}
 
Example 7
Source File: FastPathDeliveryAnnotationsType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DeliveryAnnotations val) {
    WritableBuffer buffer = getEncoder().getBuffer();

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

    MapType mapType = (MapType) getEncoder().getType(val.getValue());

    mapType.setKeyEncoding(symbolType);
    try {
        mapType.write(val.getValue());
    } finally {
        mapType.setKeyEncoding(null);
    }
}
 
Example 8
Source File: FastPathDataType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Data data) {
    WritableBuffer buffer = getEncoder().getBuffer();
    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    getEncoder().writeBinary(data.getValue());
}
 
Example 9
Source File: FastPathAmqpValueType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void write(AmqpValue value) {
    WritableBuffer buffer = getEncoder().getBuffer();
    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    getEncoder().writeObject(value.getValue());
}
 
Example 10
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Footer val) {
    WritableBuffer buffer = getEncoder().getBuffer();

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

    MapType mapType = (MapType) getEncoder().getType(val.getValue());

    mapType.write(val.getValue());
}
 
Example 11
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void write(AmqpSequence sequence) {
    WritableBuffer buffer = getEncoder().getBuffer();
    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    getEncoder().writeObject(sequence.getValue());
}
 
Example 12
Source File: AmqpReadableBuffer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
   int start = target.position();
   if (this.buffer.hasArray()) {
      target.put(this.buffer.array(), this.buffer.arrayOffset() + this.buffer.position(), this.buffer.remaining());
   } else {
      target.put(this.buffer);
   }

   int written = target.position() - start;
   this.buffer.position(this.buffer.position() + written);
   return this;
}
 
Example 13
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);
}
 
Example 14
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 15
Source File: FastPathAcceptedType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Accepted accepted) {
    WritableBuffer buffer = getEncoder().getBuffer();
    buffer.put(ACCEPTED_ENCODED_BYTES, 0, ACCEPTED_ENCODED_BYTES.length);
}
 
Example 16
Source File: Symbol.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public void writeTo(WritableBuffer buffer)
{
    buffer.put(_underlyingBytes, 0, _underlyingBytes.length);
}
 
Example 17
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 18
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 19
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);
}