/// <summary> /// Construct a new broadcast receiver based on an underlying <seealso cref="IAtomicBuffer"/>. /// The underlying buffer must a power of 2 in size plus sufficient space /// for the <seealso cref="BroadcastBufferDescriptor.TrailerLength"/>. /// </summary> /// <param name="buffer"> via which messages will be exchanged. </param> /// <exception cref="InvalidOperationException"> if the buffer capacity is not a power of 2 /// plus <seealso cref="BroadcastBufferDescriptor.TrailerLength"/> in capacity. </exception> public BroadcastReceiver(IAtomicBuffer buffer) { _buffer = buffer; _capacity = buffer.Capacity - BroadcastBufferDescriptor.TrailerLength; BroadcastBufferDescriptor.CheckCapacity(_capacity); buffer.VerifyAlignment(); _tailIntentCounterIndex = _capacity + BroadcastBufferDescriptor.TailIntentCounterOffset; _tailCounterIndex = _capacity + BroadcastBufferDescriptor.TailCounterOffset; _latestCounterIndex = _capacity + BroadcastBufferDescriptor.LatestCounterOffset; }
/// <summary> /// Construct a new broadcast receiver based on an underlying <seealso cref="IAtomicBuffer"/>. /// The underlying buffer must a power of 2 in size plus sufficient space /// for the <seealso cref="BroadcastBufferDescriptor.TrailerLength"/>. /// </summary> /// <param name="buffer"> via which messages will be exchanged. </param> /// <exception cref="InvalidOperationException"> if the buffer capacity is not a power of 2 /// plus <seealso cref="BroadcastBufferDescriptor.TrailerLength"/> in capacity. </exception> public BroadcastReceiver(IAtomicBuffer buffer) { _buffer = buffer; _capacity = buffer.Capacity - BroadcastBufferDescriptor.TrailerLength; BroadcastBufferDescriptor.CheckCapacity(_capacity); buffer.VerifyAlignment(); _tailIntentCounterIndex = _capacity + BroadcastBufferDescriptor.TailIntentCounterOffset; _tailCounterIndex = _capacity + BroadcastBufferDescriptor.TailCounterOffset; _latestCounterIndex = _capacity + BroadcastBufferDescriptor.LatestCounterOffset; _cursor = _nextRecord = buffer.GetLongVolatile(_latestCounterIndex); _recordOffset = (int)_cursor & (_capacity - 1); }