Low-level byte buffer helpers for big-endian encoding / bulk copy.
This module is dependency-free (stdlib only) and intended to be imported from both pg_protocol and pg_types/* without introducing circular dependencies. Prefer these helpers over hand-written copyMem calls for readability and to keep addr use localized.
Procs
proc readBytes(src: openArray[byte]; off, len: int): seq[byte] {....raises: [], tags: [], forbids: [].}
- Copy len bytes from src starting at off into a new seq[byte].
proc readString(src: openArray[byte]; off, len: int): string {....raises: [], tags: [], forbids: [].}
- Copy len bytes from src starting at off into a new string.
Templates
template appendBytes(buf: var seq[byte]; src: openArray[byte])
- Append src bytes to the end of buf. No-op when src is empty.
template writeBE16(buf: var openArray[byte]; pos: int; v: int16)
template writeBE32(buf: var openArray[byte]; pos: int; v: int32)
template writeBE64(buf: var openArray[byte]; pos: int; v: int64)
template writeBytesAt(dst: var openArray[byte]; pos: int; src: openArray[byte])
- Copy src bytes into dst starting at pos. No-op when src is empty.