Skip to content

PgCStringView

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Borrows the exact bytes of a PostgreSQL cstring under a checked native lifetime.

public sealed class PgCStringView : IReadOnlyList<byte>, IReadOnlyCollection<byte>, IEnumerable<byte>, IEnumerable, IDisposable

Bytes are not implicitly decoded or transcoded. Count, indexing and enumeration exclude the terminator. The source owner must remain alive; direct scalar input views expire at callback exit. Copied length and type metadata remain readable after disposal. Dispose explicitly created views while their backend is active.

Inheritance: object

Implements: IReadOnlyList<byte>, IReadOnlyCollection<byte>, IEnumerable<byte>, IEnumerable, IDisposable

Borrows the exact bytes of a PostgreSQL cstring under a checked native lifetime.

public PgCStringView(PgDatum value)

Parameters:

value — PgDatum

The present cstring datum with valid terminated native storage.

Bytes are not implicitly decoded or transcoded. Count, indexing and enumeration exclude the terminator. The source owner must remain alive; direct scalar input views expire at callback exit. Copied length and type metadata remain readable after disposal. Dispose explicitly created views while their backend is active.

Copies the entire payload after checking its lifetime and the destination capacity.

public void CopyTo(Span<byte> destination)

Parameters:

destination — Span<byte>

Storage large enough for Count bytes.

Checks the native lifetime and exposes the payload with its terminating zero byte.

public ReadOnlySpan<byte> DangerousGetNullTerminatedSpan()

Returns: ReadOnlySpan<byte>

A span whose validity is the caller’s responsibility after this method returns.

Obey the same lifetime and backend-thread restrictions as DangerousGetSpan.

Checks the lifetime once and exposes the native payload without copying.

public ReadOnlySpan<byte> DangerousGetSpan()

Returns: ReadOnlySpan<byte>

A span whose validity is the caller’s responsibility after this method returns.

Never reset or delete the source owner, dispose this view, or exit its callback while using the span. Keep it on the originating backend thread and do not retain it across backend calls. The span cannot check subsequent native lifetime changes; prefer checked indexing or copies.

Releases private storage and invalidates this view and its enumerators.

public void Dispose()

Creates an independent cursor that checks the native lifetime on every access.

public IEnumerator<byte> GetEnumerator()

Returns: IEnumerator<byte>

A byte enumerator that does not own the underlying view.

Copies the payload into an independent managed array.

public byte[] ToArray()

Returns: byte[]

Bytes that remain valid after the native owner expires.

Copies the exact payload into an independent managed C string.

public PgCString ToOwned()

Returns: PgCString

The owned value, valid after the native owner expires.

Checks the native lifetime and decodes strict UTF-8 without consulting the server encoding.

public string ToUtf8String()

Returns: string

Independent managed text.

Exceptions:

Gets the payload length, excluding the terminating zero byte.

public int Count { get; }

Value: int

Gets the checked datum, valid until this view or its source expires.

public PgDatum Datum { get; }

Value: PgDatum

Reads one byte after checking the native lifetime and zero-based index.

public byte this[int index] { get; }

Parameters:

index — int

The zero-based byte index.

Value: byte

The original nonzero payload byte.

Gets the PostgreSQL cstring type OID.

public uint TypeOid { get; }

Value: uint