moonbit-community/postgres/protocol does not have a README file

    Lsn

    type Lsn = UInt64

    A PostgreSQL Log Sequence Number (LSN).

    On the wire this is a big-endian 64-bit unsigned integer.

    Oid

    type Oid = UInt

    A PostgreSQL object identifier.

    OIDs are transmitted on the wire as 32-bit unsigned integers and appear in messages such as ParameterDescription and RowDescription.

    ProtocolError

    pub(all) suberror ProtocolError {
    InvalidInput(String)
    UnexpectedEof(String)
    Overflow(String)
    } derive(Eq,
    Debug
    )

    Shared protocol primitives.

    Primary reference:
    • https://www.postgresql.org/docs/current/protocol-overview.html#PROTOCOL-OVERVIEW
    • https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS Protocol error type used when a packet violates the wire-level invariants described in PostgreSQL protocol Sections 54.6 and 54.7.

    ByteReader

    pub struct ByteReader {
    buf : BytesView
    idx : Int
    }

    Cursor-based reader for the scalar types from protocol Section 54.6.

    All integer reads use network byte order, and read_cstr implements the protocol String type (a NUL-terminated byte sequence).

    ByteReader::is_empty

    fn ByteReader::is_empty(self : ByteReader) -> Bool

    Return whether all bytes have been consumed.

    ByteReader::new

    fn ByteReader::new(buf : BytesView) -> ByteReader

    Create a byte reader over buf.

    ByteReader::read_all

    fn ByteReader::read_all(self : ByteReader) -> BytesView

    Consume and return all remaining bytes.

    Many message formats end with Byte n, where n is implied by the overall message length. This helper returns that trailing payload.

    ByteReader::read_bytes

    fn ByteReader::read_bytes(self : ByteReader, len : Int) -> BytesView raise ProtocolError

    Read the next len bytes from a preceding Byte n or length-prefixed field.

    ByteReader::read_cstr

    fn ByteReader::read_cstr(self : ByteReader) -> Bytes raise ProtocolError

    Read a protocol String.

    PostgreSQL protocol strings are C-style NUL-terminated byte sequences with no separate length prefix.

    ByteReader::read_f32_be

    fn ByteReader::read_f32_be(self : ByteReader) -> Float raise ProtocolError

    Read the next big-endian IEEE-754 Float.

    ByteReader::read_f64_be

    fn ByteReader::read_f64_be(self : ByteReader) -> Double raise ProtocolError

    Read the next big-endian IEEE-754 Double.

    ByteReader::read_i16_be

    fn ByteReader::read_i16_be(self : ByteReader) -> Int raise ProtocolError

    Read the next big-endian signed 16-bit integer.

    ByteReader::read_i32_be

    fn ByteReader::read_i32_be(self : ByteReader) -> Int raise ProtocolError

    Read the next big-endian signed 32-bit integer.

    ByteReader::read_i64_be

    fn ByteReader::read_i64_be(self : ByteReader) -> Int64 raise ProtocolError

    Read the next big-endian signed 64-bit integer.

    ByteReader::read_u16_be

    fn ByteReader::read_u16_be(self : ByteReader) -> UInt16 raise ProtocolError

    Read the next big-endian unsigned 16-bit integer.

    ByteReader::read_u32_be

    fn ByteReader::read_u32_be(self : ByteReader) -> UInt raise ProtocolError

    Read the next big-endian unsigned 32-bit integer.

    ByteReader::read_u64_be

    fn ByteReader::read_u64_be(self : ByteReader) -> UInt64 raise ProtocolError

    Read the next big-endian unsigned 64-bit integer.

    ByteReader::read_u8

    fn ByteReader::read_u8(self : ByteReader) -> Byte raise ProtocolError

    Read the next byte.

    ByteReader::remaining

    fn ByteReader::remaining(self : ByteReader) -> Int

    Return the number of unread bytes.

    IsNull

    pub(all) enum IsNull {
    Yes
    No
    }

    Whether a length-prefixed value is present.

    PostgreSQL uses a signed Int32 length field for many values. -1 denotes SQL NULL, while any non-negative value is followed by exactly that many payload bytes.

    checked_i16

    fn checked_i16(value : Int) -> Int16 raise ProtocolError

    Ensure a value fits in the signed 16-bit range accepted by wire Int16 fields.

    checked_i32

    fn checked_i32(value : Int) -> Int raise ProtocolError

    Ensure a value fits in the signed 32-bit range accepted by wire Int32 fields.

    i16_from_usize

    fn i16_from_usize(len : Int) -> Int16 raise ProtocolError

    Wire-level scalar decoding helpers for PostgreSQL protocol values.

    Primary references:
    • https://www.postgresql.org/docs/current/protocol-overview.html#PROTOCOL-OVERVIEW
    • https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS Convert a count to the signed 16-bit representation used by many protocol fields, such as parameter counts and format-code counts.

    i32_from_u32

    fn i32_from_u32(value : UInt) -> Int

    Convert u32 bits to signed i32 (stored in Int).

    i32_from_usize

    fn i32_from_usize(len : Int) -> Int raise ProtocolError

    Convert a length to the signed 32-bit representation used by PostgreSQL length fields.

    Whether the resulting value includes the length word itself depends on the surrounding message format.

    u32_from_i32

    fn u32_from_i32(value : Int) -> UInt raise ProtocolError

    Convert signed i32 (stored in Int) to u32 bits in UInt.

    utf8_encode

    fn utf8_encode(s : String) -> Bytes

    Encode a String (UTF-16) as UTF-8 bytes.

    validate_utf8

    fn validate_utf8(bytes : BytesView) -> Unit raise ProtocolError

    Validate that bytes are valid UTF-8.

    The higher-level client requests client_encoding=UTF8, so protocol strings and textual values handled by this package are expected to pass this check.

    write_nullable

    Helpers for PostgreSQL's repeated Int32 length + payload layout.

    Primary reference:
    • https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-BIND
    • https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-DATAROW Write one nullable Int32 + Byte n field.

    This is the value layout used by Bind parameters, DataRow columns, and several composite binary payloads. The serializer writes only the payload bytes; this helper prepends the length word and emits -1 for NULL.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io