module PG::Wire
The byte level of PostgreSQL's protocol (version 3): big-endian integers
and NUL-terminated strings, written into a Bytes::Builder and read
from Bytes.
Classes and modules
PG::Wire::ReaderReads big-endian integers, NUL-terminated strings and byte runs from Bytes, front to back. Reading past the end raises PG::ProtocolError.
Class methods
def self.int16(b: Bytes::Builder, n: Int) -> Bytes::Builder
Appends n as a big-endian 16-bit integer (its two's complement when
negative). Raises ArgumentError when n does not fit in 16 bits,
signed or unsigned.
PG::Wire.int16(Bytes::Builder.new, 258).to_bytes # => b"\x01\x02"
PG::Wire.int16(Bytes::Builder.new, -1).to_bytes # => b"\xff\xff"
def self.int32(b: Bytes::Builder, n: Int) -> Bytes::Builder
Appends n as a big-endian 32-bit integer (its two's complement when
negative). Raises ArgumentError when n does not fit in 32 bits,
signed or unsigned.
PG::Wire.int32(Bytes::Builder.new, 196608).to_bytes # => b"\x00\x03\x00\x00"
def self.cstring(b: Bytes::Builder, s: String) -> Bytes::Builder
Appends s's UTF-8 bytes and a NUL. Raises ArgumentError when s
holds a NUL itself, which would end it early.
PG::Wire.cstring(Bytes::Builder.new, "user").to_bytes # => b"user\x00"
def self.frame(type: Int?, body: Bytes) -> Bytes
A message as the protocol frames it: a type byte (none for the
startup and cancel messages, type nil), then the length of what
follows counting itself, then body.
PG::Wire.frame('S'.ord, Bytes.new) # => b"S\x00\x00\x00\x04"