/// <summary> /// Non-blocking receive of next message from the transmission stream. /// <para> /// If loss has occurred then <seealso cref="LappedCount()"/> will be incremented. /// /// </para> /// </summary> /// <returns> true if transmission is available with <seealso cref="Offset()"/>, <seealso cref="Length()"/> and <seealso cref="TypeId()"/> /// set for the next message to be consumed. If no transmission is available then false. </returns> public bool ReceiveNext() { var isAvailable = false; var buffer = _buffer; var tail = buffer.GetLongVolatile(_tailCounterIndex); var cursor = _nextRecord; if (tail > cursor) { var recordOffset = (int)cursor & (_capacity - 1); if (!Validate(cursor)) { _lappedCount.LazySet(_lappedCount.Get() + 1); cursor = buffer.GetLong(_latestCounterIndex); recordOffset = (int)cursor & (_capacity - 1); } _cursor = cursor; _nextRecord = cursor + BitUtil.Align(buffer.GetInt(RecordDescriptor.GetLengthOffset(recordOffset)), RecordDescriptor.RecordAlignment); if (RecordDescriptor.PaddingMsgTypeID == buffer.GetInt(RecordDescriptor.GetTypeOffset(recordOffset))) { recordOffset = 0; _cursor = _nextRecord; _nextRecord += BitUtil.Align(buffer.GetInt(RecordDescriptor.GetLengthOffset(recordOffset)), RecordDescriptor.RecordAlignment); } _recordOffset = recordOffset; isAvailable = true; } return(isAvailable); }
/// <summary> /// The length of the next message in the transmission stream. /// </summary> /// <returns> length of the next message in the transmission stream. </returns> public int Length() { return(_buffer.GetInt(RecordDescriptor.GetLengthOffset(_recordOffset)) - RecordDescriptor.HeaderLength); }