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, IDisposableBytes 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
Constructors
Section titled “Constructors”PgCStringView(PgDatum)
Section titled “PgCStringView(PgDatum)”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.
Methods
Section titled “Methods”CopyTo(Span<byte>)
Section titled “CopyTo(Span<byte>)”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.
DangerousGetNullTerminatedSpan()
Section titled “DangerousGetNullTerminatedSpan()”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.
DangerousGetSpan()
Section titled “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.
Dispose()
Section titled “Dispose()”Releases private storage and invalidates this view and its enumerators.
public void Dispose()GetEnumerator()
Section titled “GetEnumerator()”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.
ToArray()
Section titled “ToArray()”Copies the payload into an independent managed array.
public byte[] ToArray()Returns: byte[]
Bytes that remain valid after the native owner expires.
ToOwned()
Section titled “ToOwned()”Copies the exact payload into an independent managed C string.
public PgCString ToOwned()Returns: PgCString
The owned value, valid after the native owner expires.
ToUtf8String()
Section titled “ToUtf8String()”Checks the native lifetime and decodes strict UTF-8 without consulting the server encoding.
public string ToUtf8String()Returns: string
Independent managed text.
Exceptions:
- DecoderFallbackException: The bytes are not valid UTF-8.
Properties
Section titled “Properties”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
this[int]
Section titled “this[int]”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.
TypeOid
Section titled “TypeOid”Gets the PostgreSQL cstring type OID.
public uint TypeOid { get; }Value: uint