LogPosition.checked constructor

LogPosition.checked(
  1. Int64 commitPosition,
  2. Int64 preparePosition
)

Constructs a position with the given commit and prepare positions. It is not guaranteed that the position is actually the start of a record in the transaction file.

The commit position cannot be less than the prepare position.

Implementation

factory LogPosition.checked(Int64 commitPosition, Int64 preparePosition) {
  if (commitPosition < preparePosition) {
    throw ArgumentOutOfRangeException.fromCause(GrpcError.outOfRange(
      'The commit position cannot be less than the prepare position',
    ));
  }

  if (commitPosition > Int64.MAX_VALUE && commitPosition != Int64.MAX_VALUE) {
    throw ArgumentOutOfRangeException.fromCause(GrpcError.outOfRange(
      'The commit position larger than Int64.MAX_VALUE',
    ));
  }

  if (preparePosition > Int64.MAX_VALUE &&
      preparePosition != Int64.MAX_VALUE) {
    throw ArgumentOutOfRangeException.fromCause(GrpcError.outOfRange(
      'The prepare position larger than Int64.MAX_VALUE',
    ));
  }
  return LogPosition._(commitPosition, preparePosition);
}