Skip to main content

Class FifoBuffer

This FIFO buffer is implemented as a circular buffer. (Standard computer science stuff) It operates on bytes. The only special method is WriteString, which writes a string to the buffer after converting it with Encoding.ASCII.GetBytes().

Assembly: Sc16is7x2.dll​
View Source​
Declaration
public class FifoBuffer

Properties​

Capacity​

The number of bytes that can be stored in the buffer.

View Source​
Declaration
public int Capacity { get; }

Count​

The number of bytes currently stored in the buffer. Increases with Write() and decreases with Read().

View Source​
Declaration
public int Count { get; }

this[int]​

Peek at element at index, relative to the _nextRead position. The byte at relative index 0 is the oldest one, so looking at [0] is the same as Peek().

View Source​
Declaration
public byte this[int index] { get; }

Methods​

Clear()​

Clear/empty the FIFO buffer.

View Source​
Declaration
public void Clear()

Write(byte)​

Add new item to the _nestWrite position in the buffer. Then move the _nextWrite position. If it goes beyond the capacity, it will wrap around to 0. If you try to write more data than the capacity, it will throw an error.

View Source​
Declaration
public void Write(byte item)
Parameters​
TypeName
System.Byteitem
Exceptions​

System.InvalidOperationException

Read()​

Method to remove and return the oldest item. The one at the _nextRead position. The _nextRead position will be moved. If it goes beyond the capacity, it will wrap around to 0. If you try to read from an empty buffer, it will throw an error.

View Source​
Declaration
public byte Read()
Returns​

System.Byte

Exceptions​

System.InvalidOperationException

Peek()​

Method to just return the oldest item. The one at the _nextRead position. (Withoit removing it) If the buffer is empty, it will throw an error.

View Source​
Declaration
public byte Peek()
Returns​

System.Byte

Exceptions​

System.InvalidOperationException

WriteString(string)​

Bonus method to add a string to the buffer. Each character in the string will be converted to a byte and written to the buffer. This method can be usefull if you need to tag some data written to the buffer with a string.

View Source​
Declaration
public void WriteString(string text)
Parameters​
TypeName
System.Stringtext