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>, IComparableBytes 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
Constructors
Section titled “Constructors”PgCString(ReadOnlySpan<byte>)
Section titled “PgCString(ReadOnlySpan<byte>)”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.
Methods
Section titled “Methods”AsNullTerminatedSpan()
Section titled “AsNullTerminatedSpan()”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.
AsSpan()
Section titled “AsSpan()”Gets readonly managed bytes without the terminator.
public ReadOnlySpan<byte> AsSpan()Returns: ReadOnlySpan<byte>
The payload, independent of any native lifetime.
CompareTo(PgCString?)
Section titled “CompareTo(PgCString?)”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.
CopyTo(Span<byte>)
Section titled “CopyTo(Span<byte>)”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.
Equals(PgCString?)
Section titled “Equals(PgCString?)”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.
Equals(object?)
Section titled “Equals(object?)”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.
FromUtf8(string)
Section titled “FromUtf8(string)”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.
GetEnumerator()
Section titled “GetEnumerator()”Enumerates the payload bytes without exposing or including the terminator.
public IEnumerator<byte> GetEnumerator()Returns: IEnumerator<byte>
An independent managed cursor.
GetHashCode()
Section titled “GetHashCode()”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.
ToArray()
Section titled “ToArray()”Copies the payload without its terminator into independent managed storage.
public byte[] ToArray()Returns: byte[]
The original payload bytes.
ToUtf8String()
Section titled “ToUtf8String()”Decodes the bytes as strict UTF-8 without consulting the PostgreSQL server encoding.
public string ToUtf8String()Returns: string
The decoded 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
this[int]
Section titled “this[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.
Operators
Section titled “Operators”operator ==(PgCString?, PgCString?)
Section titled “operator ==(PgCString?, PgCString?)”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.
operator >(PgCString?, PgCString?)
Section titled “operator >(PgCString?, PgCString?)”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.
operator >=(PgCString?, PgCString?)
Section titled “operator >=(PgCString?, PgCString?)”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.
operator !=(PgCString?, PgCString?)
Section titled “operator !=(PgCString?, PgCString?)”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.
operator <(PgCString?, PgCString?)
Section titled “operator <(PgCString?, PgCString?)”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.
operator <=(PgCString?, PgCString?)
Section titled “operator <=(PgCString?, PgCString?)”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.