Class Serial
Serial-line packet framing: SLIP and COBS.
public static class Serial
- Inheritance
-
Serial
- Inherited Members
Remarks
A serial line is a stream of bytes with no packet boundaries, so something has to mark where one message ends and the next begins. Each framing is offered both as a one-shot call over a complete frame and, through SlipDecoder and CobsDecoder, as a streaming decoder for the arbitrary chunks a port delivers. The streaming decoder is what a real read loop uses.
Fields
CobsDelimiter
The byte that delimits a COBS frame, which never appears inside one.
public const byte CobsDelimiter = 0
Field Value
SlipEnd
The SLIP byte that ends a frame (RFC 1055).
public const byte SlipEnd = 192
Field Value
SlipEsc
The SLIP byte that escapes a reserved value inside a frame (RFC 1055).
public const byte SlipEsc = 219
Field Value
SlipEscEnd
The byte that follows an escape to stand for a literal end byte.
public const byte SlipEscEnd = 220
Field Value
SlipEscEsc
The byte that follows an escape to stand for a literal escape byte.
public const byte SlipEscEsc = 221
Field Value
Methods
CobsDecode(ReadOnlySpan<byte>)
Reads the payload back out of a COBS frame.
public static byte[] CobsDecode(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame as it arrived.
Returns
- byte[]
The payload.
Exceptions
- PamojaException
The frame is corrupt.
CobsEncode(ReadOnlySpan<byte>)
Frames a payload as a COBS packet, terminated by its zero delimiter.
public static byte[] CobsEncode(ReadOnlySpan<byte> payload)
Parameters
payloadReadOnlySpan<byte>The bytes to send.
Returns
- byte[]
The frame, delimiter included.
Exceptions
- PamojaException
The native call failed.
CobsMaxEncodedLen(int)
Returns the largest COBS frame a payload of this length can produce.
public static int CobsMaxEncodedLen(int payloadLen)
Parameters
payloadLenintThe payload length in bytes.
Returns
- int
The worst-case frame length.
SlipDecode(ReadOnlySpan<byte>)
Reads the payload back out of a SLIP frame.
public static byte[] SlipDecode(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame as it arrived.
Returns
- byte[]
The payload.
Exceptions
- PamojaException
The frame is corrupt.
SlipEncode(ReadOnlySpan<byte>)
Frames a payload as a SLIP packet (RFC 1055).
public static byte[] SlipEncode(ReadOnlySpan<byte> payload)
Parameters
payloadReadOnlySpan<byte>The bytes to send.
Returns
- byte[]
The frame, delimiter included.
Exceptions
- PamojaException
The native call failed.
SlipMaxEncodedLen(int)
Returns the largest SLIP frame a payload of this length can produce.
public static int SlipMaxEncodedLen(int payloadLen)
Parameters
payloadLenintThe payload length in bytes.
Returns
- int
The worst-case frame length.