Search Results for

    Show / Hide Table of Contents

    Class WssFrameCodec

    Frame codec implementing a SLIP-like protocol:

    • END (0xC0) terminates a frame.
    • ESC (0xDB) escapes special bytes inside the frame.
    • END_SUB (0xDC) represents END when escaped.
    • ESC_SUB (0xDD) represents ESC when escaped.
    Frames on the wire are [sender][target][payload...][checksum][END]. The checksum is computed over all bytes except the last two (checksum + END).
    Inheritance
    object
    WssFrameCodec
    Implements
    IFrameCodec
    Namespace: Wss.CoreModule
    Assembly: WSS_Core_Interface.dll
    Syntax
    public sealed class WssFrameCodec : IFrameCodec

    Methods

    Deframe(byte[])

    Progressive deframer: feed any-size incoming chunks and get back zero or more complete, unescaped frames. Each returned frame has the format [sender][target][payload...][checksum] (END is consumed).

    Declaration
    public IEnumerable<byte[]> Deframe(byte[] chunk)
    Parameters
    Type Name Description
    byte[] chunk

    A raw byte chunk from the transport (may be partial or contain multiple frames).

    Returns
    Type Description
    IEnumerable<byte[]>

    0..N complete, unescaped frames (END removed). Checksum is not validated here.

    Frame(byte, byte, byte[])

    Builds a wire-safe frame for transmission using SLIP-style escaping. Output format (before escaping): [sender][target][payload...][checksum][END].

    Declaration
    public byte[] Frame(byte sender, byte target, byte[] payload)
    Parameters
    Type Name Description
    byte sender

    Sender address byte.

    byte target

    Target/receiver address byte (e.g., device address or broadcast).

    byte[] payload

    The protocol payload (e.g., [cmd][len][...]). The codec does not modify the payload.

    Returns
    Type Description
    byte[]

    Escaped frame ready to send (always terminates with END).

    TryUnescapeAndValidate(ReadOnlySpan<byte>, out byte[])

    Attempts to unescape and validate a single frame (without END), returning false if the checksum does not match. Useful if you want checksum enforcement at the codec layer.

    Declaration
    public static bool TryUnescapeAndValidate(ReadOnlySpan<byte> preEscaped, out byte[] output)
    Parameters
    Type Name Description
    ReadOnlySpan<byte> preEscaped

    Escaped frame bytes (without the END terminator).

    byte[] output

    On success, the unescaped frame [sender][target][payload...][checksum]. On failure, System.Array.Empty<T>() is returned.

    Returns
    Type Description
    bool

    true if the checksum is valid; otherwise false.

    Implements

    IFrameCodec
    In this article
    Back to top Generated by DocFX