Skip to content

AnsiTokenUtf8Serializer ​

Namespace: Hex1b.Tokens

Assembly: Hex1b.dll

Serializes ANSI tokens directly to UTF-8 bytes to avoid allocating intermediate strings.

csharp
public static class AnsiTokenUtf8Serializer

Inheritance ​

Object → AnsiTokenUtf8Serializer

Methods ​

Serialize(AnsiToken) ​

Serializes a single token into a UTF-8 byte buffer.

Parameters:

Returns: ReadOnlyMemory<Byte>

csharp
public static ReadOnlyMemory<byte> Serialize(AnsiToken token)

Serialize(IEnumerable<AnsiToken>) ​

Serializes a list of tokens into a UTF-8 byte buffer.

Parameters:

Returns: ReadOnlyMemory<Byte>

csharp
public static ReadOnlyMemory<byte> Serialize(IEnumerable<AnsiToken> tokens)

SerializeRented(IEnumerable<AnsiToken>, out byte[]) ​

Serializes a list of tokens into a UTF-8 byte buffer backed by an array rented from . The caller MUST return pooledBuffer to the pool when done with the bytes (typically after writing them to the wire). This avoids per-frame Large Object Heap allocations for busy fullscreen renders where the serialised output routinely exceeds the LOH threshold (~85 KB).

Parameters:

  • tokens (IEnumerable<AnsiToken>): The tokens to serialise.
  • pooledBuffer (Byte[]): Receives the rented array. Pass to when finished. Will be null only if tokens contains no bytes.

Returns: ReadOnlyMemory<Byte>

A memory window over the first N bytes of pooledBuffer, where N is the serialised length. The memory becomes invalid once the buffer is returned to the pool.

csharp
public static ReadOnlyMemory<byte> SerializeRented(IEnumerable<AnsiToken> tokens, out byte[] pooledBuffer)

Released under the MIT License.