aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx')
-rw-r--r--.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx34
1 files changed, 34 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx b/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx
new file mode 100644
index 00000000..15818258
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/bytea.pyx
@@ -0,0 +1,34 @@
+# Copyright (C) 2016-present the asyncpg authors and contributors
+# <see AUTHORS file>
+#
+# This module is part of asyncpg and is released under
+# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
+
+
+cdef bytea_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ cdef:
+ Py_buffer pybuf
+ bint pybuf_used = False
+ char *buf
+ ssize_t len
+
+ if cpython.PyBytes_CheckExact(obj):
+ buf = cpython.PyBytes_AS_STRING(obj)
+ len = cpython.Py_SIZE(obj)
+ else:
+ cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+ pybuf_used = True
+ buf = <char*>pybuf.buf
+ len = pybuf.len
+
+ try:
+ wbuf.write_int32(<int32_t>len)
+ wbuf.write_cstr(buf, len)
+ finally:
+ if pybuf_used:
+ cpython.PyBuffer_Release(&pybuf)
+
+
+cdef bytea_decode(CodecContext settings, FRBuffer *buf):
+ cdef ssize_t buf_len = buf.len
+ return cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)