Skip to content

PgCString

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Owns the exact nonzero bytes of a PostgreSQL cstring and its terminating zero byte.

public sealed class PgCString : IReadOnlyList<byte>, IReadOnlyCollection<byte>, IEnumerable<byte>, IEnumerable, IEquatable<PgCString>, IComparable<PgCString>, IComparable

Bytes are independent of PostgreSQL memory and are not implicitly transcoded. Count, indexing and enumeration exclude the terminator. A null reference represents SQL NULL; an empty instance contains only its terminator. Equality and ordering compare unsigned bytes.

Inheritance: object

Implements: IReadOnlyList<byte>, IReadOnlyCollection<byte>, IEnumerable<byte>, IEnumerable, IEquatable<PgCString>, IComparable<PgCString>, IComparable

Owns the exact nonzero bytes of a PostgreSQL cstring and its terminating zero byte.

public PgCString(ReadOnlySpan<byte> bytes)

Parameters:

bytes — ReadOnlySpan<byte>

The payload without a terminator or embedded zero bytes.

Bytes are independent of PostgreSQL memory and are not implicitly transcoded. Count, indexing and enumeration exclude the terminator. A null reference represents SQL NULL; an empty instance contains only its terminator. Equality and ordering compare unsigned bytes.

Gets readonly managed bytes including exactly one terminating zero byte.

public ReadOnlySpan<byte> AsNullTerminatedSpan()

Returns: ReadOnlySpan<byte>

The complete C string, including the terminator for an empty value.

Gets readonly managed bytes without the terminator.

public ReadOnlySpan<byte> AsSpan()

Returns: ReadOnlySpan<byte>

The payload, independent of any native lifetime.

Compares unsigned payload bytes lexicographically, with null before every present value.

public int CompareTo(PgCString? other)

Parameters:

other — PgCString

The other value, or null.

Returns: int

A negative, zero or positive value for less than, equal to or greater than.

Copies the entire payload without its terminator into a sufficiently large destination.

public void CopyTo(Span<byte> destination)

Parameters:

destination — Span<byte>

Storage for at least Count bytes.

Compares complete payload bytes without decoding or normalization.

public bool Equals(PgCString? other)

Parameters:

other — PgCString

The other value, or null.

Returns: bool

Whether the two present values contain identical bytes.

public override bool Equals(object? obj)

Parameters:

obj — object

Returns: bool

FromNullTerminatedBytes(ReadOnlySpan<byte>)

Section titled “FromNullTerminatedBytes(ReadOnlySpan<byte>)”

Copies a complete C string with exactly one zero byte at its end.

public static PgCString FromNullTerminatedBytes(ReadOnlySpan<byte> bytes)

Parameters:

bytes — ReadOnlySpan<byte>

The payload followed by its required terminator.

Returns: PgCString

An independent value excluding the terminator from Count.

Encodes managed text as strict UTF-8 without consulting the PostgreSQL server encoding.

public static PgCString FromUtf8(string text)

Parameters:

text — string

Text without embedded zero characters or unpaired surrogates.

Returns: PgCString

An independently owned C string.

Enumerates the payload bytes without exposing or including the terminator.

public IEnumerator<byte> GetEnumerator()

Returns: IEnumerator<byte>

An independent managed cursor.

Computes a process-local hash of the exact payload bytes, consistent with equality.

public override int GetHashCode()

Returns: int

The payload hash, unsuitable for persistent PostgreSQL index storage.

Copies the payload without its terminator into independent managed storage.

public byte[] ToArray()

Returns: byte[]

The original payload bytes.

Decodes the bytes as strict UTF-8 without consulting the PostgreSQL server encoding.

public string ToUtf8String()

Returns: string

The decoded text.

Exceptions:

Gets the payload length, excluding the terminating zero byte.

public int Count { get; }

Value: int

Gets a payload byte by its zero-based index, excluding the terminator.

public byte this[int index] { get; }

Parameters:

index — int

The payload byte index.

Value: byte

The original nonzero byte.

Compares two nullable values by their exact payload bytes.

public static bool operator ==(PgCString? left, PgCString? right)

Parameters:

left — PgCString

The first value.

right — PgCString

The second value.

Returns: bool

Whether the values are equal.

Compares nullable values in unsigned byte order.

public static bool operator >(PgCString? left, PgCString? right)

Parameters:

left — PgCString

The first value.

right — PgCString

The second value.

Returns: bool

Whether the first value follows the second.

Compares nullable values in unsigned byte order.

public static bool operator >=(PgCString? left, PgCString? right)

Parameters:

left — PgCString

The first value.

right — PgCString

The second value.

Returns: bool

Whether the first value follows or equals the second.

Compares two nullable values for differing payload bytes.

public static bool operator !=(PgCString? left, PgCString? right)

Parameters:

left — PgCString

The first value.

right — PgCString

The second value.

Returns: bool

Whether the values differ.

Compares nullable values in unsigned byte order.

public static bool operator <(PgCString? left, PgCString? right)

Parameters:

left — PgCString

The first value.

right — PgCString

The second value.

Returns: bool

Whether the first value precedes the second.

Compares nullable values in unsigned byte order.

public static bool operator <=(PgCString? left, PgCString? right)

Parameters:

left — PgCString

The first value.

right — PgCString

The second value.

Returns: bool

Whether the first value precedes or equals the second.