Vixen
02b45cc4
csharp
public static class Framing

Reads and writes whole messages over a stream.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Length-prefixed, because a stream is not a sequence of messages. A named pipe in byte mode, or a TCP socket, delivers whatever has arrived — which is regularly less than one message and occasionally more than one. A reader that treated one ReadAsync as one message would work for every small mesh and fail for the first big one, which is the worst possible distribution of that bug.

Here rather than in either of its callers. The asset compiler talks to its workers over a pipe and the shader compiler service talks to a device over a socket; both are the engine's serializer with a length in front, and two copies of that would be two chances to get the truncation case wrong.

The prefix is four bytes little-endian, like everything else the serializer writes. A length that is not plausible is refused rather than allocated: the number arrived from another process, and a corrupt or hostile one should not turn into a request for two gigabytes.

Fields and properties (1)

  • public const int MaximumLength

    The largest message that will be read.

Methods (2)

  • public static Task WriteAsync<T>(Stream stream, T value, CancellationToken cancellationToken = default(CancellationToken))

    Writes one message.

  • public static Task<T?> ReadAsync<T>(Stream stream, CancellationToken cancellationToken = default(CancellationToken))

    Reads one message.

Used by (4)

  • RemoteEffectSourceVixen.Shaders
  • ShaderCompilerServerVixen.ShaderCompilerService
  • WorkerVixen.AssetCompiler
  • WorkerHostVixen.AssetCompiler