class PG::Wire::Reader
Reads 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.new(data: Bytes) -> PG::Wire::Reader
Reads data from its first byte.
Methods
def remaining -> Int
The bytes not read yet.
def done? -> Bool
Whether everything was read.
def byte -> Int
The next byte, 0 to 255.
def int16 -> Int
The next big-endian signed 16-bit integer.
PG::Wire::Reader.new(b"\xff\xfe").int16 # => -2
def int32 -> Int
The next big-endian signed 32-bit integer.
PG::Wire::Reader.new(b"\x00\x00\x01\x00").int32 # => 256
PG::Wire::Reader.new(b"\xff\xff\xff\xff").int32 # => -1
def uint16 -> Int
The next big-endian unsigned 16-bit integer (counts).
PG::Wire::Reader.new(b"\xff\xfe").uint16 # => 65534
def uint32 -> Int
The next big-endian unsigned 32-bit integer (OIDs).
PG::Wire::Reader.new(b"\x80\x00\x00\x01").uint32 # => 2147483649
def cstring -> String
The next NUL-terminated string, without its NUL, decoded as UTF-8
(an invalid sequence raises PG::ProtocolError).
PG::Wire::Reader.new(b"ab\x00c\x00").cstring # => "ab"
def bytes(n: Int) -> Bytes
The next n bytes.
def rest -> Bytes
The bytes not read yet, all of them.