コード例 #1
0
ファイル: TermAppender.java プロジェクト: ezrover/Aeron
  private void applyDefaultHeader(
      final UnsafeBuffer buffer,
      final int termOffset,
      final int frameLength,
      final long defaultVersionFlagsType,
      final long defaultSessionId) {
    long lengthVersionFlagsType;
    long termOffsetAndSessionId;

    if (ByteOrder.nativeOrder() == LITTLE_ENDIAN) {
      lengthVersionFlagsType = defaultVersionFlagsType | ((-frameLength) & 0xFFFF_FFFFL);
      termOffsetAndSessionId = defaultSessionId | termOffset;
    } else {
      lengthVersionFlagsType =
          (((reverseBytes(-frameLength)) & 0xFFFF_FFFFL) << 32) | defaultVersionFlagsType;
      termOffsetAndSessionId =
          (((reverseBytes(termOffset)) & 0xFFFF_FFFFL) << 32) | defaultSessionId;
    }

    buffer.putLongOrdered(termOffset + FRAME_LENGTH_FIELD_OFFSET, lengthVersionFlagsType);
    UnsafeAccess.UNSAFE.storeFence();

    buffer.putLong(termOffset + TERM_OFFSET_FIELD_OFFSET, termOffsetAndSessionId);

    // read the stream(int) and term(int), this is the mutable part of the default header
    final long streamAndTermIds = defaultHeader.getLong(STREAM_ID_FIELD_OFFSET);
    buffer.putLong(termOffset + STREAM_ID_FIELD_OFFSET, streamAndTermIds);
  }