Java Code Examples for org.agrona.DirectBuffer#wrap()

The following examples show how to use org.agrona.DirectBuffer#wrap() . 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: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapCharacterEncoding(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 2
Source File: FrameCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapSemanticVersion(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 3
Source File: FrameCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapNamespaceName(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 4
Source File: FrameCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapPackageName(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 5
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapReferencedName(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 6
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapDescription(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 7
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapSemanticType(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 8
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapTimeUnit(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 9
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapEpoch(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 10
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapNullValue(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 11
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapMaxValue(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 12
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapMinValue(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 13
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapConstValue(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 14
Source File: TokenCodecDecoder.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
public void wrapName(final DirectBuffer wrapBuffer)
{
    final int headerLength = 2;
    final int limit = parentMessage.limit();
    final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF);
    parentMessage.limit(limit + headerLength + dataLength);
    wrapBuffer.wrap(buffer, limit + headerLength, dataLength);
}
 
Example 15
Source File: SequenceNumberIndexReader.java    From artio with Apache License 2.0 5 votes vote down vote up
public MetaDataStatus readMetaData(final long sessionId, final DirectBuffer buffer)
{
    if (metaDataFile == null)
    {
        return MetaDataStatus.FILE_ERROR;
    }

    if (lastKnownSequenceNumber(sessionId) == UNK_SESSION)
    {
        return MetaDataStatus.UNKNOWN_SESSION;
    }

    final int metaDataPosition = lastKnownDecoder.metaDataPosition();
    if (metaDataPosition == NO_META_DATA)
    {
        return MetaDataStatus.NO_META_DATA;
    }

    try
    {
        metaDataFile.seek(metaDataPosition);
        final int metaDataLength = metaDataFile.readInt();

        final byte[] metaDataValue = new byte[metaDataLength];
        metaDataFile.read(metaDataValue);

        buffer.wrap(metaDataValue);

        return MetaDataStatus.OK;
    }
    catch (final IOException e)
    {
        errorHandler.onError(e);
        return MetaDataStatus.FILE_ERROR;
    }
}
 
Example 16
Source File: DirectBufferProxy.java    From lmdbjava with Apache License 2.0 5 votes vote down vote up
@Override
protected DirectBuffer out(final DirectBuffer buffer, final Pointer ptr,
                           final long ptrAddr) {
  final long addr = UNSAFE.getLong(ptrAddr + STRUCT_FIELD_OFFSET_DATA);
  final long size = UNSAFE.getLong(ptrAddr + STRUCT_FIELD_OFFSET_SIZE);
  buffer.wrap(addr, (int) size);
  return buffer;
}
 
Example 17
Source File: SbeResponseMessageFactory.java    From conga with Apache License 2.0 4 votes vote down vote up
@Override
public Message wrap(ByteBuffer buffer) throws MessageException {
  final DirectBuffer directBuffer = bufferThreadLocal.get();
  directBuffer.wrap(buffer);
  final var messageHeaderDecoder = headerThreadLocal.get();
  final int offset = buffer.position();
  messageHeaderDecoder.wrap(directBuffer, offset);
  int blockLength = messageHeaderDecoder.blockLength();
  int templateId = messageHeaderDecoder.templateId();
  int schemaId = messageHeaderDecoder.schemaId();
  int schemaVersion = messageHeaderDecoder.version();

  switch (schemaId) {
    case OrderCancelRejectDecoder.SCHEMA_ID:
      switch (templateId) {
        case OrderCancelRejectDecoder.TEMPLATE_ID:
          final var reject = getOrderCancelReject();
          reject.wrap(buffer, offset + messageHeaderDecoder.encodedLength(), blockLength,
              schemaVersion);
          return reject;
        case ExecutionReportDecoder.TEMPLATE_ID:
          final var execution = getExecutionReport();
          execution.wrap(buffer, offset + messageHeaderDecoder.encodedLength(), blockLength,
              schemaVersion);
          return execution;
        default:
          throw new MessageException("Unknown template");
      }
    case NotAppliedDecoder.SCHEMA_ID:
      switch (templateId) {
        case NotAppliedDecoder.TEMPLATE_ID:
          var notApplied = getNotApplied();
          notApplied.wrap(buffer, offset + messageHeaderDecoder.encodedLength(), blockLength,
              schemaVersion);
          return notApplied;
        default:
          throw new MessageException("Unknown message template");
      }
    default:
      throw new MessageException("Unknown message schema " + schemaId);
  }
}
 
Example 18
Source File: SbeRequestMessageFactory.java    From conga with Apache License 2.0 4 votes vote down vote up
@Override
public Message wrap(ByteBuffer buffer) throws MessageException {
  final DirectBuffer directBuffer = bufferThreadLocal.get();
  directBuffer.wrap(buffer);
  final var messageHeaderDecoder = headerThreadLocal.get();
  final int offset = buffer.position();
  messageHeaderDecoder.wrap(directBuffer, offset);
  int blockLength = messageHeaderDecoder.blockLength();
  int templateId = messageHeaderDecoder.templateId();
  int schemaId = messageHeaderDecoder.schemaId();
  int schemaVersion = messageHeaderDecoder.version();

  switch (schemaId) {
    case NewOrderSingleDecoder.SCHEMA_ID:
      switch (templateId) {
        case NewOrderSingleDecoder.TEMPLATE_ID:
          final var newOrderSingle = getNewOrderSingle();
          newOrderSingle.wrap(buffer, offset + messageHeaderDecoder.encodedLength(), blockLength,
              schemaVersion);
          return newOrderSingle;
        case OrderCancelRequestDecoder.TEMPLATE_ID:
          var orderCancelRequest = getOrderCancelRequest();
          orderCancelRequest.wrap(buffer, offset + messageHeaderDecoder.encodedLength(),
              blockLength, schemaVersion);
          return orderCancelRequest;
        default:
          throw new MessageException("Unknown message template");
      }
    case NotAppliedDecoder.SCHEMA_ID:
      switch (templateId) {
        case NotAppliedDecoder.TEMPLATE_ID:
          var notApplied = getNotApplied();
          notApplied.wrap(buffer, offset + messageHeaderDecoder.encodedLength(), blockLength,
              schemaVersion);
          return notApplied;
        default:
          throw new MessageException("Unknown message template");
      }
    default:
      throw new MessageException("Unknown message schema");
  }
}