From 44987e57baa5eb63a7c55fc70225fa8315f50a7c Mon Sep 17 00:00:00 2001 From: fox0430 Date: Wed, 1 Apr 2026 17:14:39 +0900 Subject: [PATCH] Add toBytes and toString public to pg_types --- async_postgres/pg_types.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/async_postgres/pg_types.nim b/async_postgres/pg_types.nim index 1025115..eddfea7 100644 --- a/async_postgres/pg_types.nim +++ b/async_postgres/pg_types.nim @@ -565,11 +565,18 @@ proc `$`*(v: PgInterval): string = proc `==`*(a, b: PgInterval): bool = a.months == b.months and a.days == b.days and a.microseconds == b.microseconds -proc toBytes(s: string): seq[byte] = +proc toBytes*(s: string): seq[byte] = + ## Converts a string to a sequence of bytes. result = newSeq[byte](s.len) if s.len > 0: copyMem(addr result[0], unsafeAddr s[0], s.len) +proc toString*(s: seq[byte]): string = + ## Converts a sequence of bytes to a string. + result = newString(s.len) + if s.len > 0: + copyMem(addr result[0], unsafeAddr s[0], s.len) + proc toBE16(v: int16): array[2, byte] = [byte((v shr 8) and 0xFF), byte(v and 0xFF)]