コード例 #1
0
  public static int encode(
      final MutableDirectBuffer mutableDirectBuffer,
      final int offset,
      int flags,
      final int keepaliveInterval,
      final int maxLifetime,
      final String metadataMimeType,
      final String dataMimeType,
      final ByteBuffer metadata,
      final ByteBuffer data) {
    final int frameLength =
        computeFrameLength(metadataMimeType, dataMimeType, metadata.remaining(), data.remaining());

    int length =
        FrameHeaderFlyweight.encodeFrameHeader(
            mutableDirectBuffer, offset, frameLength, flags, FrameType.SETUP, 0);

    mutableDirectBuffer.putInt(
        offset + VERSION_FIELD_OFFSET, CURRENT_VERSION, ByteOrder.BIG_ENDIAN);
    mutableDirectBuffer.putInt(
        offset + KEEPALIVE_INTERVAL_FIELD_OFFSET, keepaliveInterval, ByteOrder.BIG_ENDIAN);
    mutableDirectBuffer.putInt(
        offset + MAX_LIFETIME_FIELD_OFFSET, maxLifetime, ByteOrder.BIG_ENDIAN);

    length += BitUtil.SIZE_OF_INT * 3;

    length += putMimeType(mutableDirectBuffer, offset + length, metadataMimeType);
    length += putMimeType(mutableDirectBuffer, offset + length, dataMimeType);

    length +=
        FrameHeaderFlyweight.encodeMetadata(mutableDirectBuffer, offset, offset + length, metadata);
    length += FrameHeaderFlyweight.encodeData(mutableDirectBuffer, offset + length, data);

    return length;
  }
コード例 #2
0
  public static int encode(
      final MutableDirectBuffer mutableDirectBuffer,
      final int offset,
      final int ttl,
      final int numRequests,
      final ByteBuffer metadata) {
    final int frameLength = computeFrameLength(metadata.remaining());

    int length =
        FrameHeaderFlyweight.encodeFrameHeader(
            mutableDirectBuffer, offset, frameLength, 0, FrameType.LEASE, 0);

    mutableDirectBuffer.putInt(offset + TTL_FIELD_OFFSET, ttl, ByteOrder.BIG_ENDIAN);
    mutableDirectBuffer.putInt(
        offset + NUM_REQUESTS_FIELD_OFFSET, numRequests, ByteOrder.BIG_ENDIAN);

    length += BitUtil.SIZE_OF_INT * 2;
    length +=
        FrameHeaderFlyweight.encodeMetadata(mutableDirectBuffer, offset, offset + length, metadata);

    return length;
  }
コード例 #3
0
  public static int computeFrameLength(
      final String metadataMimeType,
      final String dataMimeType,
      final int metadataLength,
      final int dataLength) {
    int length =
        FrameHeaderFlyweight.computeFrameHeaderLength(FrameType.SETUP, metadataLength, dataLength);

    length += BitUtil.SIZE_OF_INT * 3;
    length += 1 + metadataMimeType.getBytes(StandardCharsets.UTF_8).length;
    length += 1 + dataMimeType.getBytes(StandardCharsets.UTF_8).length;

    return length;
  }
コード例 #4
0
  public static int computeFrameLength(final int metadataLength) {
    int length = FrameHeaderFlyweight.computeFrameHeaderLength(FrameType.SETUP, metadataLength, 0);

    return length + BitUtil.SIZE_OF_INT * 2;
  }